[s3-notifications] s3 notification to lambda functions not working with existing Buckets
See original GitHub issueUsing 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
- Create a Function with “@aws-cdk/aws-lambda”
- 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:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@iliapolo Yes we can close this one as duplicate
@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?