Reliable and Scalable Email Delivery System on AWS ECS Fargate

AWS ECS Fargate Docker Amazon SES Postfix Serverless
ECS Email Delivery Architecture

Goal

The goal of this project was to set up a reliable and scalable email delivery system using Amazon SES and Postfix, integrated into a containerized environment running on AWS ECS Fargate. The objective was to create a solution that enables sending emails securely from a containerized application while also hosting a static website, all within a fully managed, serverless infrastructure.

Solution

The solution involved several AWS services and technologies to create a comprehensive email delivery system:

Dockerized Postfix Setup

A custom Docker image was created with Postfix configured to send emails using Amazon SES. The container was designed with an entry point script that dynamically updates the container's IP address in the Postfix configuration to ensure correct email routing.

Amazon ECS Fargate

The Docker image was pushed to Amazon ECR (Elastic Container Registry) and deployed as a task in ECS Fargate, which runs the container without the need to manage EC2 instances.

Amazon SES Integration

Amazon SES was used as the email service to handle email sending securely, avoiding the need for managing external SMTP servers. This setup allowed both the email service (Postfix with SES) and a static website to run in the same container.

Architecture Components:

  • Docker Container: Custom Postfix image with SES configuration
  • ECS Fargate: Serverless container orchestration
  • Amazon ECR: Container registry for image storage
  • Amazon SES: Reliable email delivery service
  • Static Website: Hosted within the same container

Impact

Scalability

The solution benefits from ECS Fargate's serverless nature, which automatically scales the application based on demand. The use of Docker ensures that the system can be easily redeployed or replicated without manual intervention.

Cost Efficiency

Using ECS Fargate eliminates the need to manage EC2 instances, reducing infrastructure management costs. Amazon SES provides an efficient and low-cost solution for email delivery, especially for bulk email sending.

Operational Simplicity

The combination of Docker, ECS Fargate, and SES eliminates the need for complex server management. This reduces maintenance efforts, allowing the team to focus on other business tasks.

Reliability

The use of SES for email delivery ensures a reliable, scalable email service with high deliverability rates, avoiding common issues associated with self-hosted SMTP servers.

Technical Implementation

1. Container Development
  • Custom Dockerfile with Postfix
  • Dynamic IP configuration script
  • SES SMTP relay setup
  • Static website integration
2. AWS Services Setup
  • Amazon ECR repository
  • ECS Fargate cluster
  • Task definition configuration
  • SES domain verification
3. Deployment & Monitoring
  • Automated container deployment
  • CloudWatch logging
  • Health checks configuration
  • Performance monitoring

Key Configuration

Docker Entry Point Script
#!/bin/bash
# Get container IP address
CONTAINER_IP=$(hostname -i)

# Update Postfix configuration
sed -i "s/CONTAINER_IP_PLACEHOLDER/$CONTAINER_IP/g" /etc/postfix/main.cf

# Configure SES relay
postconf -e 'relayhost = [email-smtp.us-east-1.amazonaws.com]:587'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_security_options = noanonymous'

# Start services
service postfix start
nginx -g 'daemon off;'