-
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
(aws-lambda-event-sources): S3EventSource
should take IBucket
instead of Bucket
#4323
Comments
+1 - This is causing us some pain around unit testing S3EventSource in C#. |
+1 - same issue for Typescript |
The underlying issue here is that CloudFormation can only set the NotificationConfiguration on a S3 Bucket in the CFN template which created the bucket. This means that if an existing S3 bucket is imported into a CDK stack then it is not possible to update the notification configuration of the bucket, even if the parameter types on Please +1 to get this changed in CFN aws-cloudformation/cloudformation-coverage-roadmap#79 |
+1 |
+1 |
@TonyFNZ Wrote:
Yes, you can see more details here: #2004
Yes, please do that :) (rather than on this cdk issue). |
Converting to a feature-request which is somewhat a duplicate of #2004. |
@TonyFNZ I think there should be another way as well. Maybe some workaround in the background without Cloudformation. The serverless team achieved it(See https://www.serverless.com/framework/docs/providers/aws/events/s3#using-existing-buckets). Then the @aws-cdk team should also find a way to solve this? |
@ThomasKiec Yes - we actually have a solution in mind and probably won't be waiting on CFN to add this support. So stay tuned. |
Any update for this issue? |
+1. Facing the same issue in our case too. |
Similar problem with 1.115.0 (Object of type @aws-cdk/aws-s3.BucketBase is not convertible to @aws-cdk/aws-s3.Bucket) |
@eladb @iliapolo Unfortunately, this is something that forces me not to use CDK on a monthly basis even though I start writing my app in CDK but then realize we cannot create a lambda event source with an existing bucket. I would really appreciate it if you could resolve this or provide some type of recommendations so I can start working on it. |
@farshadniayeshpour - have you tried using the bucket notification mechanism in the s3 module - https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-s3#bucket-notifications. This supports setting up notification on imported buckets to invoke a lambda function. |
+1. Facing the same issue. |
@nija-at using this module you can't exactly submit to Hope I didn't confuse things up ;P |
@kornicameister Subscribing all object created events is possible. When adding the event notification via See @aws-cdk/aws-s3: EventType interface A wildcard pattern is probably not useful, since currently only the event types listed here are supported by AWS. Also, the above interface contains all supported event types |
Since cdk 1.110.0, this is possible for existing buckets using Here's an example for reference: import aws_cdk.aws_s3 as s3
import aws_cdk.aws_s3_notifications as s3n
bucket = s3.Bucket.from_bucket_name(scope, 'bucket-id', bucket_name='bucket-name')
bucket.add_event_notification(s3.EventType.OBJECT_CREATED, s3n.LambdaDestination(lambda_fn), prefix="prefix/") The enhancement for this was merged in this PR: #15158 |
Does this fix also work for
|
@deepak3082, not sure about versions after cdk 1.110.0. But up to that version, only |
@ericbn .yes, my use case is to trigger lambda once a file is created/updated in s3 and i can not make any code change in the create-s3-stack. Hence, i want to update the create-lambda-stack code and add the eventsource method per aws cdk docs and I am not able to use IBucket. |
+1. Facing same issue with cdk 1.130.0 version |
+1, Any update? CDK V2 still can not use IBucket. |
any updates on this issue? 3 years later, still not fixed |
+1 |
I still get an error when trying to define the event notification on the lambda function, but things work when defining on the bucket as suggested by @ericbn. So although this issue should still be fixed, it's no longer a breaking problem. Simply create an |
In my case the solution of @ericbn proposed here worked only partially. In facts, with AttributeError: '_BucketBaseProxy' object has no attribute 'add_event_notfication' while I had no problem with My working snippet follows for reference bucket = aws_s3.Bucket.from_bucket_name(
self, id="id-bucket", bucket_name="bucket-name"
)
bucket.add_object_created_notification(
aws_s3_notifications.LambdaDestination(lambda_fn),
aws_s3.NotificationKeyFilter(prefix="someprefix/"),
) |
Using
Alternatively, using Any hope for a fix? |
I think from importing by name implies both account and region you are currently deploying to whereas the ARN version allows to explicitly set both of those. |
+1 |
…28943) ### Issue # (if applicable) Closes #4323 ### Reason for this change S3EventSource should accept `IBucket` instead of `Bucket`. `aws_s3.Bucket.from_bucket_name(...)` or `aws_s3.Bucket.from_bucket_arn(...)`, etc. returns aws_s3.IBucket type ### Description of changes Based on @otaviomacedo 's comment in #25782 , a new class `S3EventSourceV2` is implementd to accept `IBucket` instead of `Bucket`. And avoids breaking changes. ### Description of how you validated changes - unit test - integration test ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
…28943) ### Issue # (if applicable) Closes #4323 ### Reason for this change S3EventSource should accept `IBucket` instead of `Bucket`. `aws_s3.Bucket.from_bucket_name(...)` or `aws_s3.Bucket.from_bucket_arn(...)`, etc. returns aws_s3.IBucket type ### Description of changes Based on @otaviomacedo 's comment in #25782 , a new class `S3EventSourceV2` is implementd to accept `IBucket` instead of `Bucket`. And avoids breaking changes. ### Description of how you validated changes - unit test - integration test ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Reproduction Steps
Cannot import an existing s3 bucket when creating Lambda s3 events:
aws_s3.Bucket.from_bucket_name(...)
oraws_s3.Bucket.from_bucket_arn(...)
, etc. returnsaws_s3.IBucket
typeaws_lambda_event_sources.S3EventSource
only takesaws_s3.Bucket
type as a parameteraws_s3.Bucket
implementsaws_s3.IBucket
Error Log
Environment
Other
aws_lambda_event_sources.S3EventSource
should takeaws_s3.IBucket
as a parameter's type.This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: