Skip to content

Retention period in API Gateway Execution and access log groups

0

I have a REST API Gateway which has integration request as Lambda function. And I have both execution and access logs enabled in API Gateway, How to configure the retention period of this execution and access log groups in API Gateway?

1 Answer
0

To configure the retention period for API Gateway execution and access log groups, you have a few options:

  1. Using CloudFormation or AWS SAM templates: When creating your resources, you can define the CloudWatch Log Group with a specific retention period. For example, you could add this to your template:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/apigateway/your-api-name"
RetentionInDays: 14
  1. Using the CloudFormation console:
  • Sign in to the CloudFormation console
  • Choose your stack
  • Select the "Resources" tab and choose "Flat view"
  • Search for "logs" in the search resources box
  • Choose the log group you want to edit
  • Select "Actions" then "Edit retention setting(s)"
  • Choose your desired retention period
  1. Using AWS Cloud Control API: You can use the AWS CLI to update the retention period:
aws cloudcontrol create-resource --type-name AWS::Logs::LogGroup \
--desired-state '{"LogGroupName": "your-log-group-name","RetentionInDays": 90}'

By default, if you don't specify a retention period, CloudWatch log groups are set to "Never expire," which means you'll store and pay for those logs indefinitely. Setting an appropriate retention period based on your application's needs can help optimize costs.
Sources
Community | 5 ways to cost optimize your Infrastructure as Code
Change the CloudWatch log group retention period - Security Insights on AWS
Log and monitor C# Lambda functions - AWS Lambda
Getting started with Cloud Control API - Cloud Control API

answered a year 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.