FirehoseLogDestination Class
Use a Firehose delivery stream as a custom access log destination for API Gateway.
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 FirehoseLogDestination(stream: CfnDeliveryStream)
python
FirehoseLogDestination(stream: CfnDeliveryStream)
java
new FirehoseLogDestination(CfnDeliveryStream stream)
csharp
new FirehoseLogDestination(CfnDeliveryStream stream)
go
NewFirehoseLogDestination(Stream CfnDeliveryStream)
Methods
bind(stage: IStageRef): AccessLogDestinationConfigdef bind(self, stage: IStageRef) -> AccessLogDestinationConfigpublic AccessLogDestinationConfig bind(IStageRef stage)public AccessLogDestinationConfig Bind(IStageRef stage)func Bind(Stage IStageRef) AccessLogDestinationConfig#Binds this destination to the Firehose delivery stream.