Skip to content

Get email details from a dynamodb table and send with ses, in a serverless way with aws (batch, dynamodb, lambda and ses)

Notifications You must be signed in to change notification settings

anddimario/postino

Repository files navigation

Get email details from a dynamodb table and send with ses, in a serverless way with aws (batch, dynamodb, lambda and ses). Templating system is based on handlebars.

Install

export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_DEFAULT_REGION="..."
export AWS_REGION="..."
export TF_VAR_aws_region=your_region
export TF_VAR_docker_image=your_ecr_image_path
terraform apply

How it works

  • store yout template in templates/
  • store on dynamodb this payload:
{
    id: ...
    to: [...],
    locals: {
       ...
    },
    from: ....,
    subject: ...,
    template: ...
}

Development and local testing

export SERVICES=dynamodb,ses
docker-compose up
  • create a dynamodb table:
aws dynamodb create-table --endpoint=http://localhost:4569 --table-name postino_mails --attribute-definitions AttributeName=id,AttributeType=S --key-schema AttributeName=id,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  • insert a record in dynamodb:
aws dynamodb put-item --endpoint=http://localhost:4569 --table-name postino_mails --item file://item.json

example of item.json:

{
  "id": {
    "S": "test"
  },
  "to": {
    "L": [
      {
        "S": "test@example.com"
      }
    ]
  },
  "locals": {
    "M": {
      "test": {
        "S": "ok"
      }
    }
  },
  "from": {
    "S": "admin@example.com"
  },
  "subject": {
    "S": "Test"
  },
  "template": {
    "S": "testtemplate"
  }
}
  • create a template in template, example for testtemplate.html:
This is to see if it's {{ test }}
  • verify email on ses:
aws ses verify-email-identity --email-address admin@example.com --endpoint-url=http://localhost:4579

Build on localhost

  • go in the project root
  • build the image: docker build -t postino .
  • run the image:
docker run --network="host" -e DYNAMO_OPTIONS='{"endpoint":"http://localhost:4569"}' -e SES_OPTIONS='{"endpoint":"http://localhost:4579"}' -e AWS_REGION='localhost' -t postino

About

Get email details from a dynamodb table and send with ses, in a serverless way with aws (batch, dynamodb, lambda and ses)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published