S3-Bucket Lambda-Event: kann Nicht überprüfen Sie die folgenden Ziel-Konfigurationen

Ich versuche zu erstellen, die einem S3-bucket und sofort weisen ein lambda-Benachrichtigung-Ereignis, um es.

Hier ist der node test-Skript, das ich schrieb:

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);
      }
    });
  }
});

Die Schöpfung funktioniert gut, aber das aufrufen s3.putBucketNotificationConfiguration von der aws-sdk wirft:

{ 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.<anonymous> ([...]/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> ([...]/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 }

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>InvalidArgument</Code>
    <Message>Unable to validate the following destination configurations</Message>
    <ArgumentName1>arn:aws:lambda:us-west-1:xxxxxxxxxx:function:respondS3Upload, null</ArgumentName1>
    <ArgumentValue1>Not authorized to invoke function [arn:aws:lambda:us-west-1:xxxxxxxxxx:function:respondS3Upload]</ArgumentValue1>
    <RequestId>9E1CB35811ED5828</RequestId>
    <HostId>tWcmPfrAu3As74M/0sJL5uv+pLmaD4oBJXwjzlcoOBsTBh99iRAtzAloSY/LzinSQYmj46cwyfQ=</HostId>
</Error>

Ich habe es mit einer Rolle zugeordnet sind, mit lambda, was ich denke, sind all die Maßnahmen, die es braucht. Ich könnte etwas fehlen. Ich bin mit meinem root-Zugriff-Tasten, um dieses Skript auszuführen.

S3-Bucket Lambda-Event: kann Nicht überprüfen Sie die folgenden Ziel-Konfigurationen

Habe ich gedacht, es könnte ein timing-Fehler an, wenn S3 braucht Zeit, um den Eimer vor der Zugabe der Veranstaltung, aber ich habe eine Weile gewartet, hardcoded die bucket-Namen ein, und führen Sie das Skript erneut die wirft den gleichen Fehler.

Die seltsame Sache ist, dass, wenn ich Falle hook in der S3-UI und sofort zu löschen, mein Skript funktioniert, wenn ich fest, dass Eimer Namen hinein. Es scheint, wie das erstellen das Ereignis im UI-fügt einige Berechtigungen benötigt, aber ich bin mir nicht sicher, was das wäre in der SDK oder in der console UI.

S3-Bucket Lambda-Event: kann Nicht überprüfen Sie die folgenden Ziel-Konfigurationen

Irgendwelche Gedanken oder Dinge zu versuchen? Vielen Dank für Ihre Hilfe

Schreibe einen Kommentar