Skip to content

Instantly share code, notes, and snippets.

@edisdev
Created January 26, 2022 00:31
Show Gist options
  • Save edisdev/c35d7add520e1e6772a9f8fe31adecc2 to your computer and use it in GitHub Desktop.
Save edisdev/c35d7add520e1e6772a9f8fe31adecc2 to your computer and use it in GitHub Desktop.
Lambda Function For SES
const aws = require('aws-sdk')
const ses = new aws.SES()
exports.handler = async (event) => {
for (const record of event.Records) {
if (record.eventName === 'INSERT') {
const newData = record.dynamodb.NewImage
const name = newData.name.S
const email = newData.email.S
const message = newData.message.S
await ses
.sendEmail({
Destination: {
ToAddresses: [process.env.SES_TO_EMAIL],
},
Source: process.env.SES_FROM_EMAIL,
Message: {
Subject: { Data: 'X Sitesinden Mesajınız Var' },
Body: {
Html: {
Data: `
<div><b>Kimden: </b>${name}(${email})<div>
</br>
<div>
<b>Mesaj:</b>
<p>${message}</p>
</div>
`
}
},
},
})
.promise()
}
}
return { status: 'done' }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment