Skip to content
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

Bucket -> Lambda event deleted when updating prefix #1566

Closed
andrewrch opened this issue Jan 17, 2019 · 3 comments · Fixed by #4458
Closed

Bucket -> Lambda event deleted when updating prefix #1566

andrewrch opened this issue Jan 17, 2019 · 3 comments · Fixed by #4458
Assignees
Labels
@aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug.

Comments

@andrewrch
Copy link

andrewrch commented Jan 17, 2019

I successfully created a bucket with custom name and added an event handler to trigger a lambda

const bucket = new s3.Bucket(this, 'Bucket', {
    bucketName: 'custom-name'
});

bucket.grantRead(lambda.role);
bucket.onEvent(s3.EventType.ObjectCreated, lambda, {
    prefix: 'some-prefix',
    suffix: '.json'
});

This worked fine when deploying initially however when I modified the prefix and redeployed my stack, the event was actually deleted.

Cloudformation events look like this (resource names altered):

17 Jan 2019 11:35:18 | BucketNotifications1529E2E1 | DELETE_COMPLETE                     | -
17 Jan 2019 11:35:15 | BucketNotifications1529E2E1 | DELETE_IN_PROGRESS                  | -
17 Jan 2019 11:35:14 | Stack                       | UPDATE_COMPLETE_CLEANUP_IN_PROGRESS | -
17 Jan 2019 11:35:12 | BucketNotifications1529E2E1 | UPDATE_COMPLETE                     | -
17 Jan 2019 11:35:11 | BucketNotifications1529E2E1 | UPDATE_IN_PROGRESS                  | Requested update required the provider to create a new physical resource
17 Jan 2019 11:35:05 | BucketNotifications1529E2E1 | UPDATE_IN_PROGRESS                  | -
@rix0rrr rix0rrr added bug This issue is a bug. @aws-cdk/aws-s3 Related to Amazon S3 @aws-cdk/aws-events Related to CloudWatch Events labels Jan 17, 2019
@eladb eladb self-assigned this Apr 2, 2019
@eladb eladb removed their assignment May 5, 2019
@eladb eladb assigned eladb and unassigned eladb Aug 12, 2019
@eladb eladb assigned rix0rrr and unassigned eladb Sep 3, 2019
@saksiuchenka
Copy link
Contributor

I experience the same issue and found the root cause at @aws-cdk\aws-s3\lib\notifications-resource\notifications-resource-handler.ts line 138

The problem is CloudFormation sends Delete event right after Update event when PhysicalResourceId changed during Update event. It treats this condition as resource replacement.

I'd propose to change this:
PhysicalResourceId: context.logStreamName,
to that:
PhysicalResourceId: event.PhysicalResourceId || `${event.LogicalResourceId}-${props.BucketName}`,

Can I somehow create a pull request?

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 10, 2019

Yes you can!

First you fork the CDK repository to your own GitHub account, then you clone it to your disk and follow the CONTRIBUTING guide:

https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md

@saksiuchenka
Copy link
Contributor

Thank you Rico,

I just created my PR.

@mergify mergify bot closed this as completed in #4458 Oct 16, 2019
mergify bot pushed a commit that referenced this issue Oct 16, 2019
* fix(s3): bucket notifications unexpectedly deleted during stack update, closes #1566

* fix(s3): fixed integration tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants