FlowLog
Provides a VPC/Subnet/ENI Flow Log to capture IP traffic for a specific network interface, subnet, or VPC. Logs are sent to a CloudWatch Log Group or a S3 Bucket.
Example Usage
CloudWatch Logging
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var exampleLogGroup = new Aws.CloudWatch.LogGroup("exampleLogGroup", new Aws.CloudWatch.LogGroupArgs
{
});
var exampleRole = new Aws.Iam.Role("exampleRole", new Aws.Iam.RoleArgs
{
AssumeRolePolicy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Sid"": """",
""Effect"": ""Allow"",
""Principal"": {
""Service"": ""vpc-flow-logs.amazonaws.com""
},
""Action"": ""sts:AssumeRole""
}
]
}
",
});
var exampleFlowLog = new Aws.Ec2.FlowLog("exampleFlowLog", new Aws.Ec2.FlowLogArgs
{
IamRoleArn = exampleRole.Arn,
LogDestination = exampleLogGroup.Arn,
TrafficType = "ALL",
VpcId = aws_vpc.Example.Id,
});
var exampleRolePolicy = new Aws.Iam.RolePolicy("exampleRolePolicy", new Aws.Iam.RolePolicyArgs
{
Policy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": [
""logs:CreateLogGroup"",
""logs:CreateLogStream"",
""logs:PutLogEvents"",
""logs:DescribeLogGroups"",
""logs:DescribeLogStreams""
],
""Effect"": ""Allow"",
""Resource"": ""*""
}
]
}
",
Role = exampleRole.Id,
});
}
}
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/cloudwatch"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/iam"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
exampleLogGroup, err := cloudwatch.NewLogGroup(ctx, "exampleLogGroup", nil)
if err != nil {
return err
}
exampleRole, err := iam.NewRole(ctx, "exampleRole", &iam.RoleArgs{
AssumeRolePolicy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Sid\": \"\",\n", " \"Effect\": \"Allow\",\n", " \"Principal\": {\n", " \"Service\": \"vpc-flow-logs.amazonaws.com\"\n", " },\n", " \"Action\": \"sts:AssumeRole\"\n", " }\n", " ]\n", "}\n", "\n")),
})
if err != nil {
return err
}
_, err = ec2.NewFlowLog(ctx, "exampleFlowLog", &ec2.FlowLogArgs{
IamRoleArn: exampleRole.Arn,
LogDestination: exampleLogGroup.Arn,
TrafficType: pulumi.String("ALL"),
VpcId: pulumi.String(aws_vpc.Example.Id),
})
if err != nil {
return err
}
_, err = iam.NewRolePolicy(ctx, "exampleRolePolicy", &iam.RolePolicyArgs{
Policy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Action\": [\n", " \"logs:CreateLogGroup\",\n", " \"logs:CreateLogStream\",\n", " \"logs:PutLogEvents\",\n", " \"logs:DescribeLogGroups\",\n", " \"logs:DescribeLogStreams\"\n", " ],\n", " \"Effect\": \"Allow\",\n", " \"Resource\": \"*\"\n", " }\n", " ]\n", "}\n", "\n")),
Role: exampleRole.ID(),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
example_log_group = aws.cloudwatch.LogGroup("exampleLogGroup")
example_role = aws.iam.Role("exampleRole", assume_role_policy="""{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "vpc-flow-logs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
""")
example_flow_log = aws.ec2.FlowLog("exampleFlowLog",
iam_role_arn=example_role.arn,
log_destination=example_log_group.arn,
traffic_type="ALL",
vpc_id=aws_vpc["example"]["id"])
example_role_policy = aws.iam.RolePolicy("exampleRolePolicy",
policy="""{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
""",
role=example_role.id)import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const exampleLogGroup = new aws.cloudwatch.LogGroup("example", {});
const exampleRole = new aws.iam.Role("example", {
assumeRolePolicy: `{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "vpc-flow-logs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
`,
});
const exampleFlowLog = new aws.ec2.FlowLog("example", {
iamRoleArn: exampleRole.arn,
logDestination: exampleLogGroup.arn,
trafficType: "ALL",
vpcId: aws_vpc_example.id,
});
const exampleRolePolicy = new aws.iam.RolePolicy("example", {
policy: `{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
`,
role: exampleRole.id,
});S3 Logging
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var exampleBucket = new Aws.S3.Bucket("exampleBucket", new Aws.S3.BucketArgs
{
});
var exampleFlowLog = new Aws.Ec2.FlowLog("exampleFlowLog", new Aws.Ec2.FlowLogArgs
{
LogDestination = exampleBucket.Arn,
LogDestinationType = "s3",
TrafficType = "ALL",
VpcId = aws_vpc.Example.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
exampleBucket, err := s3.NewBucket(ctx, "exampleBucket", nil)
if err != nil {
return err
}
_, err = ec2.NewFlowLog(ctx, "exampleFlowLog", &ec2.FlowLogArgs{
LogDestination: exampleBucket.Arn,
LogDestinationType: pulumi.String("s3"),
TrafficType: pulumi.String("ALL"),
VpcId: pulumi.String(aws_vpc.Example.Id),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
example_bucket = aws.s3.Bucket("exampleBucket")
example_flow_log = aws.ec2.FlowLog("exampleFlowLog",
log_destination=example_bucket.arn,
log_destination_type="s3",
traffic_type="ALL",
vpc_id=aws_vpc["example"]["id"])import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const exampleBucket = new aws.s3.Bucket("example", {});
const exampleFlowLog = new aws.ec2.FlowLog("example", {
logDestination: exampleBucket.arn,
logDestinationType: "s3",
trafficType: "ALL",
vpcId: aws_vpc_example.id,
});Create a FlowLog Resource
new FlowLog(name: string, args: FlowLogArgs, opts?: CustomResourceOptions);def FlowLog(resource_name, opts=None, eni_id=None, iam_role_arn=None, log_destination=None, log_destination_type=None, log_format=None, log_group_name=None, max_aggregation_interval=None, subnet_id=None, tags=None, traffic_type=None, vpc_id=None, __props__=None);func NewFlowLog(ctx *Context, name string, args FlowLogArgs, opts ...ResourceOption) (*FlowLog, error)public FlowLog(string name, FlowLogArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args FlowLogArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args FlowLogArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args FlowLogArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
FlowLog Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The FlowLog resource accepts the following input properties:
- Traffic
Type string The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- Eni
Id string Elastic Network Interface ID to attach to
- Iam
Role stringArn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- Log
Destination string The ARN of the logging destination.
- Log
Destination stringType The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- Log
Format string The fields to include in the flow log record, in the order in which they should appear.
- Log
Group stringName Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- Max
Aggregation intInterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- Subnet
Id string Subnet ID to attach to
- Dictionary<string, string>
Key-value map of resource tags
- Vpc
Id string VPC ID to attach to
- Traffic
Type string The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- Eni
Id string Elastic Network Interface ID to attach to
- Iam
Role stringArn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- Log
Destination string The ARN of the logging destination.
- Log
Destination stringType The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- Log
Format string The fields to include in the flow log record, in the order in which they should appear.
- Log
Group stringName Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- Max
Aggregation intInterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- Subnet
Id string Subnet ID to attach to
- map[string]string
Key-value map of resource tags
- Vpc
Id string VPC ID to attach to
- traffic
Type string The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- eni
Id string Elastic Network Interface ID to attach to
- iam
Role stringArn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- log
Destination string The ARN of the logging destination.
- log
Destination stringType The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- log
Format string The fields to include in the flow log record, in the order in which they should appear.
- log
Group stringName Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- max
Aggregation numberInterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- subnet
Id string Subnet ID to attach to
- {[key: string]: string}
Key-value map of resource tags
- vpc
Id string VPC ID to attach to
- traffic_
type str The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- eni_
id str Elastic Network Interface ID to attach to
- iam_
role_ strarn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- log_
destination str The ARN of the logging destination.
- log_
destination_ strtype The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- log_
format str The fields to include in the flow log record, in the order in which they should appear.
- log_
group_ strname Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- max_
aggregation_ floatinterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- subnet_
id str Subnet ID to attach to
- Dict[str, str]
Key-value map of resource tags
- vpc_
id str VPC ID to attach to
Outputs
All input properties are implicitly available as output properties. Additionally, the FlowLog resource produces the following output properties:
Look up an Existing FlowLog Resource
Get an existing FlowLog resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: FlowLogState, opts?: CustomResourceOptions): FlowLogstatic get(resource_name, id, opts=None, arn=None, eni_id=None, iam_role_arn=None, log_destination=None, log_destination_type=None, log_format=None, log_group_name=None, max_aggregation_interval=None, subnet_id=None, tags=None, traffic_type=None, vpc_id=None, __props__=None);func GetFlowLog(ctx *Context, name string, id IDInput, state *FlowLogState, opts ...ResourceOption) (*FlowLog, error)public static FlowLog Get(string name, Input<string> id, FlowLogState? state, CustomResourceOptions? opts = null)- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
The following state arguments are supported:
- Arn string
The ARN of the Flow Log.
- Eni
Id string Elastic Network Interface ID to attach to
- Iam
Role stringArn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- Log
Destination string The ARN of the logging destination.
- Log
Destination stringType The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- Log
Format string The fields to include in the flow log record, in the order in which they should appear.
- Log
Group stringName Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- Max
Aggregation intInterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- Subnet
Id string Subnet ID to attach to
- Dictionary<string, string>
Key-value map of resource tags
- Traffic
Type string The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- Vpc
Id string VPC ID to attach to
- Arn string
The ARN of the Flow Log.
- Eni
Id string Elastic Network Interface ID to attach to
- Iam
Role stringArn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- Log
Destination string The ARN of the logging destination.
- Log
Destination stringType The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- Log
Format string The fields to include in the flow log record, in the order in which they should appear.
- Log
Group stringName Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- Max
Aggregation intInterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- Subnet
Id string Subnet ID to attach to
- map[string]string
Key-value map of resource tags
- Traffic
Type string The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- Vpc
Id string VPC ID to attach to
- arn string
The ARN of the Flow Log.
- eni
Id string Elastic Network Interface ID to attach to
- iam
Role stringArn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- log
Destination string The ARN of the logging destination.
- log
Destination stringType The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- log
Format string The fields to include in the flow log record, in the order in which they should appear.
- log
Group stringName Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- max
Aggregation numberInterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- subnet
Id string Subnet ID to attach to
- {[key: string]: string}
Key-value map of resource tags
- traffic
Type string The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- vpc
Id string VPC ID to attach to
- arn str
The ARN of the Flow Log.
- eni_
id str Elastic Network Interface ID to attach to
- iam_
role_ strarn The ARN for the IAM role that’s used to post flow logs to a CloudWatch Logs log group
- log_
destination str The ARN of the logging destination.
- log_
destination_ strtype The type of the logging destination. Valid values:
cloud-watch-logs,s3. Default:cloud-watch-logs.- log_
format str The fields to include in the flow log record, in the order in which they should appear.
- log_
group_ strname Deprecated: Use
log_destinationinstead. The name of the CloudWatch log group.- max_
aggregation_ floatinterval The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. Valid Values:
60seconds (1 minute) or600seconds (10 minutes). Default:600.- subnet_
id str Subnet ID to attach to
- Dict[str, str]
Key-value map of resource tags
- traffic_
type str The type of traffic to capture. Valid values:
ACCEPT,REJECT,ALL.- vpc_
id str VPC ID to attach to
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.