创建 Lambda 函数,该函数将使用 SES 接收规则解析上传到 S3 的电子邮件

Create Lambda function which will parse the emails which uploaded to S3 with SES receipt rule

我想创建 Lambda 函数来解析通过 SES 接收规则上传到 S3 存储桶的电子邮件。

通过 SES 接收规则上传到 S3 存储桶工作正常。所以,它已经经过测试并确认它可以正确上传文件。

我的 Amazon Lambda 函数:

var AWS = require('aws-sdk');
var s3 = new AWS.S3();

var bucketName = 'bucket_name/folder/destination';

exports.handler = function(event, context, callback) {
console.log('Process email');

var sesNotification = event.Records[0].ses;
console.log("SES Notification:\n", JSON.stringify(sesNotification, null, 2));

// Retrieve the email from your bucket
s3.getObject({
        Bucket: bucketName,
        Key: sesNotification.mail.messageId
    }, function(err, data) {
        if (err) {
            console.log(err, err.stack);
            callback(err);
        } else {
            console.log("Raw email:\n" + data.Body);

            // Custom email processing goes here

            callback(null, null);
        }
    });
};

上传文件时会触发 lambda,但我收到 [SignatureDoesNotMatch] 错误:

{ "errorMessage": "The request signature we calculated does not match the signature you provided. Check your key and signing method.", "errorType": "SignatureDoesNotMatch", "stackTrace": [ "Request.extractError (/var/runtime/node_modules/aws-sdk/lib/services/s3.js:524:35)", "Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)", "Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)", "Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:615:14)", "Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)", "AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)", "/var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10", "Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)", "Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:617:12)", "Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:115:18)" ] }

如果有人能帮我解决这个问题,那就太好了! 谢谢

好的,我解决了。 bucketName 应仅包含存储桶的名称。但是密钥可以包含到您文件的确切路径的其余部分 "directory".

所以,基本上 bucketName 不应该包含子文件夹,但 key 应该。

谢谢

供参考: