【问题标题】:Trying to trigger a Post Confirmation Lambda trigger shows error in var aws = require('aws-sdk');尝试触发 Post Confirmation Lambda 触发器在 var aws = require('aws-sdk'); 中显示错误
【发布时间】:2020-10-02 03:40:05
【问题描述】:

这是我的代码,用于在用户验证其电子邮件时在 s3 存储桶中创建文件夹,然后 POST 确认 lambda 触发函数以在 s3 存储桶中创建文件夹。

作为AWS lambda的新手,代码显示错误,下面是我的代码。

const aws = require('aws-sdk');
const s3 = new aws.S3();
exports.handler = function(event, context) {
if (event.request.userAttributes.email) {
    put0bjectToS3('documenthandle', event.request.userAttributes.email + "/");
    console.log(" should have posted");
}
else {
    context.done(null, event);
}    
};    
function putObjectToS3(bucket, key){
console.log("got to put0bjectToS3 code");
var params = {
    Bucket : bucket,
    Key : key
};    

console.log("got past params");
s3.putObject(params, function(err, data) {
    console.log("got to put code");
    if (err) console.log("some error happened");
    else {
        console.log(" successful") ;
        context.done(null, event) ;

    }
});

} 它显示类似

的错误
Response:
{
"errorMessage": "Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line           1)",
"errorType": "Runtime.UserCodeSyntaxError",
"stackTrace": [
"  File \"/var/task/lambda_function.py\" Line 1\n    const AWS = require('aws-sdk');\n"
]
}

请给我一个解决方案,并给我关于代码的任何建议。

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-lambda amazon-cognito aws-serverless


    【解决方案1】:

    您能否确认您的 Lambda 函数正在使用哪个运行时?函数代码是用 node.js 编写的,但 Lambda 报告说它需要一个 Python 函数。

    (see the available Lambda runtimes for details)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-11
      • 2020-05-17
      • 2020-07-28
      • 2018-02-16
      • 2021-03-28
      • 1970-01-01
      • 2023-01-01
      • 1970-01-01
      相关资源
      最近更新 更多