Skip to content

(cli): Provide a way to ignore "This app contains no stacks" #28371

@blimmer

Description

@blimmer

Describe the feature

It would be nice if I could ignore the "This app contains no stacks" error message specifically.

Use Case

In many cases, I have a dev and prod AWS account. When I first develop a new CDK project, I often want to only deploy the dev account, while later deploying to dev and prod. I often write this code like this:

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { TestCdkStack } from '../lib/test-cdk-stack';

const app = new cdk.App();

// Assume 12345678910 is my dev account number
if (process.env.CDK_DEFAULT_ACCOUNT === "12345678910") {
	new TestCdkStack(app, 'TestCdkStack', {
	  /* If you don't specify 'env', this stack will be environment-agnostic.
	   * Account/Region-dependent features and context lookups will not work,
	   * but a single synthesized template can be deployed anywhere. */
	
	  /* Uncomment the next line to specialize this stack for the AWS Account
	   * and Region that are implied by the current CLI configuration. */
	  // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
	
	  /* Uncomment the next line if you know exactly what Account and Region you
	   * want to deploy the stack to. */
	  // env: { account: '123456789012', region: 'us-east-1' },
	
	  /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
	});
}

However, this fails with the error message "This app contains no stacks".

You might think, "why not just set up deployment to not happen until you're ready?". My common use case is a monorepo with many projects. My CI uses lerna to run cdk diff automatically in projects that changed.

Proposed Solution

A CLI flag like --ignore-no-stacks would be great. This reminds me of jest's --passWithNoTests flag that's helpful when you've installed jest but not written tests yet.

Other Information

I've hacked my way around this by creating this script:

#! /bin/bash
# Working around this issue: https://github.com/aws/aws-cdk/issues/28371

set -e

if [ "$CI" ]  && [ "$CDK_STAGE" == 'dev' ]; then
  echo "This stack does not deploy to dev"
  exit 0
else
  cdk "$@"
fi

and updating the package.json's cdk script to call this instead.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.115.0

Environment details (OS name and version, etc.)

MacOS Latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2package/toolsRelated to AWS CDK Tools or CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions