-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
aws-lambda-event-sources: S3EventSource Requires Bucket, but only needs an IBucket #23940
Comments
Thanks for this request, it looks to me like it's not necessary to only allow a However there is already an existing check for this: aws-cdk/packages/@aws-cdk/aws-s3-notifications/lib/lambda.ts Lines 17 to 20 in c164a49
If properly documented we could be able to allow for imported buckets to be used here to allow for more use cases I am marking this issue as p2, which means that we are unable to work on this immediately. |
+1 |
1 similar comment
+1 |
Tested on 2.81.0, this is not fixed yet. In case you are having the same issue, here's my alternative solution: bucket = s3.Bucket.from_bucket_attributes(
self,
"ImportedBucket",
bucket_arn=f"arn:aws:s3:::{self.env.s3dir_source.bucket}",
)
use latest
bucket.add_event_notification(
s3.EventType.OBJECT_CREATED,
s3_notifications.LambdaDestination(
self.lambda_func_mapper[self.env.lbd_s3sync.name][KEY_FUNC],
),
s3.NotificationKeyFilter(
prefix=f"{self.env.s3dir_source.key}",
),
)
use alias
bucket.add_event_notification(
s3.EventType.OBJECT_CREATED,
s3_notifications.LambdaDestination(
lambda_.Function.from_function_attributes(
self,
f"LambdaAliasAttribute{self.env.lbd_s3sync.short_name_camel}",
function_arn=self.lambda_func_mapper[self.env.lbd_s3sync.name][KEY_ALIAS].function_arn,
same_environment=True,
),
),
s3.NotificationKeyFilter(
prefix=f"{self.env.s3dir_source.key}",
),
) |
This appears to be a duplicate of this older issue: #4323. I'm going to close this in order to consolidate issues. |
|
Describe the bug
I want to use an externally created bucket as an event notification source for a lambda
Expected Behavior
An IBucket can be used as the notification source
Current Behavior
Type errors. An
IBucket
cannot be assigned to aBucket
.Reproduction Steps
Possible Solution
Since
addEventNotification
is the only method used by S3EventSource and is available on an IBucket, I think it should be safe to loosen the type restriction to IBucket.Coercing the type and deploying works.
Additional Information/Context
No response
CDK CLI Version
2.40.0
Framework Version
No response
Node.js Version
16
OS
OSX
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: