Monorepo using serverless microservices design with AWS Lambda
and Amazon MQ (RabbitMQ)
for backend,
Vercel for frontend (Next.js) with Terraform CDK infrastructure.
This turborepo uses pnpm as a packages manager. It includes the following packages/apps:
csv-to-pdf-microservice
: a python microservice that converts csv to pdf with RabbitMQ & kombu (messaging library)aggregation
: a Nestjs backend for frontend (Lambda function)web
: Next.js appeslint-config-custom
:eslint
configurations (includeseslint-config-next
andeslint-config-prettier
)tsconfig
:tsconfig.json
s used throughout the monorepo
- The infrastructure targets minimum cost (free) and does not include best practices for security. If you want to use it for large production you should create a VPC with private & public subnets with NAT Gateway (or VPC Endpoint PrivateLink) to establish a connection between API Gateway, Amazon MQ (set publicly accessible to false), STS, SecretsManager, and AWS Lambda. If you use VPC Endpoint (PrivateLink) for communication between these services, the traffic won't go on the public internet, it stays on AWS Network and this will help maximum security for your application.
- Besides requests between microservice and frontend, the file sharing between Lambdas is provided with a message queue. (we are working with files less than 100 KB, and for staying free tier) You should not use a message queue for sharing file binary in large production, instead, you should use a reference path. For a serverless (AWS Lambda) environment, you can use EFS or S3. You can find additional information in application code comments.
This turborepo has some additional tools already setup for you:
- TypeScript for static type checking
- ESLint for code linting
- Prettier for code formatting
git clone https://github.com/sinanbekar/turborepo-cdktf-microservices-app
cd turborepo-cdktf-microservices-app
pnpm install
To build all apps and packages, run the following command:
pnpm run build
To deploy frontend to Vercel, backend to AWS (Lambda), first install cdktf-cli:
pnpm add --global cdktf-cli@latest
cd infrastructure/cdktf
cdktf get # generate constructs from hcl providers
Please make sure that set up these environment variables: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
and VERCEL_API_TOKEN
and deploy 🚀
cdktf deploy backend frontend
To develop all apps and packages, run the following command:
pnpm run dev
Learn more about Terraform and CDK for Terraform:
Learn more about the power of Turborepo: