Next.js and Django Microservices Lambda Deployments
An AWS code pipeline is created for each application. This pipeline is responsible for deploying the infrastructure and the application code. The pipeline is triggered when a new commit is pushed to the specified branch of the application's repository.
Architectures
Next.js and Django Microservice Lambda and ECS with Database

Next.js and Django Microservice ECS with Database

Static Files
Static files of the Next.js application are deployed to an S3 bucket. The deployed bucket is private and all static files are served using CloudFront.
Image Optimization
An image optimization lambda handles image optimization for the Next.js application. Optimization requests are made
when the Next.js <Image />
component is used. The lambda uses the sharp
library to optimize images.
Lambda Servers
Lambda servers handle server-side rendering and other server-side logic for the Next.js service. The lambda servers are placed in a private subnet and are not directly accessible from the internet.
ECS Servers
ECS servers handle API requests for the Django service. The Zonké dashboard exposes the capability to scale the number of ECS servers based on application traffic. You have the option to use Fargate or EC2 instances for the ECS servers. For security, deployed ECS servers are placed in a private subnet and are not directly accessible from the internet.
Lambda Warmers
A lambda warmer function is used to call the Next.js server lambda functions. This is done to reduce the cold start time of the lambda functions. The lambda warmer function is triggered by an EventBridge event and is scheduled to run every 5 minutes. The dashboard allows you to configure the number of servers to keep warm.
Secrets
Secrets are stored in AWS Secrets Manager and are exposed to the lambda and ECS servers as environment variables. The
dashboard allows you to add, update, and delete secrets for the Next.js and Django services. Secrets are only stored
in your AWS account and are encrypted at rest and in transit. The Next.js application can access these secrets using
the process.env
object and directly from Secrets Manager.
Database
The Django application is deployed with a database. The database is deployed using RDS and is accessible from the ECS servers. Database credentials are stored in AWS Secrets Manager and, just like other service secrets, they are exposed to the ECS servers as secrets. The database is placed in an isolated subnet and is only accessible from the ECS servers.
Database Migrations
Django applications run database migrations during deployment. A migration lambda function is created and triggered by the pipeline during application deployment. You do not need to configure anything in your codebase to run migrations.