lambda-ses

command module
v0.0.0-...-781d4f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Lambda SES

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.

Installing node-client

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

Examples

node-client with SDK V3
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: "luke_zhang_04@protonmail.com",
        dest: {
            to: ["luke_zhang_04@protonmail.com"],
        },
        content: {
            simple: {
                body: {
                    html: {
                        charset: "UTF-8",
                        data: "<h1>Hello!</h1><br/><p>This is a message</p>",
                    },
                },
                subject: {
                    charset: "UTF-8",
                    data: "no",
                },
            },
        },
    },
});
CLI V2

Make sure cli_binary_format=raw-in-base64-out

{
    "email": {
        "from": "luke_zhang_04@protonmail.com",
        "dest": {
            "to": ["luke_zhang_04@protonmail.com"]
        },
        "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

Uploading to AWS

  1. 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
  1. Create Lambda Function

Lambda Config

  1. Upload to AWS
zip main.zip main
aws lambda update-function-code --function-name lambda-ses --zip-file fileb://main.zip

Documentation

Overview

SESv2 API interactions through AWS Lambda Copyright 2021 - 2022 Luke Zhang BSD-3-Clause License

Redefinition of SESV2 types with json field declarations Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright 2014-2015 Stripe, Inc. Copyright 2021 - 2022 Luke Zhang BSD-3-Clause License

Redefinition of SESV2 types with json field declarations Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright 2014-2015 Stripe, Inc. Copyright 2021 - 2022 Luke Zhang BSD-3-Clause License

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL