尝试触发 Post 确认 Lambda 触发器在 var aws = require('aws-sdk') 中显示错误;
Trying to trigger a Post Confirmation Lambda trigger shows error in var aws = require('aws-sdk');
这是我的代码,用于在用户验证其电子邮件时在 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"
]
}
请给我一个解决方案,并给我任何关于代码的建议。
您能确认您的 Lambda 函数使用的是哪个运行时吗?函数代码是用 node.js 编写的,但 Lambda 报告它需要一个 Python 函数。
这是我的代码,用于在用户验证其电子邮件时在 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"
]
}
请给我一个解决方案,并给我任何关于代码的建议。
您能确认您的 Lambda 函数使用的是哪个运行时吗?函数代码是用 node.js 编写的,但 Lambda 报告它需要一个 Python 函数。