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.

[s3-notifications] s3 notification to lambda functions not working with existing Buckets

See original GitHub issue

Using S3EventSource to create a lambda triggered by S3 Object_Created events of a bucket which already exists. If you follow the instruction in the documentation (https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-event-sources-readme.html#s3) the resources cannot be created due to the following type mismatch:

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 33 more.

Reproduction Steps

  1. Create a Function with “@aws-cdk/aws-lambda
  2. Add EventSource using S3EventSource (“@aws-cdk/aws-lambda-event-sources”) of external bucket (“@aws-cdk/aws-s3”)
const function = new Function(stack, 'SomeFunction', { ... })
const bucket = Bucket.fromBucketName(stack, 'SomeBucket', bucketName)
function.addEventSource(
  new S3EventSource(bucket, {
      events: [EventType.OBJECT_CREATED]
})
)

What did you expect to happen?

I expected that creating a S3/Lambda trigger would be very easy with “@aws-cdk/aws-lambda-event-sources” without type errors. The deployment of such easy things should be so easy. This is not the first time I have experienced problems with types or functions that do not allow to do what they should be able to do… I don’t understand why the Bucket returned by Bucket.fromBucketName is something different from new Bucket(). Both Bucket(s) are from the same lib and nevertheless have different types.

What actually happened?

Type Errors during development and deployment

Environment

  • **CLI Version : “aws-cdk”: “1.60.0”,
  • **Node.js Version: 12
  • **OS : mac/ linux
  • **Language (Version): TypeScript (3.9.3)

Other

/Volumes/Workspace/project/node_modules/@aws-cdk/aws-lambda-event-sources/lib/s3.ts:31
      this.bucket.addEventNotification(event, new notifs.LambdaDestination(target), ...filters);
                          ^
TypeError: this.bucket.addEventNotification is not a function
    at S3EventSource.bind (/Volumes/Workspace/project/node_modules/@aws-cdk/aws-lambda-event-sources/lib/s3.ts:31:19)
    at Function.addEventSource (/Volumes/Workspace/project/node_modules/@aws-cdk/aws-lambda/lib/function-base.ts:309:12)
    at Object.<anonymous> (/Volumes/Workspace/project/cdk/functions/somefunction.ts:33:14)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Module.m._compile (/Volumes/Workspace/project/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Object.require.extensions.<computed> [as .ts] (/Volumes/Workspace/project/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ThomasKieccommented, Sep 2, 2020

@iliapolo Yes we can close this one as duplicate

0reactions
iliapolocommented, Sep 2, 2020

@ThomasKiec We already have an issue for this: https://github.com/aws/aws-cdk/issues/2004.

Can you look it over and let us know if its ok to close this one as duplicate?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Lambda invoke errors for Amazon S3 event ...
A Lambda function's resource-based policy is deleted or removed and the changes are saved to an Amazon S3 event notification for that function....
Read more >
Unable to link AWS S3 with AWS Lambda - Stack Overflow
This problem occurs when (clearly stated by the error message) Lambda and S3 buckets are residing in different regions. For creating lambda in ......
Read more >
Why I Wouldn't Choose S3 Bucket Notifications Again
AWS offers S3 bucket notifications for sending events to Lambdas and also other services like SQS and SNS. In plenty of places, we...
Read more >
Using an Amazon S3 trigger to invoke a Lambda function
The Lambda function retrieves the source S3 bucket name and the key name of the uploaded object from the event parameter that it...
Read more >
Create S3 Event Notification using AWS Lambda Function
Using Amazon S3 Event Notifications, you can be notified when certain events occur in your S3 bucket. Configure Amazon S3 to publish events ......
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