How to add log retention for cdk API gateway execution log?

0

I have created an API using CDK and enabled execution log. I am not able to get a solution to add log retention for execution log. Yes, we can use access log with log retention, but I just wanted to know is there any way I can add log retention for execution log? please help with your valuable suggestion.

const api = new RestApi(this, MyAPI, { deployOptions: { stageName: 'dev', dataTraceEnabled: true, tracingEnabled: true, loggingLevel: MethodLoggingLevel.INFO, }, cloudWatchRole: true });

1 Answer
0

Hi,

Yes, you have a parameter named retention in the class LogRetention of CDK: see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogRetention.html.

Put here the number that you want.

This blog post will show you how to do that form the API Gateway Construct: https://www.kevinwmcconnell.com/cdk/http-api-logs-with-cdk

Best,

Didier

profile pictureAWS
EXPERT
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions