typescriptamazon-web-servicesaws-cdkmonorepoturborepo

AWS CDK in monorepo packages - "This app contains no stacks"


I have a large typescript application, deployed with AWS CDK. The project is structured in a monorepo where each package represents a microservice on its own.

I'm trying to get away from the "root level" cdk.json - that has worked well until now that the size of the application has grown considerably - and split up the stacks (cdk.json + cdk/lib folders) into each individual service, so that they can be deployed independently. The structure I'm aiming at is below:

./
│   node_modules
│   ...
├── services
│   ├── service-a
│   │   ├── cdk
│   │   ├── ...
│   │   ├── cdk.json
│   │   ├── package.lock
│   │   └── src
│   ├── service-b
│   │   ├── cdk
│   │   ├── ...
│   │   ├── cdk.json
│   │   ├── package.lock
│   │   └── src
│   ├── service-c
│   │   ├── cdk
│   │   ├── ...
│   │   ├── cdk.json
│   │   ├── package.lock
│   │   └── src
├── ...
├── ...
├── package.lock
└── package.json

The idea is to be able to run cdk deploy individually for each service to minimize deploy time and increase scalability.

Just to try things out I've added the following command to service-a package.json

"cdk": "npx aws-cdk --require-approval never deploy --all -c branchName=dev -c environment=dev",

and run it from root with

turbo run cdk --filter=service-a

Alas, I'm getting this error:

@mine/service-a:cdk: This app contains no stacks
@mine/service-a:cdk: npm ERR! Lifecycle script `cdk` failed with error: 
@mine/service-a:cdk: npm ERR! Error: command failed 
@mine/service-a:cdk: npm ERR!   in workspace: @mine/service-a@1.0.0 

Is this functionality even supported or am I missing something?

I'm at loss here as there is nothing documented out there that I could find, these stacks deploy fine when they deploy all together from root but this This app contains no stacks error is a concern.


Solution

  • Have you defined separate stacks for each of the microservices?

    For instance, you can do something like this..

    new microservice_A(app, 'microservice_A', {});
    new microservice_B(app, 'microservice_B', {});
    new microservice_C(app, 'microservice_C', {});

    And you can use 'cdk deploy ${microservice_stack}' to deploy each of the microservices stacks independently.