npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

template-mailer-aws-lambda

v2.2.2

Published

A transactional email mailer that runs on AWS lambda and sends emails via SES

Downloads

46

Readme

template-mailer-aws-lambda

npm version Build Status monitored by greenkeeper.io js-standard-style semantic-release Code Climate

A transactional email mailer that runs on AWS Lambda and sends emails via AWS SES.

Setup

IAM

Create a role for the lambda function in IAM and attach these policies:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1459942470000",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::template-mailer/*"
            ]
        }
    ]
}

*Replace template-mailer with your bucket name.

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

S3

Create the S3 bucket used by the mailer.

Lambda

Copy config.json.dist to config.json and adapt to your needs.

Run

ROLE="…" make deploy

to publish the lambda function.

You can override the default function name with the environment variable FUNCTION_NAME.

You might also be interested in setting these environment variables for the aws CLI:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION

API Gateway

Then setup an API Gateway Lamdba Proxy.

Init configuration

Create the template foo:

curl -v -X PUT https://XXXX.execute-api.YYYY.amazonaws.com/production/templates/foo \
-H 'X-API-Key: ????' \
-H 'Content-Type: application/vnd.resourceful-humans.template-mailer-aws-lambda.v2+json; charset=utf-8' \
--data '{"subject":"Mail for <%= name %>","html":"Hello <%= name %>"}'

Create the transport bar:

curl -v -X PUT https://XXXX.execute-api.YYYY.amazonaws.com/production/transport/bar \
-H 'X-API-Key: ????' \
-H 'Content-Type: application/vnd.resourceful-humans.template-mailer-aws-lambda.v2+json; charset=utf-8' \
--data '{"email":"[email protected]","name":"Example Inc."}'

Note: In order to use the email, you need to configure it in AWS SES.

Send an email using the transport bar and the template foo:

curl -v -X POST https://XXXX.execute-api.YYYY.amazonaws.com/production/send/bar/foo \
-H 'X-API-Key: ????' \
-H 'Content-Type: application/vnd.resourceful-humans.template-mailer-aws-lambda.v2+json; charset=utf-8' \
--data '{"to":"[email protected]","name":"John Doe"}'

Templates

The subject, html and text part of the template will be parsed through lodash's template function with the data provided in the body of this request.

You can provide the data with a formatter hint:

"subject": {
  "@markdown": "This will be parsed with *markdown*"
}

it will parsed into

"subject": {
  "@text": "This will be parsed with *markdown*",                // the original value
  "@html": "This will be parsed with <strong>markdown</strong>"  // the HTML result
}

and can be access in the template accordingly.