aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(aws-lambda-event-sources): `S3EventSource` should take `IBucket` instead of `Bucket`

Open guangyuzh opened this issue 7 years ago • 36 comments

Reproduction Steps

Cannot import an existing s3 bucket when creating Lambda s3 events:

  1. aws_s3.Bucket.from_bucket_name(...) or aws_s3.Bucket.from_bucket_arn(...), etc. returns aws_s3.IBucket type
  2. However, aws_lambda_event_sources.S3EventSource only takes aws_s3.Bucket type as a parameter
  3. Note: aws_s3.Bucket implements aws_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

guangyuzh avatar Oct 01 '19 18:10 guangyuzh

+1 - This is causing us some pain around unit testing S3EventSource in C#.

AjkayAlan avatar Mar 12 '20 14:03 AjkayAlan

+1 - same issue for Typescript

leantorres73 avatar Apr 29 '20 19:04 leantorres73

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

TonyFNZ avatar May 06 '20 10:05 TonyFNZ

+1

purnesh avatar May 06 '20 11:05 purnesh

+1

pigna90 avatar Jul 06 '20 12:07 pigna90

@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).

iliapolo avatar Jul 10 '20 12:07 iliapolo

Converting to a feature-request which is somewhat a duplicate of #2004.

iliapolo avatar Jul 10 '20 12:07 iliapolo

@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 avatar Aug 21 '20 12:08 ThomasKiec

@ThomasKiec Yes - we actually have a solution in mind and probably won't be waiting on CFN to add this support. So stay tuned.

iliapolo avatar Aug 23 '20 10:08 iliapolo

Any update for this issue?

ireneaguilar-seat avatar Oct 15 '20 08:10 ireneaguilar-seat

Pending https://github.com/aws/aws-cdk/issues/2004

iliapolo avatar Oct 15 '20 10:10 iliapolo

Looking forward to support for this

chidifrank avatar Feb 12 '21 22:02 chidifrank

Any news here?

FreeWillaert avatar Jun 11 '21 08:06 FreeWillaert

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.

iliapolo avatar Jun 20 '21 14:06 iliapolo

Any updates on this? We still cannot add new notifications to an existing bucket?

farshadniayeshpour avatar Jul 01 '21 14:07 farshadniayeshpour

+1. Facing the same issue in our case too.

itharavi avatar Jul 03 '21 04:07 itharavi

Similar problem with 1.115.0 (Object of type @aws-cdk/aws-s3.BucketBase is not convertible to @aws-cdk/aws-s3.Bucket)

istvanszabo92 avatar Jul 23 '21 08:07 istvanszabo92

@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 avatar Sep 08 '21 14:09 farshadniayeshpour

@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.

nija-at avatar Sep 10 '21 13:09 nija-at

+1. Facing the same issue.

LucasOliveiraS avatar Sep 27 '21 15:09 LucasOliveiraS