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

Add S3EventSource Not Possible with Existing Bucket #5364

Closed
joncantu opened this issue Dec 10, 2019 · 6 comments
Closed

Add S3EventSource Not Possible with Existing Bucket #5364

joncantu opened this issue Dec 10, 2019 · 6 comments
Assignees
Labels
@aws-cdk/aws-s3 Related to Amazon S3 feature-request A feature should be added or improved. p1

Comments

@joncantu
Copy link

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

@joncantu joncantu added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 10, 2019
@SomayaB SomayaB added the @aws-cdk/aws-s3 Related to Amazon S3 label Dec 10, 2019
@eladb eladb added feature-request A feature should be added or improved. p1 and removed bug This issue is a bug. labels Dec 11, 2019
@joncantu
Copy link
Author

@eladb
Going with

import s3_notify = require('@aws-cdk/aws-s3-notifications');

This doesn't work either:

    filesBucket.addEventNotification(s3.EventType.OBJECT_CREATED,
        new s3_notify.SqsDestination(ZipFileUploadQueue),
        { prefix: 'foo/', suffix: '.zip' });

I get the following error:

error TS2339: Property 'addEventNotification' does not exist on type 'IBucket'.

@joncantu
Copy link
Author

joncantu commented Dec 11, 2019

So I basically need to just setup a SNS topic for ALL file uploads to a bucket and filter inside of my lamba which is less than ideal.

@joncantu
Copy link
Author

joncantu commented Jan 3, 2020

@eladb I would argue that this is actually a bug not a feature request. Why would you not be able to perform actions such as addEventNotification to an existing bucket? This somehow seems wrong to me. Unless there is an alternative way to do this without having to create an entirely new bucket.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Jan 15, 2020
@aruneko
Copy link

aruneko commented 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.

@eladb
Copy link
Contributor

eladb commented Jan 15, 2020

Duplicate with #2004

@eladb eladb closed this as completed Jan 15, 2020
@xiangweilee
Copy link

this feature should be supported from the beginning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

5 participants