Run daily in AWS Lambda this code generates an email in SendGrid after pulling the current access report data from CloudCannon.
It retrieves the Handlebars template from Sendgrid and executes a first pass render with the report data.
It posts the rendered HTML back to SendGrid as a draft email. The mailing lists and unsubscribe groups are set automatically.
The code runs daily at 10:00 am Darwin time and creates a scheduled single send in SendGrid which is scheduled to automatically send at 10:30 am Darwin time.
This project is set up and deployed using AWS CDK.
This project requires Node.js 12.x and that you have AWS credentials configured in order to deploy.
npm install
npm run test
npm run debug
The project includes a Github Codespaces config that will create an environment with all of the require dependencies installed. All that is required after creating the codespace is to run aws configure
and enter your AWS API keys and region.
You may also like to set your SendGrid API key for local development and debugging:
export SENDGRID_API_KEY="SG.<snip>"
First the SendGrid API key must be set in the account using AWS secrets manager.
Then you can deploy the stack with:
npm run cdk deploy
The SendGrid API key is stored in AWS Secrets Manager and is pulled when deploying the application.
To set the key:
aws secretsmanager create-secret --name accessReport/sendgridApiKey --description "SendGrid API key" --secret-string "<key>"
To change the key, the secret needs to first be updated and then the CDK stack redeployed:
aws secretsmanager update-secret --name accessReport/sendgridApiKey --description "SendGrid API key" --secret-string "<key>"