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)

Most upvoted comments

hi @NGL321

Switching to fromFunctionAttributes produces the same Unable to validate the following destination configurations. error.

Here is what I changed to:

    const importedLambdaFromArn = lambda.Function.fromFunctionAttributes(
      this,
      'external-lambda-from-arn',
      {
        functionArn: 'my-arn',
      }
    );

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.

We have met the same issue, but in SQS case. And we found this is an occasional issue.

We pointed the S3 event notification to an SQS with the following code,

// Add the S3 event on the log bucket with the target is sqs queue
logBucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.SqsDestination(logEventQueue), {
     prefix: props.logBucketPrefix
})

but got the same error "Error: An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operation: Unable to validate the following destination configurations. See the details in CloudWatch Log Stream: "

And we had a look at the CloudWatch Log, but we cannot find some useful information. Here is the CloudWatch Log:

START RequestId: 41419846-addb-4806-b7dc-340c1ae7a2f9 Version: $LATEST
[ERROR] 2022-05-24T05:25:08.232Z 41419846-addb-4806-b7dc-340c1ae7a2f9 Failed to put bucket notification configuration
Traceback (most recent call last):
File "/var/task/index.py", line 28, in handler
put_bucket_notification_configuration(bucket, config)
File "/var/task/index.py", line 79, in put_bucket_notification_configuration
s3.put_bucket_notification_configuration(Bucket=bucket, NotificationConfiguration=notification_configuration)
File "/var/runtime/botocore/client.py", line 391, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 719, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operation: Unable to validate the following destination configurations
Status code: OK
END RequestId: 41419846-addb-4806-b7dc-340c1ae7a2f9
REPORT RequestId: 41419846-addb-4806-b7dc-340c1ae7a2f9 Duration: 1053.50 ms Billed Duration: 1054 ms Memory Size: 128 MB Max Memory Used: 73 MB Init Duration: 449.19 ms 
START RequestId: d78e4fd9-0e9a-4aba-8682-0ecc43969805 Version: $LATEST
Status code: OK
END RequestId: d78e4fd9-0e9a-4aba-8682-0ecc43969805
REPORT RequestId: d78e4fd9-0e9a-4aba-8682-0ecc43969805 Duration: 574.22 ms Billed Duration: 575 ms Memory Size: 128 MB Max Memory Used: 73 MB

And the workaround is delete the CloudFormation Stack and redeploy it.

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

b'<?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>InvalidArgument</Code><Message>Unable to validate the following destination configurations</Message><ArgumentName1>arn:aws:sqs:eu-north-1:*****:tCaT-clo-cognito-571690-CLFlbConfUploadingEventQueueAB242C04-ittCZ64K0mAg</ArgumentName1><ArgumentValue1>Permissions on the destination queue do not allow S3 to publish notifications from this bucket</ArgumentValue1><RequestId>SMY8RNEEN1PY4QB9</RequestId><HostId>YxuzvmGghxa3uVJ/o3OPB2wshteBI+1oWQWxSqY5g0ZKm5aLeW/tHBSIDXWiw8sOafq7NdD/BaI=</HostId></Error>'

The following is how I manually edit the generated template.

    "BucketNotificationsHandler050a0587b7544547bf325f094a3db8347ECC3691": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Description": "AWS CloudFormation handler for \"Custom::S3BucketNotifications\" resources (@aws-cdk/aws-s3)",
        "Code": {
          "ZipFile": "import boto3  # type: ignore\nimport json\nimport logging\nimport urllib.request\nboto3.set_stream_logger(\"botocore\", logging.DEBUG)\n\n ...

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 operation

let bucket = new s3.Bucket(this, "Bucket", {
  bucketName: bucketName
}

// new code
const snsTopic = sns.Topic.fromTopicArn(
  this,
  `snsTopic`,
  "arn"
);

bucket.addEventNotification(
  s3.EventType.OBJECT_CREATED
  new s3n.SnsDestination(snsTopic)
);

Is there a workaround?

Similar to #28915