- Newest
- Most votes
- Most comments
Yes, there is an established pattern for organizing a mono-repo in CDK to achieve both full deployment capabilities and individual service deployments. This approach combines the use of multiple stacks within a single CDK application and leverages the concept of nested stacks.
Here's a recommended approach:
-
Create a main CDK application at the root of your mono-repo. This will serve as the entry point for full deployments.
-
Organize your services into separate directories within the mono-repo, each with its own CDK stack definition.
-
In the main CDK application, import and reference all the individual service stacks. This allows for a complete deployment of all services when needed.
-
Use nested stacks to modularize your infrastructure. Each service can be defined as a nested stack, which can be deployed independently or as part of the larger application.
-
Implement a flexible structure that allows individual services to be deployed separately. This can be achieved by creating separate CDK entry points for each service.
-
Use environment variables or configuration files to control which stacks are deployed, allowing for flexibility in deployment scenarios.
Here's a basic structure you might follow:
monorepo/
├── bin/
│ └── main.ts (main CDK app entry point)
├── lib/
│ ├── parent-stack.ts (parent stack that includes all services)
│ └── shared-resources.ts (shared resources across services)
├── services/
│ ├── service-a/
│ │ ├── lib/
│ │ │ └── service-a-stack.ts
│ │ └── bin/
│ │ └── service-a.ts (entry point for individual deployment)
│ └── service-b/
│ ├── lib/
│ │ └── service-b-stack.ts
│ └── bin/
│ └── service-b.ts (entry point for individual deployment)
└── package.json
With this structure, you can achieve your goals:
- For full deployment:
git clone monorepo && cd monorepo && cdk deploy
- For individual service deployment:
git clone monorepo && cd monorepo/services/service-a && cdk deploy
This approach allows for both comprehensive deployments and quick, individual service deployments. It consolidates your infrastructure into a single CDK application while maintaining the flexibility for developers to work on and deploy specific services independently.
Remember to use proper IAM roles and permissions to ensure that developers can only deploy the services they're responsible for. Also, consider implementing a CI/CD pipeline that can handle both full and partial deployments based on the changes detected in the repository.
Sources
Automatically detect changes and initiate different CodePipeline pipelines for a monorepo in CodeCommit - AWS Prescriptive Guidance
Deploy multiple-stack applications using AWS CDK with TypeScript - AWS Prescriptive Guidance