I'm struggling to set up logs in CloudWatch for my RestApi via cdk.
This is my code:
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 console, the settings of the logs that I want are called "Log full request/responses data". which should be the part
deployOptions: {
accessLogDestination: new apigw.LogGroupLogDestination(logGroup),
loggingLevel: apigw.MethodLoggingLevel.INFO,
dataTraceEnabled: true
}
This setting works as I want as shown in the screenshot:

However if I now check CloudWatch after sending requests to the API, two logGroups are created and have logs:
The first is the LogGroup with the name
apiLogsas defined in my code but the output of the logs are not as detailed as I want them as shown here:
The second is a LogGroup with a default name including the id of the endpoint and the logs include the detailed information that I want as shown here:

Why are there 2 separate logGroups created and why is apiLogs not showing the detailed logs?
Has anyone faced the same problem?