Table of Contents

Class AccessLogField

Namespace
Amazon.CDK.AWS.APIGateway
Assembly
Amazon.CDK.AWS.APIGateway.dll

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

public class AccessLogField : DeputyBase
Inheritance
AccessLogField

Examples

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")
                } }
            }));

Remarks

ExampleMetadata: infused

Constructors

AccessLogField()

public AccessLogField()

Methods

ContextAccountId()

The API owner's AWS account ID.

public static string ContextAccountId()

Returns

string

ContextApiId()

The identifier API Gateway assigns to your API.

public static string ContextApiId()

Returns

string

ContextAuthorizer(string)

The stringified value of the specified key-value pair of the context map returned from an API Gateway Lambda authorizer function.

public static string ContextAuthorizer(string property)

Parameters

property string

key of the context map.

Returns

string

Remarks

ContextAuthorizerClaims(string)

A property of the claims returned from the Amazon Cognito user pool after the method caller is successfully authenticated.

public static string ContextAuthorizerClaims(string property)

Parameters

property string

A property key of the claims.

Returns

string

Remarks

ContextAuthorizerIntegrationLatency()

The authorizer latency in ms.

public static string ContextAuthorizerIntegrationLatency()

Returns

string

ContextAuthorizerPrincipalId()

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).

public static string ContextAuthorizerPrincipalId()

Returns

string

Remarks

ContextAwsEndpointRequestId()

The AWS endpoint's request ID.

public static string ContextAwsEndpointRequestId()

Returns

string

ContextDomainName()

The full domain name used to invoke the API.

public static string ContextDomainName()

Returns

string

Remarks

This should be the same as the incoming Host header.

ContextDomainPrefix()

The first label of the $context.domainName. This is often used as a caller/customer identifier.

public static string ContextDomainPrefix()

Returns

string

ContextErrorMessage()

A string containing an API Gateway error message.

public static string ContextErrorMessage()

Returns

string

ContextErrorMessageString()

The quoted value of $context.error.message, namely "$context.error.message".

public static string ContextErrorMessageString()

Returns

string

ContextErrorResponseType()

A type of GatewayResponse.

public static string ContextErrorResponseType()

Returns

string

Remarks

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.

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/customize-gateway-responses.html

ContextErrorValidationErrorString()

A string containing a detailed validation error message.

public static string ContextErrorValidationErrorString()

Returns

string

ContextExtendedRequestId()

The extended ID that API Gateway assigns to the API request, which contains more useful information for debugging/troubleshooting.

public static string ContextExtendedRequestId()

Returns

string

ContextHttpMethod()

The HTTP method used.

public static string ContextHttpMethod()

Returns

string

Remarks

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

ContextIdentityAccountId()

The AWS account ID associated with the request.

public static string ContextIdentityAccountId()

Returns

string

ContextIdentityApiKey()

For API methods that require an API key, this variable is the API key associated with the method request.

public static string ContextIdentityApiKey()

Returns

string

Remarks

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

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html

ContextIdentityApiKeyId()

The API key ID associated with an API request that requires an API key.

public static string ContextIdentityApiKeyId()

Returns

string

ContextIdentityCaller()

The principal identifier of the caller making the request.

public static string ContextIdentityCaller()

Returns

string

ContextIdentityCognitoAuthenticationProvider()

The Amazon Cognito authentication provider used by the caller making the request.

public static string ContextIdentityCognitoAuthenticationProvider()

Returns

string

Remarks

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

See: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html

ContextIdentityCognitoAuthenticationType()

The Amazon Cognito authentication type of the caller making the request.

public static string ContextIdentityCognitoAuthenticationType()

Returns

string

Remarks

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

ContextIdentityCognitoIdentityId()

The Amazon Cognito identity ID of the caller making the request.

public static string ContextIdentityCognitoIdentityId()

Returns

string

Remarks

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

ContextIdentityCognitoIdentityPoolId()

The Amazon Cognito identity pool ID of the caller making the request.

public static string ContextIdentityCognitoIdentityPoolId()

Returns

string

Remarks

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

ContextIdentityPrincipalOrgId()

The AWS organization ID.

public static string ContextIdentityPrincipalOrgId()

Returns

string

ContextIdentitySourceIp()

The source IP address of the TCP connection making the request to API Gateway.

public static string ContextIdentitySourceIp()

Returns

string

Remarks

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

ContextIdentityUser()

The principal identifier of the user making the request.

public static string ContextIdentityUser()

Returns

string

Remarks

ContextIdentityUserAgent()

The User-Agent header of the API caller.

public static string ContextIdentityUserAgent()

Returns

string

ContextIdentityUserArn()

The Amazon Resource Name (ARN) of the effective user identified after authentication.

public static string ContextIdentityUserArn()

Returns

string

Remarks

ContextIntegrationLatency()

The integration latency in ms.

public static string ContextIntegrationLatency()

Returns

string

ContextIntegrationStatus()

For Lambda proxy integration, this parameter represents the status code returned from AWS Lambda, not from the backend Lambda function.

public static string ContextIntegrationStatus()

Returns

string

ContextPath()

The request path.

public static string ContextPath()

Returns

string

Remarks

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()

The request protocol, for example, HTTP/1.1.

public static string ContextProtocol()

Returns

string

ContextRequestId()

The ID that API Gateway assigns to the API request.

public static string ContextRequestId()

Returns

string

ContextRequestOverrideHeader(string)

The request header override.

public static string ContextRequestOverrideHeader(string headerName)

Parameters

headerName string

Returns

string

Remarks

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.

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html

ContextRequestOverridePath(string)

The request path override.

public static string ContextRequestOverridePath(string pathName)

Parameters

pathName string

Returns

string

Remarks

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.

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html

ContextRequestOverrideQuerystring(string)

The request query string override.

public static string ContextRequestOverrideQuerystring(string querystringName)

Parameters

querystringName string

Returns

string

Remarks

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()

The CLF-formatted request time (dd/MMM/yyyy:HH:mm:ss +-hhmm).

public static string ContextRequestTime()

Returns

string

ContextRequestTimeEpoch()

The Epoch-formatted request time.

public static string ContextRequestTimeEpoch()

Returns

string

ContextResourceId()

The identifier that API Gateway assigns to your resource.

public static string ContextResourceId()

Returns

string

ContextResourcePath()

The path to your resource.

public static string ContextResourcePath()

Returns

string

Remarks

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.

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-step-by-step.html

ContextResponseLatency()

The response latency in ms.

public static string ContextResponseLatency()

Returns

string

ContextResponseLength()

The response payload length.

public static string ContextResponseLength()

Returns

string

ContextResponseOverrideHeader(string)

The response header override.

public static string ContextResponseOverrideHeader(string headerName)

Parameters

headerName string

Returns

string

Remarks

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.

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html

ContextResponseOverrideStatus()

The response status code override.

public static string ContextResponseOverrideStatus()

Returns

string

Remarks

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.

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html

ContextStage()

The deployment stage of the API request (for example, Beta or Prod).

public static string ContextStage()

Returns

string

ContextStatus()

The method response status.

public static string ContextStatus()

Returns

string

ContextWafResponseCode()

The response received from AWS WAF: WAF_ALLOW or WAF_BLOCK.

public static string ContextWafResponseCode()

Returns

string

Remarks

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

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-aws-waf.html

ContextWebaclArn()

The complete ARN of the web ACL that is used to decide whether to allow or block the request.

public static string ContextWebaclArn()

Returns

string

Remarks

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

See: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-aws-waf.html

ContextXrayTraceId()

The trace ID for the X-Ray trace.

public static string ContextXrayTraceId()

Returns

string

Remarks