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.

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

See original GitHub issue

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 Report

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:27
  • Comments:34 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
ericbncommented, Oct 7, 2021

Since cdk 1.110.0, this is possible for existing buckets using IBucket.add_event_notification as @ThomasKiec mentioned.

Here’s an example for reference:

import aws_cdk.aws_s3 as s3
import aws_cdk.aws_s3_notifications as s3n

bucket = s3.Bucket.from_bucket_name(scope, 'bucket-id', bucket_name='bucket-name')
bucket.add_event_notification(s3.EventType.OBJECT_CREATED, s3n.LambdaDestination(lambda_fn), prefix="prefix/")

The enhancement for this was merged in this PR: https://github.com/aws/aws-cdk/pull/15158

4reactions
ireneaguilar-seatcommented, Oct 15, 2020

Any update for this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lookup S3 Bucket and add a trigger to invoke a lambda
This is why the event source uses s3.Bucket instead of s3.IBucket. You could use onPutObject: const bucket = s3.Bucket.
Read more >
class S3EventSource · AWS CDK
Use S3 bucket notifications as an event source for AWS Lambda. Example. import * as eventsources from '@aws-cdk/aws-lambda- ...
Read more >
aws-cdk/aws-lambda-event-sources module
You can write Lambda functions to process S3 bucket events, such as the object-created or object-deleted events. For example, when a user uploads...
Read more >
Using AWS Lambda with Amazon S3
You can use Lambda to process event notifications from Amazon Simple Storage ... You configure notification settings on a bucket, and grant Amazon...
Read more >
aws-cdk/aws-s3 module - AWS Documentation
Most of the time, you won't have to manipulate the bucket policy directly. Instead, buckets have "grant" methods called to give prepackaged sets...
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