问题描述
这有效,但我知道它没有正确编码。我刚刚学习 AWS
并且知道我可以使用 DynamoDB
流和(可能)Kinesis?尽管我仍然是 JS
和 async/await
的新手,但目前这种方法对我来说更容易掌握。我可以要求一些说明并帮助编写正确的代码,写入 DynamoDB
并向我发送一封包含相同数据的电子邮件:
// Loads in the AWS SDK
const AWS = require('aws-sdk');
const ses = new AWS.SES({ region: "us-west-1" });
// Creates the document client specifing the region
const ddb = new AWS.DynamoDB.DocumentClient({region: 'us-west-1'});
exports.handler = async (event,context,callback) => {
// Captures the requestId from the context message
const requestId = context.awsRequestId;
// Handle promise fulfilled/rejected states
await createMessage(requestId,event).then(() => {
// If success return 201
callback(null,{
statusCode: 201,body: '',headers: {
'Access-Control-Allow-Origin' : '*'
}
});
}).catch((err) => {
// If an error occurs write to the console
console.error(err)
})
};
// Function createMessage
// Writes message to DynamoDb table Message
// Returns promise
function createMessage(requestId,event) {
let params = {
Destination: {
ToAddresses: ["myemailaddress@gmail.com"],},Message: {
Body: {
Html: { Data: event }
},Subject: { Data: `Testing IGnorE` }
},Source: "myemailaddress@gmail.com",};
// THIS WORKS BUT I KNow IT IS THE WRONG WAY TO DO IT. I ASSUME THIS SHOULD BE IT'S OWN FUNCTION
ses.sendEmail(params,function (err,data) {
if (err) {
console.log("this is error :" + err);
return;
} console.log("this is ok: " + data);
});
params = {
TableName: 'mytable',Item: event
}
return ddb.put(params).promise();
}
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)