aws-cdk: (aws-s3-notifications): Unable to validate the following destination configurations.
What is the problem?
Error: An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operation: Unable to validate the following destination configurations. See the details in CloudWatch Log Stream:
Cloudwatch Log Stream didn’t seem to have further details.
Reproduction Steps
const importedBucketFromName = s3.Bucket.fromBucketName(
this,
'imported-bucket-from-name',
'bucket-name'
);
const importedLambdaFromArn = lambda.Function.fromFunctionArn(
this,
'external-lambda-from-arn',
'lambda-arn'
);
importedBucketFromName.addEventNotification(
s3.EventType.OBJECT_CREATED,
new s3n.LambdaDestination(importedLambdaFromArn),
{ prefix: 'test/', suffix: '.yaml' }
);
What did you expect to happen?
Bucket would have an event notification for the given config pointing to the lambda.
What actually happened?
Error shown was generated.
CDK CLI Version
2.2.0 (build 4f5c27c)
Framework Version
n/a
Node.js Version
16.11
OS
OSX
Language
Typescript
Language Version
TypeScript (4.4.4)
Other information
From what I have read this seems to be caused by a missing policy on either the S3 Bucket or Lambda function or both. My attempts to add these policies have not worked.
Perhaps this issue stems from both resources(lambda, bucket) being imported, and thus addEventNotification is not able to add the required policies. Any workaround would be greatly apprecaited.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 11
- Comments: 18 (3 by maintainers)
I had the same issue. You need to set “sameEnvironment” flag to “true” in fromFunctionAttributes() to allow CDK has permission to update your external lambda function.
something like:
{ functionArn: 'my-arn', sameEnvironment: true }Hi @NGL321, I am trying to plan feature development around this issue. I am wondering if it’s possible to get an idea of when this issue might be resolved. This way I can decide if it makes sense to look into a workaround.
Thanks in advance for any details.
By manually adding
boto3.set_stream_logger(\"botocore\", logging.DEBUG)to the custom resource lambda generated by cdk for BucketNotifications, I found that the root cause of the error was due to insufficient permissions on the destination queue, preventing S3 from publishing notifications from the bucket. Given that the sqs access policy may take some time to propagate, the best solution would be to incorporate retry logic into the put bucket notification custom resource lambda.The following is the boto3 debug log
The following is how I manually edit the generated template.
We had the same issue. I contacted AWS support, and they were able to tell us that we had an existing event notification in the bucket for which the destination didn’t exist anymore. We removed that notification and afterwards CDK could create the new event notification configuration correctly.
I have also been coming across the same issue, my work around was to go and manually create it via console and then delete the same event notification. After doing this I was able to successfully deploy the event notification to AWS.
Not an ideal work around, but at least our CDK is not complaining… Something behind the scenes with AWS must get created and not deleted following this.
This fixed it for me: https://sagargiri.com/s3-event-notification-issue
$ aws lambda add-permission
–function-name TestFunc:dev
–profile default
–statement-id AllowToBeInvoked
–action “lambda:InvokeFunction”
–principal s3.amazonaws.com
–source-arn “arn:aws:s3:::MyAwesomeBucket”
–source-account 123456789101
I am facing the same issue when adding a new SNS event notification to my already-created S3 bucket. The bucket is created using CDK only.
Error -
An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operationIs there a workaround?
Similar to #28915