Created
October 14, 2019 23:50
-
-
Save rich-nahra/5a0e105f9b1a538b505703e9c7aca531 to your computer and use it in GitHub Desktop.
Lambda Mailer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var aws = require('aws-sdk'); | |
var ses = new aws.SES(); | |
exports.mailHandler = (event, context, callback) => { | |
console.log("subject" + event.subject); | |
var params = { | |
Destination: { | |
ToAddresses: event.to | |
}, | |
Message: { | |
Body: { | |
Text: { Data: event.body } | |
}, | |
Subject: { Data: event.subject } | |
}, | |
Source: event.sender | |
}; | |
ses.sendEmail(params, function (err, data) { | |
callback(null, {err: err, data: data}); | |
if (err) { | |
console.log(err); | |
context.fail(err); | |
} else { | |
console.log(data); | |
context.succeed(event); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Description: > | |
lambda function smtp mailer on static schedule | |
Globals: | |
Function: | |
Timeout: 3 | |
Resources: | |
SendMailFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
Policies: | |
- Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- 'ses:SendEmail' | |
- 'ses:SendRawEmail' | |
Resource: '*' | |
CodeUri: . | |
Handler: app.mailHandler | |
Runtime: nodejs10.x | |
Events: | |
SendMail: | |
Type: Schedule | |
Properties: | |
Schedule: cron(0 0 1 1 ? *) | |
Name: annual-billing-reminder | |
Description: Sends and email once per year | |
Enabled: True | |
Input: | | |
{ | |
"subject": "Annual AWS billing reminder", | |
"to": [ | |
"rich@org.local" | |
], | |
"sender": "rich@org.local", | |
"body": "This is a reminder to prepare for annual billing statement." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment