FlowLog

class aws_cdk.aws_ec2.FlowLog(scope, id, *, resource_type, flow_log_name=None, destination=None, traffic_type=None)

Bases: Resource

A VPC flow log.

Resource:

AWS::EC2::FlowLog

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc


log_group = logs.LogGroup(self, "MyCustomLogGroup")

role = iam.Role(self, "MyCustomRole",
    assumed_by=iam.ServicePrincipal("vpc-flow-logs.amazonaws.com")
)

ec2.FlowLog(self, "FlowLog",
    resource_type=ec2.FlowLogResourceType.from_vpc(vpc),
    destination=ec2.FlowLogDestination.to_cloud_watch_logs(log_group, role)
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • resource_type (FlowLogResourceType) – The type of resource for which to create the flow log.

  • flow_log_name (Optional[str]) – The name of the FlowLog. It is not recommended to use an explicit name. Default: If you don’t specify a flowLogName, AWS CloudFormation generates a unique physical ID and uses that ID for the group name.

  • destination (Optional[FlowLogDestination]) – 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 Default: FlowLogDestinationType.toCloudWatchLogs()

  • traffic_type (Optional[FlowLogTrafficType]) – The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic. Default: ALL

Methods

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:

policy (RemovalPolicy) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

bucket

The S3 bucket to publish flow logs to.

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

flow_log_id

The Id of the VPC Flow Log.

Attribute:

true

iam_role

The iam role used to publish logs to CloudWatch.

key_prefix

S3 bucket key prefix to publish the flow logs under.

log_group

The CloudWatch Logs LogGroup to publish flow logs to.

node

The construct tree node associated with this construct.

stack

The stack in which this resource is defined.

Static Methods

classmethod from_flow_log_id(scope, id, flow_log_id)

Import a Flow Log by it’s Id.

Parameters:
  • scope (Construct) –

  • id (str) –

  • flow_log_id (str) –

Return type:

IFlowLog

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters:

x (Any) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool