GithubHelp home page GithubHelp logo

craftzdog / send-email-lambda Goto Github PK

View Code? Open in Web Editor NEW
69.0 5.0 12.0 115 KB

Simple email sender running on Lambda

License: MIT License

JavaScript 100.00%
apex lambda aws-ses api-gateway email-lambda nodejs

send-email-lambda's Introduction

send-email-lambda

Simple email sender running on Lambda. It sends emails via AWS SES. It comes in handy when you would add a contact form to your static website.

Prerequisites

Prepare

Init your project

git clone [email protected]:craftzdog/send-email-lambda.git
cd send-email-lambda
apex init
> Project nane: send-email

Edit your project.json file based on project.json.example like:

{
  "name": "send-email",
  "description": "Simple email transmitter",
  "memory": 128,
  "timeout": 5,
  "environment": {},
  "runtime": "nodejs6.10",
  "role": "<YOUR_IAM_ROLE>"
}

Configure

Edit functions/submit/function.json as you like:

{
  "environment": {
    "SES_REGION": "us-west-2",
    "FROM_NAME": "Craftzdog Contact Form",
    "FROM_EMAIL": "<YOUR_AUTOMATED_EMAIL_SENDER>",
    "TO_EMAIL": "<EMAIL_TO_RECEIVE>"
  }
}
  • SES_REGION: The AWS region for the SES
  • FROM_NAME: Sender name like "Contact Form"
  • FROM_EMAIL: The email address you would receive from. e.g., [email protected]
  • TO_EMAIL: Your personal email address to receive emails.

Add a permission to send emails to the IAM role

Add following policy to your lambda's IAM role (ex. send-email_lambda_function) that allows the lambda function to use SES.sendEmail with policy name send-email_submit:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1504526549000",
            "Effect": "Allow",
            "Action": [
                "ses:SendEmail"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

Deploy and test sending emails

At the project top directory:

apex deploy

You can run the lambda function manually with below command:

echo -n '{ "subject": "hello", "body": "world" }' | apex invoke submit

And you will get an email to the configured address.

Publish on the Web

API Gateway

Configure your API Gateway like this:

API Gateway

And deploy the API.

Swagger definitions

See the swagger YAML file as an example.

API

POST <YOUR_API_ENTRYPOINT>/submit

It accepts JSON data with 2 fields:

  • subject: The message subject
  • body: The message body

License

MIT, Copyright 2017 by Takuya Matsuyama <[email protected]>

send-email-lambda's People

Contributors

craftzdog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.