Class AccessLogFormat
factory methods for access log format.
Namespace: Amazon.CDK.AWS.APIGateway
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class AccessLogFormat : DeputyBase
Syntax (vb)
Public Class AccessLogFormat Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
var destinationBucket = new Bucket(this, "Bucket");
var deliveryStreamRole = new Role(this, "Role", new RoleProps {
AssumedBy = new ServicePrincipal("firehose.amazonaws.com")
});
var stream = new CfnDeliveryStream(this, "MyStream", new CfnDeliveryStreamProps {
DeliveryStreamName = "amazon-apigateway-delivery-stream",
S3DestinationConfiguration = new S3DestinationConfigurationProperty {
BucketArn = destinationBucket.BucketArn,
RoleArn = deliveryStreamRole.RoleArn
}
});
var api = new RestApi(this, "books", new RestApiProps {
DeployOptions = new StageOptions {
AccessLogDestination = new FirehoseLogDestination(stream),
AccessLogFormat = AccessLogFormat.JsonWithStandardFields()
}
});
Synopsis
Constructors
| AccessLogFormat(string) | factory methods for access log format. |
Methods
| Clf() | Generate Common Log Format. |
| Custom(string) | Custom log format. |
| JsonWithStandardFields(IJsonWithStandardFieldProps?) | Access log will be produced in the JSON format with a set of fields most useful in the access log. |
| ToString() | Output a format string to be used with CloudFormation. |
Constructors
AccessLogFormat(string)
factory methods for access log format.
public AccessLogFormat(string format)
Parameters
- format string
Remarks
ExampleMetadata: infused
Examples
var destinationBucket = new Bucket(this, "Bucket");
var deliveryStreamRole = new Role(this, "Role", new RoleProps {
AssumedBy = new ServicePrincipal("firehose.amazonaws.com")
});
var stream = new CfnDeliveryStream(this, "MyStream", new CfnDeliveryStreamProps {
DeliveryStreamName = "amazon-apigateway-delivery-stream",
S3DestinationConfiguration = new S3DestinationConfigurationProperty {
BucketArn = destinationBucket.BucketArn,
RoleArn = deliveryStreamRole.RoleArn
}
});
var api = new RestApi(this, "books", new RestApiProps {
DeployOptions = new StageOptions {
AccessLogDestination = new FirehoseLogDestination(stream),
AccessLogFormat = AccessLogFormat.JsonWithStandardFields()
}
});
Methods
Clf()
Generate Common Log Format.
public static AccessLogFormat Clf()
Returns
Remarks
ExampleMetadata: infused
Custom(string)
Custom log format.
public static AccessLogFormat Custom(string format)
Parameters
- format string
Returns
Remarks
You can create any log format string. You can easily get the $ context variable by using the methods of 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")
} }
}));
JsonWithStandardFields(IJsonWithStandardFieldProps?)
Access log will be produced in the JSON format with a set of fields most useful in the access log.
public static AccessLogFormat JsonWithStandardFields(IJsonWithStandardFieldProps? fields = null)
Parameters
- fields IJsonWithStandardFieldProps
Returns
Remarks
All fields are turned on by default with the option to turn off specific fields.
ToString()
Output a format string to be used with CloudFormation.
public override string ToString()
Returns
Remarks
ExampleMetadata: infused