Description
An API Gateway access log can record each request’s ID and response status.
Potential impact
Without these records, it is harder to trace a failed or suspicious call.
Remediation
Set AccessLogSetting on AWS::Serverless::Api or AccessLogSettings on AWS::Serverless::HttpApi. Choose the destination and retention, grant log delivery permissions, and include a request ID in the format.
Examples
The REST API example writes $context.requestId and $context.status to a log group you create separately.
Before
yaml
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TracingEnabled: true
After
yaml
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TracingEnabled: true
AccessLogSetting:
DestinationArn: arn:aws:logs:ap-northeast-2:123456789012:log-group:api-access-log
Format: '{"requestId":"$context.requestId","status":"$context.status"}'