-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ec2): Cannot deploy VPC flow log with other resources that requires bucket policies #23889
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, this is great!
Could you add the stack you included as reproduction steps as a new stack in packages/@aws-cdk/aws-ec2/test/integ.vpc-flow-logs.ts
?
It's this code:
import * as cdk from 'aws-cdk-lib';
import { RemovalPolicy, Stack } from 'aws-cdk-lib';
import { FlowLogDestination, Vpc } from 'aws-cdk-lib/aws-ec2';
import { Bucket } from 'aws-cdk-lib/aws-s3';
const stack = new Stack(new cdk.App(), "Stack");
const vpc = new Vpc(stack, 'Vpc', {
natGateways: 1,
});
const logBucket = new Bucket(stack, 'LogBucket', {
autoDeleteObjects: true,
removalPolicy: RemovalPolicy.DESTROY,
});
vpc.addFlowLog('FlowLogS3', {
destination: FlowLogDestination.toS3(logBucket, 'vpcFlowLog'),
});
Pull request has been modified.
Hi @comcalvi, thanks for the review! I added the integ test. I also added |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Closes #18985.
The problem is described on the issue. In short, when we enable VPC Flow log, it tries to create a bucket policy for the target S3 bucket. That's why a deployment fails if there is a bucket policy defined in a CFn template and the policy is created AFTER a flow log is enabled, which cannot replace the existing policy created by the flow log.
To avoid the error, this PR adds explicit dependencies for a VPC flow log resource:
autoDeleteObjects
custom resource removed (i.e. deleting all the objects in the bucket).Dependency 2 is actually not related to the original issue, but I'd like to add this because I saw the error relating this on the integration tests.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license