VPCs must have VPC Flow Logs enabled so network traffic metadata is recorded for detecting suspicious activity and supporting incident investigation and compliance audits.
For each AWS::EC2::VPC resource, ensure there is an AWS::EC2::FlowLog resource whose Properties.ResourceId references that VPC (for example, Ref: MyVPC) so traffic for that VPC is captured. Resources missing a flow log, or where the flow log’s ResourceId does not reference the VPC, will be flagged. The flow log should also specify a valid destination (CloudWatch Logs or S3) via LogDestination/LogDestinationType.
AWSTemplateFormatVersion:'2010-09-09'Description: 'VPC:public and private subnets in two availability zones, a cloudonaut.io template'Parameters:ClassB:Description:'Class B of VPC (10.XXX.0.0/16)'Type:NumberDefault:0ConstraintDescription:'Must be in the range [0-255]'MinValue:0MaxValue:255Resources:Role:Type:'AWS::IAM::Role'Properties:AssumeRolePolicyDocument:Version:'2012-10-17'Statement:- Effect:AllowPrincipal:Service:'vpc-flow-logs.amazonaws.com'Action:'sts:AssumeRole'Policies:- PolicyName:'flowlogs-policy'PolicyDocument:Version:'2012-10-17'Statement:- Effect:AllowAction:- 'logs:CreateLogStream'- 'logs:PutLogEvents'- 'logs:DescribeLogGroups'- 'logs:DescribeLogStreams'Resource:!GetAtt 'LogGroup.Arn'MyVPC:Type:'AWS::EC2::VPC'Properties:CidrBlock:!Sub '10.${ClassB}.0.0/16'EnableDnsSupport:trueEnableDnsHostnames:trueInstanceTenancy:defaultTags:- Key:NameValue:!Sub '10.${ClassB}.0.0/16'LogGroup:Type:'AWS::Logs::LogGroup'Properties:RetentionInDays:14FlowLog:Type:'AWS::EC2::FlowLog'Properties:DeliverLogsPermissionArn:!GetAtt 'Role.Arn'LogGroupName:!Ref LogGroupResourceId:!Ref MyVPCResourceType:'VPC'TrafficType:ACCEPT
AWSTemplateFormatVersion:'2010-09-09'Description:VPC whose flow log references the VPC through a short-form Ref intrinsicResources:IsolatedVPC:Type:'AWS::EC2::VPC'Properties:CidrBlock:10.0.0.0/16IsolatedLogGroup:Type:'AWS::Logs::LogGroup'Properties:RetentionInDays:14IsolatedFlowLog:Type:'AWS::EC2::FlowLog'Properties:LogGroupName:!Ref IsolatedLogGroupResourceId:!Ref IsolatedVPCResourceType:'VPC'TrafficType:ALL
Non-Compliant Code Examples
AWSTemplateFormatVersion:'2010-09-09'Description: 'VPC:public and private subnets in two availability zones, a cloudonaut.io template'Parameters:ClassB:Description:'Class B of VPC (10.XXX.0.0/16)'Type:NumberDefault:0ConstraintDescription:'Must be in the range [0-255]'MinValue:0MaxValue:255Resources:Role:Type:'AWS::IAM::Role'Properties:AssumeRolePolicyDocument:Version:'2012-10-17'Statement:- Effect:AllowPrincipal:Service:'vpc-flow-logs.amazonaws.com'Action:'sts:AssumeRole'Policies:- PolicyName:'flowlogs-policy'PolicyDocument:Version:'2012-10-17'Statement:- Effect:AllowAction:- 'logs:CreateLogStream'- 'logs:PutLogEvents'- 'logs:DescribeLogGroups'- 'logs:DescribeLogStreams'Resource:!GetAtt 'LogGroup.Arn'MyVPC:Type:'AWS::EC2::VPC'Properties:CidrBlock:!Sub '10.${ClassB}.0.0/16'EnableDnsSupport:trueEnableDnsHostnames:trueInstanceTenancy:defaultTags:- Key:NameValue:!Sub '10.${ClassB}.0.0/16'LogGroup:Type:'AWS::Logs::LogGroup'Properties:RetentionInDays:14FlowLog:Type:'AWS::EC2::FlowLog'Properties:DeliverLogsPermissionArn:!GetAtt 'Role.Arn'LogGroupName:!Ref LogGroupResourceId:!Ref MyVPC1ResourceType:'VPC'TrafficType:ACCEPT
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.