dwyl / aws-ses-lambda Goto Github PK
View Code? Open in Web Editor NEW๐ฌ A Lambda function for sending email and tracking deliverability via AWS Simple Email Service (SES)
๐ฌ A Lambda function for sending email and tracking deliverability via AWS Simple Email Service (SES)
We have the Lambda function to send emails working. ๐
Now we want to create an SNS topic so that our Lambda can receive SES related notifications.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/configure-sns-notifications.html
But what happens when with the information in the SNS Notification?
In the past we have stored this data in S3 or DynamoDB but both those data stores are cumbersome to query and have per-request charges for saving/getting data. So we need a way of getting the SNS notification info back to our PostgreSQL (main) database.
Our ultimate objective with email
is to have a real-time dashboard where we can visualise the aggregate deliverability stats and specific stats for a given person using our App (while preserving their anonymity/privacy).
We still want our Lambda function to receive and process the SNS messages,
and then forward the formatted info back to Phoenix App via REST API endpoint.
In order to use the same tables/schema as the MVP which has detailed explanations
see: https://github.com/dwyl/app-mvp-phoenix#schema
We are borrowing the actual migration files:
tags
table by reusing 20191113100513_create_tags.exs
migration from the MVP:status
table by reusing 20191113100912_create_status.exs
from MVP: https://github.com/dwyl/app-mvp-phoenix/blob/master/priv/repo/migrations/20191113100912_create_status.exspeople
table by reusing 20191113100920_create_people.exs
migration from the MVP:person_id
to Tags using 20191113114340_add_person_id_to_tag.exs
from MVP:person_id
to Status using 20191113141229_add_person_id_to_status.exs
form MVP:This way we can run the Email and Auth Apps in several ways:
Auth
and Email
can be run separatelyEmail
can be run as an Umbrella App to Auth
sent
table/schema with the following fields:
person_id
(references person.id
) - the person the email was sent to.template
- the template that was used to send the email to the person.message_id
and request_id
fields to store SES metadata.status_id
(references status.id
) - the status of the email e.g: 6:sent
, 7:delivered
, 8:bounce
, etc. This allows us to have unlimited statuses without tons of duplication of text.Note: the "status" does not need to be a single word, it can be for example:
"bounce: addressee unknown"
/api
endpoint that:
It's not possible to load the AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
environment variables in AWS lambda see: dwyl/aws-lambda-deploy#58 (comment)
Which is why we are seeing the AccessDenied
error #10 ๐
There appears to be a way forward:
https://aws.amazon.com/premiumsupport/knowledge-center/lambda-send-email-ses
LambdaExecRole
This is a potential features "roadmap" in (descending) order of importance.
else
might consider adding)If you are keen on a particular feature or want to propose other ideas, please comment below! ๐
These are the steps we originally defined:
Each time an email is sent using the aws-ses-lambda
5 things happen:
From experience making distinct functions separate lambda functions,
just increases our cost/complexity without any discernible benefit.
Having separate lambdas when we know that all functionality is executed
each time
aws-ses-bounce-checker periodically retrieves stats on outbound emails from SES.
These include bounce rates and whether an email has been opened.
We need to take a fresh look at these and determine which features are still needed.
while
building the functionality for aws-ses-lambda
I've been working off my imagination ... ๐ก
Obviously that doesn't make it very easy for other people to understand it. ๐
The main App does not do anything with Email as that is is not it's core function.
It delegates all email sending and monitoring activity to the aws-ses-lambda.
โโโโโโโ send โโโโโโโโโโโโโโโโโโ
| App | ----->| aws-ses-lambda |โ the Lambda function Sends email
โโโโโโโ email โโโโโโโโโโโโโโโโโโ| and handles SNS notifications
โโโโโโโโโ SNS Notification | for bounce events.
| Email | <โโโโโโโโโโโโโโโโโโโโ
| Stats |
โโโโโโโโโ The Email Stats App aggregates and visualises email stats.
This allows us to be more data-driven in our communications.
And understand exactly who is engaged with the app.
In order to debug the data we are receiving in the Lambda event,
we need to save a copy of the event to S3 so that we can view it after the Lambda has finished execution.
(yes, we can do this by hunting through the cloudwatch logs, but it's so much easier if we can just open a file and view it immediately rather than scrolling for ages)
event
object as JSON in a file on S3.Our mission is to create an SNS topic to "listen" for Bounce emails
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/configure-sns-notifications.html
Hi,
I was just wondering how AWS is invoicing SES mails sent from Lambda functions?
SES has two types of invoices:
Regards
Paul
There are a couple of options for invoking a Lambda function from Elixir:
else
... but it's a reference and it's good to know they're using Elixir! ๐arn:aws:lambda:eu-west-1:110797354241:function:aws-ses-lambda-v1
AWS SES is great for sending email but does not have great UI for checking the stats of our sent emails. Thankfully, there's an API we can use to lookup the data and display it to our "admin" people so they are aware of the success/failure (bounce) rate. ๐
While attempting to send SNS notification data to the Phoenix App https://phemail.herokuapp.com
we are seeing the following error:
problem with request: Hostname/IP does not match certificate's altnames: Host: https. is not in the cert's altnames: DNS:*.herokuapp.com, DNS:herokuapp.com
Reading request/request#1777 we discover
that we have the option to ignore this error by adding the option:
rejectUnauthorized: false,
https://stackoverflow.com/questions/36588963/node-js-requests-with-rejectunauthorized-as-false
In order to deploy and invoke a Lambda function and send email from that function,
we need to define an AWS Identity and Access Management (IAM) Role with the required permissions.
lambda-user
AWSLambdaFullAccess
AmazonSESFullAccess
AmazonS3FullAccess
One of the only "down sides" of AWS Lambda is latency.
It can take up to 700ms for a "cold" Lambda function to startup.
The median cold-start is around 400ms
Once the Lambda has been invoked and is cached, it only takes 50ms to respond to subsequent requests.
What this means in practice is that someone registering for our App they will wait up to 1 second for an email to be sent.
index.js
so the lambda function can be invoked without any operation or output. See: https://en.wikipedia.org/wiki/NOP_(code)
event
as data
Attempting to run the Lambda function on Lambda getting the following error:
{
"errorType": "AccessDenied",
"errorMessage": "User `arn:aws:sts::123456789:assumed-role/LambdaExecRole/aws-ses-lambda-v1' is not authorized to perform `ses:SendEmail' on resource `arn:aws:ses:eu-west-1:123456789:identity/[email protected]'",
"trace": [
"AccessDenied: User `arn:aws:sts::123456789:assumed-role/LambdaExecRole/aws-ses-lambda-v1' is not authorized to perform `ses:SendEmail' on resource `arn:aws:ses:eu-west-1:123456789:identity/[email protected]'",
" at Request.extractError (/var/task/node_modules/aws-sdk/lib/protocol/query.js:50:29)",
" at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)",
" at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)",
" at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:683:14)",
" at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)",
" at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)",
" at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10",
" at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)",
" at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:685:12)",
" at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"
]
}
Investigating now ... ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.