title: S3 Bucket Lambda Event: Unable to validate the following destination configurations
body: <p>I'm trying to create an S3 bucket and immediately assign a lambda notification event to it.</p>
  
  <p>Here's the node test script I wrote:</p>
  
  
  
  <pre><code>const aws = require('aws-sdk');
  const uuidv4 = require('uuid/v4');
  
  aws.config.update({
    accessKeyId: 'key',
    secretAccessKey:'secret',
    region: 'us-west-1'
  });
  
  const s3 = new aws.S3();
  
  const params = {
    Bucket: `bucket-${uuidv4()}`,
    ACL: "private",
    CreateBucketConfiguration: {
      LocationConstraint: 'us-west-1'
    }
  };
  
  s3.createBucket(params, function (err, data) {
    if (err) {
      throw err;
    } else {
      const bucketUrl = data.Location;
  
      const bucketNameRegex = /bucket-[a-z0-9\-]+/;
      const bucketName = bucketNameRegex.exec(bucketUrl)[0];
  
      const params = {
        Bucket: bucketName,
        NotificationConfiguration: {
          LambdaFunctionConfigurations: [
            {
              Id: `lambda-upload-notification-${bucketName}`,
              LambdaFunctionArn: 'arn:aws:lambda:us-west-1:xxxxxxxxxx:function:respondS3Upload',
              Events: ['s3:ObjectCreated:CompleteMultipartUpload']
            },
          ]
        }
      };
  
      // Throws "Unable to validate the following destination configurations" until an event is manually added and deleted from the bucket in the AWS UI Console
      s3.putBucketNotificationConfiguration(params, function(err, data) {
        if (err) {
          console.error(err);
          console.error(this.httpResponse.body.toString());
        } else {
          console.log(data);
        }
      });
    }
  });
  </code></pre>
  
  <p>The creation works fine but calling <code>s3.putBucketNotificationConfiguration</code> from the <code>aws-sdk</code> throws:</p>
  
  <pre><code>{ InvalidArgument: Unable to validate the following destination configurations
      at Request.extractError ([...]/node_modules/aws-sdk/lib/services/s3.js:577:35)
      at Request.callListeners ([...]/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
      at Request.emit ([...]/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
      at Request.emit ([...]/node_modules/aws-sdk/lib/request.js:683:14)
      at Request.transition ([...]/node_modules/aws-sdk/lib/request.js:22:10)
      at AcceptorStateMachine.runTo ([...]/node_modules/aws-sdk/lib/state_machine.js:14:12)
      at [...]/node_modules/aws-sdk/lib/state_machine.js:26:10
      at Request.&lt;anonymous&gt; ([...]/node_modules/aws-sdk/lib/request.js:38:9)
      at Request.&lt;anonymous&gt; ([...]/node_modules/aws-sdk/lib/request.js:685:12)
      at Request.callListeners ([...]/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    message: 'Unable to validate the following destination configurations',
    code: 'InvalidArgument',
    region: null,
    time: 2017-11-10T02:55:43.004Z,
    requestId: '9E1CB35811ED5828',
    extendedRequestId: 'tWcmPfrAu3As74M/0sJL5uv+pLmaD4oBJXwjzlcoOBsTBh99iRAtzAloSY/LzinSQYmj46cwyfQ=',
    cfId: undefined,
    statusCode: 400,
    retryable: false,
    retryDelay: 4.3270874729153475 }
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Error&gt;
      &lt;Code&gt;InvalidArgument&lt;/Code&gt;
      &lt;Message&gt;Unable to validate the following destination configurations&lt;/Message&gt;
      &lt;ArgumentName1&gt;arn:aws:lambda:us-west-1:xxxxxxxxxx:function:respondS3Upload, null&lt;/ArgumentName1&gt;
      &lt;ArgumentValue1&gt;Not authorized to invoke function [arn:aws:lambda:us-west-1:xxxxxxxxxx:function:respondS3Upload]&lt;/ArgumentValue1&gt;
      &lt;RequestId&gt;9E1CB35811ED5828&lt;/RequestId&gt;
      &lt;HostId&gt;tWcmPfrAu3As74M/0sJL5uv+pLmaD4oBJXwjzlcoOBsTBh99iRAtzAloSY/LzinSQYmj46cwyfQ=&lt;/HostId&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p>I've run it with a role assigned to lambda with what I think are all the policies it needs. I could be missing something. I'm using my root access keys to run this script.</p>
  
  <p><a href="https://i.stack.imgur.com/IlOaH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IlOaH.png" alt="Role"></a></p>
  
  <p>I've thought it might be a timing error where S3 needs time to create the bucket before adding the event, but I've waited a while, hardcoded the bucket name, and run my script again which throws the same error.</p>
  
  <p>The weird thing is that if I create the event hook in the S3 UI and immediately delete it, my script works if I hardcode that bucket name into it. It seems like creating the event in the UI adds some needed permissions but I'm not sure what that would be in the SDK or in the console UI.</p>
  
  <p><a href="https://i.stack.imgur.com/ulRAn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ulRAn.png" alt="S3 Event Config"></a></p>
  
  <p>Any thoughts or things to try? Thanks for your help</p>