简体   繁体   English

AWS Lambda:“无法读取未定义的属性‘0’”

[英]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.

相关问题 AWS Lambda TypeError:无法读取未定义的属性“ toString” - AWS lambda TypeError: Cannot read property 'toString' of undefined AWS Lambda 函数:无法读取未定义的属性“logs”“numberOfPages”“stream”。 包问题还是 AWS Lambda 问题? - AWS Lambda Function: Cannot read property 'logs' 'numberOfPages' 'stream' of undefined. Package issue or AWS Lambda issue? AWS Lambda 与 typescript 获取无法读取异步处理程序内部未定义的属性 - AWS Lambda with typescript getting Cannot read property of undefined inside async handler AWS Lambda 上的 Apollo 网关无法读取未定义的属性“内容类型” - Apollo Gateway on AWS Lambda Cannot read property 'content-type' of undefined AWS Lambda event.pathParameters 未定义,因此无法解构属性 - AWS Lambda event.pathParameters is undefined and hence cannot destructure a property Lambda 给了我调用错误 - 无法读取未定义的属性“方法” - Lambda is giving me Invoke Error - Cannot read property 'method' of undefined Lambda function 错误消息“:”无法读取未定义的属性“桶” - Lambda function errorMessage“: ”Cannot read property 'bucket' of undefined 无法读取未定义的属性“文件名”,将 html-pdf 与 lambda 一起使用 - Cannot read property 'filename' of undefined Using html-pdf with lambda 在 Jest 中模拟 Lambda 回调? (无法读取未定义的属性主体) - Mock Lambda callback in Jest? (Cannot read property body of undefined) AWS SDK v3 TransactWriteItemsCommand 类型错误:无法读取未定义的属性“0” - AWS SDK v3 TransactWriteItemsCommand TypeError: Cannot read property '0' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM