Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a specific stack using AWS SDK?

In my AWS CDK/ Typescript project I have 1 main stack i.e. aws-microservices-stack.ts

rest all typescript files are just constructs extended in aws-microservices-stack.ts

enter image description here

But when I run cdk deploy I get error

Since this app includes more than a single stack, specify which stacks to use (wildcards are supported) or specify --all Stacks: AwsMicroservicesStack · AwsMicroservicesStack/Database · AwsMicroservicesStack/Microservices · AwsMicroservicesStack/ApiGateway

How can I mark aws-microservices-stack.ts so that deploy command picks up only that stack

aws-microservices-stack.ts

import { Stack, StackProps } from 'aws-cdk-lib';;
import { Construct } from 'constructs';
import { SwnApiGateway } from './apigateway';
import { SwnDatabase } from './database';
import { SwnMicroServices } from './microservices';

export class AwsMicroservicesStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const database = new SwnDatabase(this, 'Database');
....

  }
}

database.ts

import { RemovalPolicy, Stack } from 'aws-cdk-lib';
import { AttributeType, BillingMode, ITable, Table } from 'aws-cdk-lib/aws-dynamodb';
import { Construct } from 'constructs';


export class SwnDatabase extends Stack {

  public readonly productTable: ITable;
  constructor(scope: Construct, id: string) {
    super(scope, id);

    // DynamoDb Table
    const productTable = new Table(this, 'product', {

      partitionKey: {
        name: 'id',
        type: AttributeType.STRING
      },
      tableName: 'product',
      removalPolicy: RemovalPolicy.DESTROY,
      billingMode: BillingMode.PAY_PER_REQUEST
    });

    this.productTable = productTable;


  }
}
like image 263
dota2pro Avatar asked May 09 '26 06:05

dota2pro


1 Answers

You can't "mark" it for deployment, you need to specify which stack to deploy with:

cdk deploy $yourstackname

The names of the declares stacks are listed by

cdk ls

Here you can read more about cdk stacks handling.

like image 103
Dario Avatar answered May 12 '26 11:05

Dario