I am beginner, I found two instructions on the internet to get data ( Contact us - Email, Phone, etc ) to AWS - Lambda then send to my email
And another one to make a AWS - Lambda function to send to Dynamo to back up.
https://www.vairix.com/tech-blog/get-and-put-data-using-lambda-and-dynamodb-simple-and-clear
I put them together, but they don't connect. For example, Lamba trigger to send info from website to my email but the other function wont collect the item to send it to Dynamo
Lambda to send email:
var AWS = require('aws-sdk');
var ses = new AWS.SES();
var RECEIVER = '[email protected]';
var SENDER = '[email protected]';
var response = {
"isBase64Encoded": false,
"headers": { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'example.com'},
"statusCode": 200,
"body": "{\"result\": \"Success.\"}"
};
exports.handler = function (event, context) {
console.log('Received event:', event);
sendEmail(event, function (err, data) {
context.done(err, null);
});
};
function sendEmail (event, done) {
var params = {
Destination: {
ToAddresses: [
RECEIVER
]
},
Message: {
Body: {
Text: {
Data: 'name: ' + event.name + '\nphone: ' + event.phone + '\nemail: ' + event.email + '\ndesc: ' + event.desc,
Charset: 'UTF-8'
}
},
Subject: {
Data: 'Website Referral Form: ' + event.name,
Charset: 'UTF-8'
}
},
Source: SENDER
};
ses.sendEmail(params, done);
}
Lambda to store information in DynamoDB:
"use strict";
AWS.config.update({ region: "us-east-1" });
exports.handler = async() => {
const documentCilent = new AWS.DynamoDB.DocumentClient({region: "us-east-1"});
const params = {
TableName: "Users",
// This part, I need the variable connect with the top part.
Item:{
id : "test",
name: "name",
phone: "phone",
desc: "desc",
email: "email"
}
};
try {
const data = await documentCilent.put(params).promise();
console.log(data);
} catch (err) {
console.log(err);
}
};
console.log('Received event:', event);- what do you see in CloudWatch? - Ermiya Eskandary