Skip to content

Commit

Permalink
IT-2314 add flow logging
Browse files Browse the repository at this point in the history
  • Loading branch information
brucehoff committed Dec 19, 2024
1 parent f56dddb commit efa7d8c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/vpc_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from aws_cdk import (Stack,
aws_ec2 as ec2,
aws_s3 as s3,
Tags)

from constructs import Construct

VPC_CIDR_CONTEXT= "VPC_CIDR"
FLOW_LOGS_BUCKET="sagebase-vpc-flow-logs-bucket-bucket-5lvxjv2gp37h"

class VpcStack(Stack):

Expand All @@ -18,6 +20,10 @@ def __init__(self, scope: Construct, context: str, env: dict, **kwargs) -> None:
cidr=env.get(VPC_CIDR_CONTEXT),
max_azs=2)

bucket_arn=f"arn:aws:s3:::{FLOW_LOGS_BUCKET}"
bucket=s3.Bucket.from_bucket_attributes(self, id=FLOW_LOGS_BUCKET, bucket_arn=bucket_arn)
self.vpc.add_flow_log(f"{stack_id}-FlowLogS3",destination=ec2.FlowLogDestination.to_s3(bucket=bucket))

# Tag all resources in this Stack's scope with context tags
for key, value in env.get(config.TAGS_CONTEXT).items():
Tags.of(scope).add(key, value)

0 comments on commit efa7d8c

Please sign in to comment.