A simple lambda function that allows access to the AWS SES V2 API from AWS Lambda, which is definetly not to use the free 62 000 emails a month.
npm i talentmaker/lambda-ses#semver:<version>
pnpm add talentmaker/lambda-ses#semver:<version>
yarn add talentmaker/lambda-ses#semver:<version>
E.G
pnpm add talentmaker/lambda-ses#semver:^1.0.0
import { LambdaClient } from "@aws-sdk/client-lambda";
import { LambdaSes } from "lambda-ses";
const config = {
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
apiVersion: "2022-01-10",
region: "us-east-1",
};
const lambda = new LambdaClient(config);
const lambdaSes = new LambdaSes(lambda, "lambda-ses");
lambdaSes.send({
email: {
from: "[email protected]",
dest: {
to: ["[email protected]"],
},
content: {
simple: {
body: {
html: {
charset: "UTF-8",
data: "<h1>Hello!</h1><br/><p>This is a message</p>",
},
},
subject: {
charset: "UTF-8",
data: "no",
},
},
},
},
});
Make sure cli_binary_format=raw-in-base64-out
{
"email": {
"from": "[email protected]",
"dest": {
"to": ["[email protected]"]
},
"content": {
"simple": {
"body": {
"html": {
"charset": "UTF-8",
"data": "<h1>Hello!</h1><br/><p>This is a message</p>"
}
},
"subject": {
"charset": "UTF-8",
"data": "no"
}
}
}
}
}
aws lambda invoke --function-name "lambda-ses" --payload "$(cat ./email.json)" /dev/stdout
- Build with docker
docker build -t ses .
docker container create --name temp ses
docker container cp temp:/go/src/github.com/talentmaker/lambda-ses/main .
docker container rm temp
- Create Lambda Function
- Upload to AWS
zip main.zip main
aws lambda update-function-code --function-name lambda-ses --zip-file fileb://main.zip