AWS CloudFormation
User Guide (Version )

AWS::EC2::FlowLog

Specifies an Amazon Elastic Compute Cloud (Amazon EC2) flow log that captures IP traffic for a specified network interface, subnet, or VPC. To view the log data, use Amazon CloudWatch Logs (CloudWatch Logs) to help troubleshoot connection issues. For example, you can use a flow log to investigate why certain traffic isn't reaching an instance, which can help you diagnose overly restrictive security group rules. For more information, see VPC Flow Logs in the Amazon VPC User Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::EC2::FlowLog", "Properties" : { "DeliverLogsPermissionArn" : String, "LogDestination" : String, "LogDestinationType" : String, "LogGroupName" : String, "ResourceId" : String, "ResourceType" : String, "TrafficType" : String } }

YAML

Type: AWS::EC2::FlowLog Properties: DeliverLogsPermissionArn: String LogDestination: String LogDestinationType: String LogGroupName: String ResourceId: String ResourceType: String TrafficType: String

Properties

DeliverLogsPermissionArn

The ARN for the IAM role that permits Amazon EC2 to publish flow logs to a CloudWatch Logs log group in your account.

If you specify LogDestinationType as s3, do not specify DeliverLogsPermissionArn or LogGroupName.

Required: No

Type: String

Update requires: Replacement

LogDestination

Specifies the destination to which the flow log data is to be published. Flow log data can be published to a CloudWatch Logs log group or an Amazon S3 bucket. The value specified for this parameter depends on the value specified for LogDestinationType.

If LogDestinationType is not specified or cloud-watch-logs, specify the Amazon Resource Name (ARN) of the CloudWatch Logs log group.

If LogDestinationType is s3, specify the ARN of the Amazon S3 bucket. You can also specify a subfolder in the bucket. To specify a subfolder in the bucket, use the following ARN format: bucket_ARN/subfolder_name/. For example, to specify a subfolder named my-logs in a bucket named my-bucket, use the following ARN: arn:aws:s3:::my-bucket/my-logs/. You cannot use AWSLogs as a subfolder name. This is a reserved term.

Required: No

Type: String

Update requires: Replacement

LogDestinationType

Specifies the type of destination to which the flow log data is to be published. Flow log data can be published to CloudWatch Logs or Amazon S3. To publish flow log data to CloudWatch Logs, specify cloud-watch-logs. To publish flow log data to Amazon S3, specify s3.

If you specify LogDestinationType as s3, do not specify DeliverLogsPermissionArn or LogGroupName.

Default: cloud-watch-logs

Required: No

Type: String

Allowed Values: cloud-watch-logs | s3

Update requires: Replacement

LogGroupName

The name of a new or existing CloudWatch Logs log group where Amazon EC2 publishes your flow logs.

If you specify LogDestinationType as s3, do not specify DeliverLogsPermissionArn or LogGroupName.

Required: No

Type: String

Update requires: Replacement

ResourceId

The ID of the subnet, network interface, or VPC for which you want to create a flow log.

Constraints: Maximum of 1000 resources

Required: Yes

Type: String

Update requires: Replacement

ResourceType

The type of resource for which to create the flow log. For example, if you specified a VPC ID for the ResourceId property, specify VPC for this property.

Required: Yes

Type: String

Allowed Values: NetworkInterface | Subnet | VPC

Update requires: Replacement

TrafficType

The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic.

Required: Yes

Type: String

Allowed Values: ACCEPT | ALL | REJECT

Update requires: Replacement

Return Values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the flow log ID, such as fl-1a23b456.

For more information about using the Ref function, see Ref.

Examples

Creating a flow log that monitors all traffic types

The following example creates a flow log for the VPC called MyVPC and logs all traffic types. Amazon EC2 publishes the logs to the FlowLogsGroup log group.

JSON

"MyFlowLog" : { "Type" : "AWS::EC2::FlowLog", "Properties" : { "DeliverLogsPermissionArn" : { "Fn::GetAtt" : ["FlowLogRole", "Arn"] }, "LogGroupName" : "FlowLogsGroup", "ResourceId" : { "Ref" : "MyVPC" }, "ResourceType" : "VPC", "TrafficType" : "ALL" } }

YAML

MyFlowLog: Type: AWS::EC2:FlowLog Properties: DeliverLogsPermissionArn: !GetAtt FlowLogRole.Arn LogGroupName: FlowLogsGroup ResourceId: !Ref MyVPC ResourceType: VPC TrafficType: ALL