question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add S3EventSource Not Possible with Existing Bucket

See original GitHub issue

I have an existing bucket that I would like to trigger a lambda whenever a zip file is uploaded so that the lambda can unzip it and process the unzipped files.

However, I cannot add S3EventSource to an existing S3 bucket. For example, this fails to compile:

    const filesBucket = s3.Bucket.fromBucketName(this, 'SBFilesBucket', props.s3Bucket);

    fileUnzipAdaptor.addEventSource(new S3EventSource(filesBucket, {
      events: [s3.EventType.OBJECT_CREATED],
      filters: [{suffix: 'zip'}] // optional
    }));

The error is:

error TS2345: Argument of type 'IBucket' is not assignable to parameter of type 'Bucket'.
  Type 'IBucket' is missing the following properties from type 'Bucket': autoCreatePolicy, lifecycleRules, notifications, metrics, and 25 more.

Is this by design? If so, how else can I obtain the desired effect?

Reproduction Steps

    const filesBucket = s3.Bucket.fromBucketName(this, 'SBFilesBucket', props.s3Bucket);

    fileUnzipAdaptor.addEventSource(new S3EventSource(filesBucket, {
      events: [s3.EventType.OBJECT_CREATED],
      filters: [{suffix: 'zip'}] // optional
    }));

Where props.s3Bucket is the name of a existing S3 bucket.

Error Log

error TS2345: Argument of type 'IBucket' is not assignable to parameter of type 'Bucket'.
  Type 'IBucket' is missing the following properties from type 'Bucket': autoCreatePolicy, lifecycleRules, notifications, metrics, and 25 more.

Environment

  • CLI Version :
  • Framework Version:
  • OS :
  • Language :

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
xiangweileecommented, Nov 2, 2020

this feature should be supported from the beginning

5reactions
arunekocommented, Jan 15, 2020

I have same problem now. An stack overflow user solves this problem with AwsCustomResource. But I think it is not smart. I would be happy to solve this problem by updating CDK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS CDK - How to add an event notification to an existing S3 ...
I managed to get this working with a custom resource. It's TypeScript, but it should be easily translated to Python: const uploadBucket =...
Read more >
class S3EventSource · AWS CDK
class S3EventSource. You are not viewing the latest version. ... Implements IEventSource. Use S3 bucket notifications as an event source for AWS Lambda....
Read more >
awslabs/aws-cdk - Gitter
That doesn't work cause bucket is an IBucket type and it needs to be a Bucket type to be an accepted param for...
Read more >
Leveraging existing event sources (S3 and CognitoUserPools)
Its very likely your organisation has had an S3 bucket or Cognito User Pool ... infrastructure changes, it not short of downsides as...
Read more >
Triggering an AWS Lambda Function For S3 File Uploads
One possible event is the creation of S3 objects (e.g., ... Lambda code 07:53 Adding a unction trigger ( S3 event source )...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found