Skip to content
v2.278.0

AccessLogField Class ​

$context variables that can be used to customize access log pattern.

Example ​

ts
 apigateway.AccessLogFormat.custom(JSON.stringify({
     requestId: apigateway.AccessLogField.contextRequestId(),
     sourceIp: apigateway.AccessLogField.contextIdentitySourceIp(),
     method: apigateway.AccessLogField.contextHttpMethod(),
     userContext: {
       sub: apigateway.AccessLogField.contextAuthorizerClaims('sub'),
       email: apigateway.AccessLogField.contextAuthorizerClaims('email')
     }
  }))
python
apigateway.AccessLogFormat.custom(JSON.stringify({
    "request_id": apigateway.AccessLogField.context_request_id(),
    "source_ip": apigateway.AccessLogField.context_identity_source_ip(),
    "method": apigateway.AccessLogField.context_http_method(),
    "user_context": {
        "sub": apigateway.AccessLogField.context_authorizer_claims("sub"),
        "email": apigateway.AccessLogField.context_authorizer_claims("email")
    }
}))
java
AccessLogFormat.custom(JSON.stringify(Map.of(
        "requestId", AccessLogField.contextRequestId(),
        "sourceIp", AccessLogField.contextIdentitySourceIp(),
        "method", AccessLogField.contextHttpMethod(),
        "userContext", Map.of(
                "sub", AccessLogField.contextAuthorizerClaims("sub"),
                "email", AccessLogField.contextAuthorizerClaims("email")))));
csharp
// Install: dotnet add package Amazon.CDK.Lib
AccessLogFormat.Custom(JSON.Stringify(new Dictionary<string, object> {
    { "requestId", AccessLogField.ContextRequestId() },
    { "sourceIp", AccessLogField.ContextIdentitySourceIp() },
    { "method", AccessLogField.ContextHttpMethod() },
    { "userContext", new Struct {
        Sub = AccessLogField.ContextAuthorizerClaims("sub"),
        Email = AccessLogField.ContextAuthorizerClaims("email")
    } }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
apigateway.AccessLogFormat_Custom(jSON.stringify(map[string]interface{}{
	"requestId": apigateway.AccessLogField_contextRequestId(),
	"sourceIp": apigateway.AccessLogField_contextIdentitySourceIp(),
	"method": apigateway.AccessLogField_contextHttpMethod(),
	"userContext": map[string]*string{
		"sub": apigateway.AccessLogField_contextAuthorizerClaims(jsii.String("sub")),
		"email": apigateway.AccessLogField_contextAuthorizerClaims(jsii.String("email")),
	},
}))

Initializer ​

ts
new AccessLogField()
python
AccessLogField()
java
new AccessLogField()
csharp
new AccessLogField()
go
NewAccessLogField()

Methods ​

contextAccountId(): string@staticmethod def context_account_id() -> strpublic static String contextAccountId()public static string ContextAccountId()func ContextAccountId() *string static deprecated #
Use `contextCallerAccountId` or `contextOwnerAccountId` instead
contextApiId(): string@staticmethod def context_api_id() -> strpublic static String contextApiId()public static string ContextApiId()func ContextApiId() *string static #
The identifier API Gateway assigns to your API.
contextAuthenticateError(): string@staticmethod def context_authenticate_error() -> strpublic static String contextAuthenticateError()public static string ContextAuthenticateError()func ContextAuthenticateError() *string static #
The error message returned from an authentication attempt.
contextAuthenticateLatency(): string@staticmethod def context_authenticate_latency() -> strpublic static String contextAuthenticateLatency()public static string ContextAuthenticateLatency()func ContextAuthenticateLatency() *string static #
The authentication latency in ms.
contextAuthenticateStatus(): string@staticmethod def context_authenticate_status() -> strpublic static String contextAuthenticateStatus()public static string ContextAuthenticateStatus()func ContextAuthenticateStatus() *string static #
The status code returned from an authentication attempt.
contextAuthorizeError(): string@staticmethod def context_authorize_error() -> strpublic static String contextAuthorizeError()public static string ContextAuthorizeError()func ContextAuthorizeError() *string static #
The authorization error message.
contextAuthorizeLatency(): string@staticmethod def context_authorize_latency() -> strpublic static String contextAuthorizeLatency()public static string ContextAuthorizeLatency()func ContextAuthorizeLatency() *string static #
The authorization latency in ms.
contextAuthorizer(property: string): string@staticmethod def context_authorizer(property: str) -> strpublic static String contextAuthorizer(String property)public static string ContextAuthorizer(string property)func ContextAuthorizer(Property *string) *string static #
The stringified value of the specified key-value pair of the `context` map returned from an API Gateway Lambda authorizer function.
1 parameter

Parameters

  • propertypropertypropertypropertyProperty — key of the context map.
contextAuthorizerClaims(property: string): string@staticmethod def context_authorizer_claims(property: str) -> strpublic static String contextAuthorizerClaims(String property)public static string ContextAuthorizerClaims(string property)func ContextAuthorizerClaims(Property *string) *string static #
A property of the claims returned from the Amazon Cognito user pool after the method caller is successfully authenticated.
1 parameter

Parameters

  • propertypropertypropertypropertyProperty — A property key of the claims.
contextAuthorizerError(): string@staticmethod def context_authorizer_error() -> strpublic static String contextAuthorizerError()public static string ContextAuthorizerError()func ContextAuthorizerError() *string static #
The error message returned from an authorizer.
contextAuthorizerIntegrationLatency(): string@staticmethod def context_authorizer_integration_latency() -> strpublic static String contextAuthorizerIntegrationLatency()public static string ContextAuthorizerIntegrationLatency()func ContextAuthorizerIntegrationLatency() *string static #
The authorizer latency in ms.
contextAuthorizerIntegrationStatus(): string@staticmethod def context_authorizer_integration_status() -> strpublic static String contextAuthorizerIntegrationStatus()public static string ContextAuthorizerIntegrationStatus()func ContextAuthorizerIntegrationStatus() *string static #
The status code returned from a Lambda authorizer.
contextAuthorizerLatency(): string@staticmethod def context_authorizer_latency() -> strpublic static String contextAuthorizerLatency()public static string ContextAuthorizerLatency()func ContextAuthorizerLatency() *string static #
The authorizer latency in ms.
contextAuthorizerPrincipalId(): string@staticmethod def context_authorizer_principal_id() -> strpublic static String contextAuthorizerPrincipalId()public static string ContextAuthorizerPrincipalId()func ContextAuthorizerPrincipalId() *string static #
The principal user identification associated with the token sent by the client and returned from an API Gateway Lambda authorizer (formerly known as a custom authorizer).
contextAuthorizerRequestId(): string@staticmethod def context_authorizer_request_id() -> strpublic static String contextAuthorizerRequestId()public static string ContextAuthorizerRequestId()func ContextAuthorizerRequestId() *string static #
The AWS endpoint's request ID.
contextAuthorizerStatus(): string@staticmethod def context_authorizer_status() -> strpublic static String contextAuthorizerStatus()public static string ContextAuthorizerStatus()func ContextAuthorizerStatus() *string static #
The status code returned from an authorizer.
contextAuthorizeStatus(): string@staticmethod def context_authorize_status() -> strpublic static String contextAuthorizeStatus()public static string ContextAuthorizeStatus()func ContextAuthorizeStatus() *string static #
The status code returned from an authorization attempt.
contextAwsEndpointRequestId(): string@staticmethod def context_aws_endpoint_request_id() -> strpublic static String contextAwsEndpointRequestId()public static string ContextAwsEndpointRequestId()func ContextAwsEndpointRequestId() *string static #
The AWS endpoint's request ID.
contextCallerAccountId(): string@staticmethod def context_caller_account_id() -> strpublic static String contextCallerAccountId()public static string ContextCallerAccountId()func ContextCallerAccountId() *string static #
The API callers AWS account ID.
contextConnectionId(): string@staticmethod def context_connection_id() -> strpublic static String contextConnectionId()public static string ContextConnectionId()func ContextConnectionId() *string static #
A unique ID for the connection that can be used to make a callback to the client.
contextCustomDomainBasePathMatched(): string@staticmethod def context_custom_domain_base_path_matched() -> strpublic static String contextCustomDomainBasePathMatched()public static string ContextCustomDomainBasePathMatched()func ContextCustomDomainBasePathMatched() *string static #
The path for an API mapping that an incoming request matched.

Applicable when a client uses a custom domain name to access an API. For example if a client sends a request to https://api.example.com/v1/orders/1234, and the request matches the API mapping with the path v1/orders, the value is v1/orders.

contextDomainName(): string@staticmethod def context_domain_name() -> strpublic static String contextDomainName()public static string ContextDomainName()func ContextDomainName() *string static #
The full domain name used to invoke the API.

This should be the same as the incoming Host header.

contextDomainPrefix(): string@staticmethod def context_domain_prefix() -> strpublic static String contextDomainPrefix()public static string ContextDomainPrefix()func ContextDomainPrefix() *string static #
The first label of the `$context.domainName`. This is often used as a caller/customer identifier.
contextErrorMessage(): string@staticmethod def context_error_message() -> strpublic static String contextErrorMessage()public static string ContextErrorMessage()func ContextErrorMessage() *string static #
A string containing an API Gateway error message.
contextErrorMessageString(): string@staticmethod def context_error_message_string() -> strpublic static String contextErrorMessageString()public static string ContextErrorMessageString()func ContextErrorMessageString() *string static #
The quoted value of $context.error.message, namely "$context.error.message".
contextErrorResponseType(): string@staticmethod def context_error_response_type() -> strpublic static String contextErrorResponseType()public static string ContextErrorResponseType()func ContextErrorResponseType() *string static #
A type of GatewayResponse.

This variable can only be used for simple variable substitution in a GatewayResponse body-mapping template, which is not processed by the Velocity Template Language engine, and in access logging.

contextErrorValidationErrorString(): string@staticmethod def context_error_validation_error_string() -> strpublic static String contextErrorValidationErrorString()public static string ContextErrorValidationErrorString()func ContextErrorValidationErrorString() *string static #
A string containing a detailed validation error message.
contextEventType(): string@staticmethod def context_event_type() -> strpublic static String contextEventType()public static string ContextEventType()func ContextEventType() *string static #
The event type: CONNECT, MESSAGE, or DISCONNECT.
contextExtendedRequestId(): string@staticmethod def context_extended_request_id() -> strpublic static String contextExtendedRequestId()public static string ContextExtendedRequestId()func ContextExtendedRequestId() *string static #
The extended ID that API Gateway assigns to the API request, which contains more useful information for debugging/troubleshooting.
contextHttpMethod(): string@staticmethod def context_http_method() -> strpublic static String contextHttpMethod()public static string ContextHttpMethod()func ContextHttpMethod() *string static #
The HTTP method used.

Valid values include: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT.

contextIdentityAccountId(): string@staticmethod def context_identity_account_id() -> strpublic static String contextIdentityAccountId()public static string ContextIdentityAccountId()func ContextIdentityAccountId() *string static #
The AWS account ID associated with the request.
contextIdentityApiKey(): string@staticmethod def context_identity_api_key() -> strpublic static String contextIdentityApiKey()public static string ContextIdentityApiKey()func ContextIdentityApiKey() *string static #
For API methods that require an API key, this variable is the API key associated with the method request.

For methods that don't require an API key, this variable is

contextIdentityApiKeyId(): string@staticmethod def context_identity_api_key_id() -> strpublic static String contextIdentityApiKeyId()public static string ContextIdentityApiKeyId()func ContextIdentityApiKeyId() *string static #
The API key ID associated with an API request that requires an API key.
contextIdentityCaller(): string@staticmethod def context_identity_caller() -> strpublic static String contextIdentityCaller()public static string ContextIdentityCaller()func ContextIdentityCaller() *string static #
The principal identifier of the caller making the request.
contextIdentityClientCertIssunerDN(): string@staticmethod def context_identity_client_cert_issuner_dn() -> strpublic static String contextIdentityClientCertIssunerDN()public static string ContextIdentityClientCertIssunerDN()func ContextIdentityClientCertIssunerDN() *string static #
The distinguished name of the issuer of the certificate that a client presents.

Present when a client accesses an API by using a custom domain name that has mutual TLS enabled. Present only in access logs if mutual TLS authentication fails.

contextIdentityClientCertPem(): string@staticmethod def context_identity_client_cert_pem() -> strpublic static String contextIdentityClientCertPem()public static string ContextIdentityClientCertPem()func ContextIdentityClientCertPem() *string static #
The PEM-encoded client certificate that the client presented during mutual TLS authentication.

Present when a client accesses an API by using a custom domain name that has mutual TLS enabled. Present only in access logs if mutual TLS authentication fails.

contextIdentityClientCertSerialNumber(): string@staticmethod def context_identity_client_cert_serial_number() -> strpublic static String contextIdentityClientCertSerialNumber()public static string ContextIdentityClientCertSerialNumber()func ContextIdentityClientCertSerialNumber() *string static #
The serial number of the certificate.

Present when a client accesses an API by using a custom domain name that has mutual TLS enabled. Present only in access logs if mutual TLS authentication fails.

contextIdentityClientCertSubjectDN(): string@staticmethod def context_identity_client_cert_subject_dn() -> strpublic static String contextIdentityClientCertSubjectDN()public static string ContextIdentityClientCertSubjectDN()func ContextIdentityClientCertSubjectDN() *string static #
The distinguished name of the subject of the certificate that a client presents.

Present when a client accesses an API by using a custom domain name that has mutual TLS enabled. Present only in access logs if mutual TLS authentication fails.

contextIdentityClientCertValidityNotAfter(): string@staticmethod def context_identity_client_cert_validity_not_after() -> strpublic static String contextIdentityClientCertValidityNotAfter()public static string ContextIdentityClientCertValidityNotAfter()func ContextIdentityClientCertValidityNotAfter() *string static #
The date after which the certificate is invalid.

Present when a client accesses an API by using a custom domain name that has mutual TLS enabled. Present only in access logs if mutual TLS authentication fails.

contextIdentityClientCertValidityNotBefore(): string@staticmethod def context_identity_client_cert_validity_not_before() -> strpublic static String contextIdentityClientCertValidityNotBefore()public static string ContextIdentityClientCertValidityNotBefore()func ContextIdentityClientCertValidityNotBefore() *string static #
The date before which the certificate is invalid.

Present when a client accesses an API by using a custom domain name that has mutual TLS enabled. Present only in access logs if mutual TLS authentication fails.

contextIdentityCognitoAuthenticationProvider(): string@staticmethod def context_identity_cognito_authentication_provider() -> strpublic static String contextIdentityCognitoAuthenticationProvider()public static string ContextIdentityCognitoAuthenticationProvider()func ContextIdentityCognitoAuthenticationProvider() *string static #
The Amazon Cognito authentication provider used by the caller making the request.

Available only if the request was signed with Amazon Cognito credentials.

contextIdentityCognitoAuthenticationType(): string@staticmethod def context_identity_cognito_authentication_type() -> strpublic static String contextIdentityCognitoAuthenticationType()public static string ContextIdentityCognitoAuthenticationType()func ContextIdentityCognitoAuthenticationType() *string static #
The Amazon Cognito authentication type of the caller making the request.

Available only if the request was signed with Amazon Cognito credentials.

contextIdentityCognitoIdentityId(): string@staticmethod def context_identity_cognito_identity_id() -> strpublic static String contextIdentityCognitoIdentityId()public static string ContextIdentityCognitoIdentityId()func ContextIdentityCognitoIdentityId() *string static #
The Amazon Cognito identity ID of the caller making the request.

Available only if the request was signed with Amazon Cognito credentials.

contextIdentityCognitoIdentityPoolId(): string@staticmethod def context_identity_cognito_identity_pool_id() -> strpublic static String contextIdentityCognitoIdentityPoolId()public static string ContextIdentityCognitoIdentityPoolId()func ContextIdentityCognitoIdentityPoolId() *string static #
The Amazon Cognito identity pool ID of the caller making the request.

Available only if the request was signed with Amazon Cognito credentials.

contextIdentityPrincipalOrgId(): string@staticmethod def context_identity_principal_org_id() -> strpublic static String contextIdentityPrincipalOrgId()public static string ContextIdentityPrincipalOrgId()func ContextIdentityPrincipalOrgId() *string static #
The AWS organization ID.
contextIdentitySourceIp(): string@staticmethod def context_identity_source_ip() -> strpublic static String contextIdentitySourceIp()public static string ContextIdentitySourceIp()func ContextIdentitySourceIp() *string static #
The source IP address of the TCP connection making the request to API Gateway.

Warning: You should not trust this value if there is any chance that the X-Forwarded-For header could be forged.

contextIdentityUser(): string@staticmethod def context_identity_user() -> strpublic static String contextIdentityUser()public static string ContextIdentityUser()func ContextIdentityUser() *string static #
The principal identifier of the user making the request.

Used in Lambda authorizers.

contextIdentityUserAgent(): string@staticmethod def context_identity_user_agent() -> strpublic static String contextIdentityUserAgent()public static string ContextIdentityUserAgent()func ContextIdentityUserAgent() *string static #
The User-Agent header of the API caller.
contextIdentityUserArn(): string@staticmethod def context_identity_user_arn() -> strpublic static String contextIdentityUserArn()public static string ContextIdentityUserArn()func ContextIdentityUserArn() *string static #
The Amazon Resource Name (ARN) of the effective user identified after authentication.
contextIntegrationErrorMessage(): string@staticmethod def context_integration_error_message() -> strpublic static String contextIntegrationErrorMessage()public static string ContextIntegrationErrorMessage()func ContextIntegrationErrorMessage() *string static #
A string that contains an integration error message.
contextIntegrationLatency(): string@staticmethod def context_integration_latency() -> strpublic static String contextIntegrationLatency()public static string ContextIntegrationLatency()func ContextIntegrationLatency() *string static #
The integration latency in ms.
contextIntegrationStatus(): string@staticmethod def context_integration_status() -> strpublic static String contextIntegrationStatus()public static string ContextIntegrationStatus()func ContextIntegrationStatus() *string static #
For Lambda proxy integration, this parameter represents the status code returned from AWS Lambda, not from the backend Lambda function.
contextOwnerAccountId(): string@staticmethod def context_owner_account_id() -> strpublic static String contextOwnerAccountId()public static string ContextOwnerAccountId()func ContextOwnerAccountId() *string static #
The API owner's AWS account ID.
contextPath(): string@staticmethod def context_path() -> strpublic static String contextPath()public static string ContextPath()func ContextPath() *string static #
The request path.

For example, for a non-proxy request URL of https://{rest-api-id.execute-api.{region}.amazonaws.com/{stage}/root/child, this value is /{stage}/root/child.

contextProtocol(): string@staticmethod def context_protocol() -> strpublic static String contextProtocol()public static string ContextProtocol()func ContextProtocol() *string static #
The request protocol, for example, HTTP/1.1.
contextRequestId(): string@staticmethod def context_request_id() -> strpublic static String contextRequestId()public static string ContextRequestId()func ContextRequestId() *string static #
The ID that API Gateway assigns to the API request.
contextRequestOverrideHeader(headerName: string): string@staticmethod def context_request_override_header(header_name: str) -> strpublic static String contextRequestOverrideHeader(String headerName)public static string ContextRequestOverrideHeader(string headerName)func ContextRequestOverrideHeader(HeaderName *string) *string static #
The request header override.

If this parameter is defined, it contains the headers to be used instead of the HTTP Headers that are defined in the Integration Request pane.

contextRequestOverridePath(pathName: string): string@staticmethod def context_request_override_path(path_name: str) -> strpublic static String contextRequestOverridePath(String pathName)public static string ContextRequestOverridePath(string pathName)func ContextRequestOverridePath(PathName *string) *string static #
The request path override.

If this parameter is defined, it contains the request path to be used instead of the URL Path Parameters that are defined in the Integration Request pane.

contextRequestOverrideQuerystring(querystringName: string): string@staticmethod def context_request_override_querystring(querystring_name: str) -> strpublic static String contextRequestOverrideQuerystring(String querystringName)public static string ContextRequestOverrideQuerystring(string querystringName)func ContextRequestOverrideQuerystring(QuerystringName *string) *string static #
The request query string override.

If this parameter is defined, it contains the request query strings to be used instead of the URL Query String Parameters that are defined in the Integration Request pane.

contextRequestTime(): string@staticmethod def context_request_time() -> strpublic static String contextRequestTime()public static string ContextRequestTime()func ContextRequestTime() *string static #
The CLF-formatted request time (dd/MMM/yyyy:HH:mm:ss +-hhmm).
contextRequestTimeEpoch(): string@staticmethod def context_request_time_epoch() -> strpublic static String contextRequestTimeEpoch()public static string ContextRequestTimeEpoch()func ContextRequestTimeEpoch() *string static #
The Epoch-formatted request time.
contextResourceId(): string@staticmethod def context_resource_id() -> strpublic static String contextResourceId()public static string ContextResourceId()func ContextResourceId() *string static #
The identifier that API Gateway assigns to your resource.
contextResourcePath(): string@staticmethod def context_resource_path() -> strpublic static String contextResourcePath()public static string ContextResourcePath()func ContextResourcePath() *string static #
The path to your resource.

For example, for the non-proxy request URI of https://{rest-api-id.execute-api.{region}.amazonaws.com/{stage}/root/child, The $context.resourcePath value is /root/child.

contextResponseLatency(): string@staticmethod def context_response_latency() -> strpublic static String contextResponseLatency()public static string ContextResponseLatency()func ContextResponseLatency() *string static #
The response latency in ms.
contextResponseLength(): string@staticmethod def context_response_length() -> strpublic static String contextResponseLength()public static string ContextResponseLength()func ContextResponseLength() *string static #
The response payload length.
contextResponseOverrideHeader(headerName: string): string@staticmethod def context_response_override_header(header_name: str) -> strpublic static String contextResponseOverrideHeader(String headerName)public static string ContextResponseOverrideHeader(string headerName)func ContextResponseOverrideHeader(HeaderName *string) *string static #
The response header override.

If this parameter is defined, it contains the header to be returned instead of the Response header that is defined as the Default mapping in the Integration Response pane.

contextResponseOverrideStatus(): string@staticmethod def context_response_override_status() -> strpublic static String contextResponseOverrideStatus()public static string ContextResponseOverrideStatus()func ContextResponseOverrideStatus() *string static #
The response status code override.

If this parameter is defined, it contains the status code to be returned instead of the Method response status that is defined as the Default mapping in the Integration Response pane.

contextRouteKey(): string@staticmethod def context_route_key() -> strpublic static String contextRouteKey()public static string ContextRouteKey()func ContextRouteKey() *string static #
The selected route key.
contextStage(): string@staticmethod def context_stage() -> strpublic static String contextStage()public static string ContextStage()func ContextStage() *string static #
The deployment stage of the API request (for example, `Beta` or `Prod`).
contextStatus(): string@staticmethod def context_status() -> strpublic static String contextStatus()public static string ContextStatus()func ContextStatus() *string static #
The method response status.
contextWafError(): string@staticmethod def context_waf_error() -> strpublic static String contextWafError()public static string ContextWafError()func ContextWafError() *string static #
The error message returned from AWS WAF.
contextWafLatency(): string@staticmethod def context_waf_latency() -> strpublic static String contextWafLatency()public static string ContextWafLatency()func ContextWafLatency() *string static #
The AWS WAF latency in ms.
contextWafResponseCode(): string@staticmethod def context_waf_response_code() -> strpublic static String contextWafResponseCode()public static string ContextWafResponseCode()func ContextWafResponseCode() *string static #
The response received from AWS WAF: `WAF_ALLOW` or `WAF_BLOCK`.

Will not be set if the stage is not associated with a web ACL.

contextWafStatus(): string@staticmethod def context_waf_status() -> strpublic static String contextWafStatus()public static string ContextWafStatus()func ContextWafStatus() *string static #
The status code returned from AWS WAF.
contextWebaclArn(): string@staticmethod def context_webacl_arn() -> strpublic static String contextWebaclArn()public static string ContextWebaclArn()func ContextWebaclArn() *string static #
The complete ARN of the web ACL that is used to decide whether to allow or block the request.

Will not be set if the stage is not associated with a web ACL.

contextXrayTraceId(): string@staticmethod def context_xray_trace_id() -> strpublic static String contextXrayTraceId()public static string ContextXrayTraceId()func ContextXrayTraceId() *string static #
The trace ID for the X-Ray trace.