[英]AWS Lambda: "Cannot read property '0' of undefined"
Here is my AWS Lambda function.这是我的 AWS Lambda 函数。 However, when running it, I get
Cannot read property '0' of undefined
.但是,在运行它时,我得到了
Cannot read property '0' of undefined
。
const AWS = require('aws-sdk');
const SES = new AWS.SES();
const FROM_EMAIL_ADDRESS = process.env.FROM_EMAIL_ADDRESS;
const TO_EMAIL_ADDRESS = process.env.TO_EMAIL_ADDRESS;
function sendEmailToMe(formData) {
const emailParams = {
Source: FROM_EMAIL_ADDRESS,
ReplyToAddresses: ['keshijemi478@gmail.com'],
Destination: {
ToAddresses: [TO_EMAIL_ADDRESS],
},
Message: {
Body: {
Text: {
Charset: 'UTF-8',
Data: `Thanks for subscribe: ${formData.message}\n\n Name: ${formData.name}\n Email: ${formData.email}\n I will reply as soon as possible`,
},
},
Subject: {
Charset: 'UTF-8',
Data: 'New message from your_site.com',
},
},
};
console.log(emailParams);
const promise = SES.sendEmail(emailParams).promise();
console.log(promise);
return promise;
}
exports.handler = async(event) => {
console.log('SendEmail called');
const dynamodb = event.Records[0].dynamodb;
console.log(dynamodb);
const formData = {
name : dynamodb.NewImage.name.S,
message : dynamodb.NewImage.message.S,
email : dynamodb.NewImage.email.S
};
console.log(formData);
return sendEmailToMe(formData).then(data => {
console.log(data);
}).catch(error => {
console.log(error);
});
};
It appears that your code is an AWS Lambda function.您的代码似乎是一个 AWS Lambda 函数。
When a Lambda function is called, information is passed to the function via the event
parameter.当 Lambda 函数被调用时,信息通过
event
参数传递给函数。 The information passed via event
varies depending upon how the function was triggered.通过传递的信息
event
的变化取决于功能是如何引发的。 For example, if the function is triggered by an Amazon S3 Event, then S3 provides information in the event
parameter that describes the object that caused the event to be triggered.例如,如果函数由 Amazon S3 事件触发,则 S3 在
event
参数中提供信息,描述导致事件被触发的对象。
If, however, you trigger this event 'manually', then Amazon S3 is not involved and the event
parameter only contains the information that you provided when you invoked the function.但是,如果你触发该事件“手动”,那么亚马逊S3是不涉及与
event
参数只包含的信息,您提供的,当你调用函数。
If you are testing the function in the AWS Lambda management console, you can supply an event
via the "Configure Test" option.如果您正在 AWS Lambda 管理控制台中测试该函数,您可以通过“配置测试”选项提供一个
event
。 The event provided in this configuration will then be passed to the function being tested.此配置中提供的事件随后将传递给正在测试的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.