从网站上执行,但在控制台正常工作时的λ功能的NodeJS不点火
这是我创造的NodeJS使用lambda函数的第一次尝试。正确的行为是先发送电子邮件然后第二次打开Contact_Success.html
页面。
当它通过API调用网关从我的网站的功能不发送电子邮件,但它确实打开Contact_Success.html
页面。
当AWS控制台中无论是从API网关测试或拉姆达开发控制台测试,电子邮件就被发送。
下面是代码:
const AWS = require('aws-sdk');
const querystring = require('querystring');
AWS.config.region = 'us-east-1';
exports.handler = function(evt, context, callback) {
// Our raw request body will be in evt.body.
const params = querystring.parse(evt.body);
// Our field from the request.
const first_name = params['first_name'];
const last_name = params['last_name'];
const emailaddr = params['email'];
const telephone = params['telephone'];
const comments = params['comments'];
var eParams = {
Destination: {
ToAddresses: ["[email protected]"]
},
Message: {
Body: {
Text: {
// Data: first_name
Data: first_name + " " + last_name + " at " + emailaddr + " phone:" + telephone + " post:" + comments
}
},
Subject: {
Data: "BlaBlah Inquirty"
}
},
Source: ‘[email protected]'
};
// Create the promise and SES service object
const sendPromise = new AWS.SES({ apiVersion: "2010-12-01" })
.sendEmail(eParams)
.promise();
// Handle promise's fulfilled/rejected states
sendPromise
.then(data => {
console.log(data.MessageId);
// Generate HTML.
const html = `<script type="text/javascript">window.location = ".html"</script>`;
// Return HTML as the result.
callback(null, html);
context.done(null, "Success");
})
.catch(err => {
console.error(err, err.stack);
// Generate HTML.
const html = `<script type="text/javascript">window.location = ".html"</script>`;
// Return HTML as the result.
callback(null, html);
context.done(null, "Failed");
});
};
回答如下:
我将开始调试这通过查看CloudWatch的日志
从网站上执行,但在控制台正常工作时的λ功能的NodeJS不点火
这是我创造的NodeJS使用lambda函数的第一次尝试。正确的行为是先发送电子邮件然后第二次打开Contact_Success.html
页面。
当它通过API调用网关从我的网站的功能不发送电子邮件,但它确实打开Contact_Success.html
页面。
当AWS控制台中无论是从API网关测试或拉姆达开发控制台测试,电子邮件就被发送。
下面是代码:
const AWS = require('aws-sdk');
const querystring = require('querystring');
AWS.config.region = 'us-east-1';
exports.handler = function(evt, context, callback) {
// Our raw request body will be in evt.body.
const params = querystring.parse(evt.body);
// Our field from the request.
const first_name = params['first_name'];
const last_name = params['last_name'];
const emailaddr = params['email'];
const telephone = params['telephone'];
const comments = params['comments'];
var eParams = {
Destination: {
ToAddresses: ["[email protected]"]
},
Message: {
Body: {
Text: {
// Data: first_name
Data: first_name + " " + last_name + " at " + emailaddr + " phone:" + telephone + " post:" + comments
}
},
Subject: {
Data: "BlaBlah Inquirty"
}
},
Source: ‘[email protected]'
};
// Create the promise and SES service object
const sendPromise = new AWS.SES({ apiVersion: "2010-12-01" })
.sendEmail(eParams)
.promise();
// Handle promise's fulfilled/rejected states
sendPromise
.then(data => {
console.log(data.MessageId);
// Generate HTML.
const html = `<script type="text/javascript">window.location = ".html"</script>`;
// Return HTML as the result.
callback(null, html);
context.done(null, "Success");
})
.catch(err => {
console.error(err, err.stack);
// Generate HTML.
const html = `<script type="text/javascript">window.location = ".html"</script>`;
// Return HTML as the result.
callback(null, html);
context.done(null, "Failed");
});
};
回答如下:
我将开始调试这通过查看CloudWatch的日志