I've been encountering difficulties setting up CloudWatch logs for my RestApi using cdk.
Here is the code I'm using:
const logGroup = new LogGroup(this, `apiLogs`, {
logGroupName: `apiLogs`,
retention: RetentionDays.ONE_WEEK
});
const api = new apigw.RestApi(this, `apiName`, {
// set up CORS
defaultCorsPreflightOptions: {
statusCode: 200,
allowMethods: ['OPTIONS', 'GET', 'POST', 'DELETE'],
allowOrigins: apigw.Cors.ALL_ORIGINS
},
deploy: true,
restApiName: `apiName`,
deployOptions: {
accessLogDestination: new apigw.LogGroupLogDestination(logGroup),
loggingLevel: apigw.MethodLoggingLevel.INFO,
dataTraceEnabled: true
}}
);
In the AWS console, the specific logs I need are labeled as "Log full request/responses data", which is a crucial part of my setup.
deployOptions: {
accessLogDestination: new apigw.LogGroupLogDestination(logGroup),
loggingLevel: apigw.MethodLoggingLevel.INFO,
dataTraceEnabled: true
}
Although this configuration functions correctly and displays the desired outcome in the screenshot provided: https://i.sstatic.net/J5NXa.png
Upon checking CloudWatch after sending requests to the API, I notice the creation of two distinct logGroups with logs:
The first logGroup named
apiLogs
, as specified in my code, produces logs that lack detailed information as shown here: https://i.sstatic.net/jr1ys.pngThe second logGroup has a default name incorporating the endpoint ID and contains the precise details that I require as illustrated here: https://i.sstatic.net/HUVTr.png
I'm puzzled by the creation of two separate logGroups and why apiLogs
doesn't display the desired level of detail in its logs.
Has anyone encountered this issue before?