For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-serverless-api-access-logging-setting-undefined.md.
A documentation index is available at /llms.txt.
Serverless APIs should have access logging enabled to create an audit trail and support incident investigation and detection of anomalous or abusive traffic. For AWS::Serverless::Api resources, the Properties.AccessLogSetting property must be defined and not null. For AWS::Serverless::HttpApi resources, the Properties.AccessLogSettings property must be defined and not null. These properties configure the log destination and format, so missing or null values will be flagged. Ensure the access log configuration includes a log destination (for example, DestinationArn) and a Format describing the fields to record.
AWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Description:AWS SAM template with a simple API definitionResources:ApiGatewayApi2:Type:AWS::Serverless::ApiProperties:StageName:prodTracingEnabled:trueCacheClusterEnabled:trueAccessLogSetting:DestinationArn:'arn:aws:logs:us-east-1:123456789:log-group:my-log-group'Format:>- {"requestId":"$context.requestId", "ip": "$context.identity.sourceIp",
"caller":"$context.identity.caller",
"user":"$context.identity.user","requestTime":"$context.requestTime",
"eventType":"$context.eventType","routeKey":"$context.routeKey",
"status":"$context.status","connectionId":"$context.connectionId"}
AWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Description:AWS SAM template with a simple API definitionResources:HttpApi2:Type:AWS::Serverless::HttpApiProperties:StageName:!Ref StageNameTags:Tag:ValueAccessLogSettings:DestinationArn:'arn:aws:logs:us-east-1:123456789:log-group:my-log-group'Format:>- {"requestId":"$context.requestId", "ip": "$context.identity.sourceIp",
"caller":"$context.identity.caller",
"user":"$context.identity.user","requestTime":"$context.requestTime",
"eventType":"$context.eventType","routeKey":"$context.routeKey",
"status":"$context.status","connectionId":"$context.connectionId"}
Non-Compliant Code Examples
AWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Description:AWS SAM template with a simple API definitionResources:ApiGatewayApi:Type:AWS::Serverless::ApiProperties:StageName:prodTracingEnabled:trueCacheClusterEnabled:true
AWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Description:AWS SAM template with a simple API definitionResources:HttpApi:Type:AWS::Serverless::HttpApiProperties:StageName:!Ref StageNameTags:Tag:Value
1
2
rulesets:- CloudFormation / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.