AccessLogFormat Class
factory methods for access log format.
Example
ts
const destinationBucket = new s3.Bucket(this, 'Bucket');
const deliveryStreamRole = new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('firehose.amazonaws.com'),
});
const stream = new firehose.CfnDeliveryStream(this, 'MyStream', {
deliveryStreamName: 'amazon-apigateway-delivery-stream',
s3DestinationConfiguration: {
bucketArn: destinationBucket.bucketArn,
roleArn: deliveryStreamRole.roleArn,
},
});
const api = new apigateway.RestApi(this, 'books', {
deployOptions: {
accessLogDestination: new apigateway.FirehoseLogDestination(stream),
accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields(),
},
});
python
destination_bucket = s3.Bucket(self, "Bucket")
delivery_stream_role = iam.Role(self, "Role",
assumed_by=iam.ServicePrincipal("firehose.amazonaws.com")
)
stream = firehose.CfnDeliveryStream(self, "MyStream",
delivery_stream_name="amazon-apigateway-delivery-stream",
s3_destination_configuration=firehose.CfnDeliveryStream.S3DestinationConfigurationProperty(
bucket_arn=destination_bucket.bucket_arn,
role_arn=delivery_stream_role.role_arn
)
)
api = apigateway.RestApi(self, "books",
deploy_options=apigateway.StageOptions(
access_log_destination=apigateway.FirehoseLogDestination(stream),
access_log_format=apigateway.AccessLogFormat.json_with_standard_fields()
)
)
java
Bucket destinationBucket = new Bucket(this, "Bucket");
Role deliveryStreamRole = Role.Builder.create(this, "Role")
.assumedBy(new ServicePrincipal("firehose.amazonaws.com"))
.build();
CfnDeliveryStream stream = CfnDeliveryStream.Builder.create(this, "MyStream")
.deliveryStreamName("amazon-apigateway-delivery-stream")
.s3DestinationConfiguration(S3DestinationConfigurationProperty.builder()
.bucketArn(destinationBucket.getBucketArn())
.roleArn(deliveryStreamRole.getRoleArn())
.build())
.build();
RestApi api = RestApi.Builder.create(this, "books")
.deployOptions(StageOptions.builder()
.accessLogDestination(new FirehoseLogDestination(stream))
.accessLogFormat(AccessLogFormat.jsonWithStandardFields())
.build())
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
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()
}
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
destinationBucket := s3.NewBucket(this, jsii.String("Bucket"))
deliveryStreamRole := iam.NewRole(this, jsii.String("Role"), &RoleProps{
AssumedBy: iam.NewServicePrincipal(jsii.String("firehose.amazonaws.com")),
})
stream := firehose.NewCfnDeliveryStream(this, jsii.String("MyStream"), &CfnDeliveryStreamProps{
DeliveryStreamName: jsii.String("amazon-apigateway-delivery-stream"),
S3DestinationConfiguration: &S3DestinationConfigurationProperty{
BucketArn: destinationBucket.bucketArn,
RoleArn: deliveryStreamRole.roleArn,
},
})
api := apigateway.NewRestApi(this, jsii.String("books"), &RestApiProps{
DeployOptions: &StageOptions{
AccessLogDestination: apigateway.NewFirehoseLogDestination(stream),
AccessLogFormat: apigateway.AccessLogFormat_JsonWithStandardFields(),
},
})
Initializer
ts
new AccessLogFormat(format: string)
python
AccessLogFormat(format: str)
java
new AccessLogFormat(String format)
csharp
new AccessLogFormat(string format)
go
NewAccessLogFormat(Format *string)
Methods
clf(): AccessLogFormat // chainable@staticmethod def clf() -> AccessLogFormatpublic static AccessLogFormat clf()public static AccessLogFormat Clf()func Clf() AccessLogFormatstatic#Generate Common Log Format.
custom(format: string): AccessLogFormat // chainable@staticmethod def custom(format: str) -> AccessLogFormatpublic static AccessLogFormat custom(String format)public static AccessLogFormat Custom(string format)func Custom(Format *string) AccessLogFormatstatic#Custom log format.
You can create any log format string. You can easily get the $ context variable by using the methods of AccessLogField.
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')
}
}))
jsonWithStandardFields(fields?: JsonWithStandardFieldProps): AccessLogFormat // chainable@staticmethod def json_with_standard_fields(fields: typing.Optional[JsonWithStandardFieldProps] = None) -> AccessLogFormatpublic static AccessLogFormat jsonWithStandardFields(JsonWithStandardFieldProps fields)public static AccessLogFormat JsonWithStandardFields(JsonWithStandardFieldProps? fields = null)func JsonWithStandardFields(Fields JsonWithStandardFieldProps) AccessLogFormatstatic#Access log will be produced in the JSON format with a set of fields most useful in the access log.
All fields are turned on by default with the option to turn off specific fields.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#Output a format string to be used with CloudFormation.