(aws-lambda-event-sources): `S3EventSource` should take `IBucket` instead of `Bucket`
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.IBuckettype- However,
aws_lambda_event_sources.S3EventSourceonly takesaws_s3.Buckettype as a parameter - Note:
aws_s3.Bucketimplementsaws_s3.IBucket
Error Log
File "/usr/local/lib/python3.6/site-packages/jsii/_runtime.py", line 66, in __call__
inst = super().__call__(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/aws_cdk/aws_lambda_event_sources/__init__.py", line 199, in __init__
jsii.create(S3EventSource, self, [bucket, props])
File "/usr/local/lib/python3.6/site-packages/jsii/_kernel/__init__.py", line 208, in create
overrides=overrides,
File "/usr/local/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 331, in create
return self._process.send(request, CreateResponse)
File "/usr/local/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 316, in send
raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Object of type @aws-cdk/aws-s3.IBucket is not convertible to @aws-cdk/aws-s3.Bucket
Environment
- CLI Version : v1.10.1
- Framework Version: v1.10.1
- OS : Mac OS
- Language : Python
Other
aws_lambda_event_sources.S3EventSource should take aws_s3.IBucket as a parameter's type.
This is :bug: Bug Report
+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 aws_lambda_event_sources.S3EventSource are changed.
Please +1 to get this changed in CFN https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/79
+1
+1
@TonyFNZ Wrote:
The underlying issue here is that CloudFormation can only set the NotificationConfiguration on a S3 Bucket in the CFN template which created the bucket.
Yes, you can see more details here: https://github.com/aws/aws-cdk/issues/2004
Please +1 to get this changed in CFN aws-cloudformation/aws-cloudformation-coverage-roadmap#79
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?
Pending https://github.com/aws/aws-cdk/issues/2004
Looking forward to support for this
Any news here?
Even though https://github.com/aws/aws-cdk/pull/15158 was merged, we still can't change the type since it constitutes a breaking change. Would need to come up with some additive approach.
Any updates on this? We still cannot add new notifications to an existing bucket?
+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.