Skip to content
v2.278.0

LogGroupLogDestination Class ​

Use CloudWatch Logs as a custom access log destination for API Gateway.

Example ​

ts
import * as apigw from 'aws-cdk-lib/aws-apigateway';
import * as logs from 'aws-cdk-lib/aws-logs';

declare const api: apigwv2.HttpApi;
declare const logGroup: logs.LogGroup;

const stage = new apigwv2.HttpStage(this, 'Stage', {
  httpApi: api,
  accessLogSettings: {
    destination: new apigwv2.LogGroupLogDestination(logGroup),
    format: apigw.AccessLogFormat.clf(),
  },
});
python
import aws_cdk.aws_apigateway as apigw
import aws_cdk.aws_logs as logs

# api: apigwv2.HttpApi
# log_group: logs.LogGroup


stage = apigwv2.HttpStage(self, "Stage",
    http_api=api,
    access_log_settings={
        "destination": apigwv2.LogGroupLogDestination(log_group),
        "format": apigw.AccessLogFormat.clf()
    }
)
java
import software.amazon.awscdk.services.apigateway.*;
import software.amazon.awscdk.services.logs.*;

HttpApi api;
LogGroup logGroup;


HttpStage stage = HttpStage.Builder.create(this, "Stage")
        .httpApi(api)
        .accessLogSettings(Map.of(
                "destination", new LogGroupLogDestination(logGroup),
                "format", AccessLogFormat.clf()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.APIGateway;
using Amazon.CDK.AWS.Logs;

HttpApi api;
LogGroup logGroup;


var stage = new HttpStage(this, "Stage", new HttpStageProps {
    HttpApi = api,
    AccessLogSettings = new Dictionary<string, object> {
        { "destination", new LogGroupLogDestination(logGroup) },
        { "format", AccessLogFormat.Clf() }
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import apigw "github.com/aws/aws-cdk-go/awscdk"
import logs "github.com/aws/aws-cdk-go/awscdk"

var api HttpApi
var logGroup LogGroup


stage := apigwv2.NewHttpStage(this, jsii.String("Stage"), &HttpStageProps{
	HttpApi: api,
	AccessLogSettings: map[string]interface{}{
		"destination": apigwv2.NewLogGroupLogDestination(logGroup),
		"format": apigw.AccessLogFormat_clf(),
	},
})

Initializer ​

ts
new LogGroupLogDestination(logGroup: ILogGroupRef)
python
LogGroupLogDestination(log_group: ILogGroupRef)
java
new LogGroupLogDestination(ILogGroupRef logGroup)
csharp
new LogGroupLogDestination(ILogGroupRef logGroup)
go
NewLogGroupLogDestination(LogGroup ILogGroupRef)

Methods ​

bind(_stage: IStage): AccessLogDestinationConfigdef bind(self, _stage: IStage) -> AccessLogDestinationConfigpublic AccessLogDestinationConfig bind(IStage _stage)public AccessLogDestinationConfig Bind(IStage _stage)func Bind(_stage IStage) AccessLogDestinationConfig #
Binds this destination to the CloudWatch Logs.