This deploys listmonk to AWS and contains configuration files to make it look good.
The app itself is deployed to AWS Lambda using a Docker Container.
The container communicates over HTTP, and this is translated to a Lambda
handler using aws-lambda-adapter
AWS SAM is used to wrap everything up and deploy it.
The application frontend is styled to look like DC's other products.
This is done according to the listmonk templating docs.
The design system is implemented using a Makefile to write to the static directory.
To make the design system and update the CSS, run make static from the
root folder. sass needs to be on your PATH for this to work, best
installed with npm install -g sass.
Listmonk manages the email templates via the frontend / database.
In order to keep these templates in source control, we have checked them in to
app_assets.
You need to login to the admin interface and copy/paste the contents of these files into the 'templates' section under campaigns.
Of course, it's possible to just update the templates in the admin interface, however it's much better to do the work locally first and copy the finished template to the production environment.
You should only need to run locally to change the templates / theme.
If this is the first time running locally:
Download listmonk as per https://listmonk.app/#download
Run listmonk --new-config
Edit config.yaml with your DB setting.
Run listmonk --install
Run listmonk --static-dir=app/static
Visit http://localhost:3000
- Log in to the AWS SSO account you want to deploy to
export DC_ENVIRONMENT=according to the environment you're deploying to- run
make deploy
If you run cdk deploy directly, also
export BUILDX_NO_DEFAULT_ATTESTATIONS=1, or building the email preprocessor's
image will fail with cannot export attestations.
- Make sure you have a hosted one for your domain name in the account you're using and the hosted zone is 'live' (the DNS is pointed to it).
- Create an ACM cert in the us-west-1 location and verify it
- Grab the ARN of the cert and add it to the parameter store (see below)
We need to give ListMonk an IAM user for uploading media (it doesn't support role based authentication).
In the S3 console, make a new bucket [bucket_name] and ensure that public access _is not blocked. Also allow ACLs under object ownership.
In the AWS account you're using, create a new IAM user (the name doesn't matter) and give it the following inline policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": ["s3:*"],
"Resource": [
"arn:aws:s3:::[bucket_name]",
"arn:aws:s3:::[bucket_name]/*"
]
}
]
}Create new access keys for the user, ignoring the wanings about using role based auth.
Make a note of the Access key and Secret access key for later.
/MailingList/S3MediaBucketNameMedia bucket name (as above)/MailingList/ListMonkFQDNDomain name/MailingList/CertificateArnACM ARN (as above)/MailingList/CloudFrontOriginTokenA private token to prevent direct access to API Gateway. Set to something long and unguessable/MailingList/ListMonkApiKeyThe token the Lambda functions use to authenticate againsthttps://{ListMonkFQDN}/api/. Create an API user calledlambda_keyin ListMonk's admin UI (the name is set byLISTMONK_API_USERincdk/stacks/listmonk_stack.py), with a user role that has thelists:get_all,lists:manage_all,subscribers:get_all,subscribers:manage,subscribers:sql_queryandtx:sendpermissions, and use its token as the value/MailingList/LISTMONK_db__hostThe RDS host/MailingList/LISTMONK_db__userThe RDS user/MailingList/LISTMONK_db__passwordThe RDS password/MailingList/AlertEmailThe address to email when sign ups are failing. AWS sends a confirmation link to this address after the first deploy, and no alerts arrive until it has been clicked/MailingList/MainListUuidThe UUID of the list that new subscribers get a welcome email for being on/MailingList/WelcomeTemplateIdThe ID of the welcome email's template in ListMonk, which must be a transactional template
Sign up and welcome email events that can't be processed go to a dead letter
queue, after Lambda has retried them twice. An email is sent to
/MailingList/AlertEmail when the queue stops being empty.
The alarm stays on while there are messages in the queue, so further failures won't send another email until it has been cleared. Messages are deleted after 14 days, so anything still there needs replaying before then.
To replay a message, fix the problem and then invoke the event receiver Lambda with the message body as its payload. Once it has succeeded, delete the message from the queue.
The same address is emailed if the hourly onboarder Lambda fails. This doesn't use the queue, as the next run retries anyone who signed up in the last 24 hours. Check the function's logs, as anyone older than that isn't retried.
https://{ListMonkFQDN}/preprocessor is an editor that converts Markdown to
HTML with the inline styles that emails need. It runs as a separate Lambda
function, built from email_preprocessor/. It's publicly accessible, and it
doesn't store anything.
email_preprocessor/default_email.html is a copy of the email template, as the
Docker build can't read files outside of that directory.