Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
blimmer opened this issue Apr 11, 2024 · 4 comments
Open
2 tasks

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

blimmer opened this issue Apr 11, 2024 · 4 comments
Labels
cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@blimmer
Copy link
Contributor

blimmer commented Apr 11, 2024

Describe the feature

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

@msambol added --ignore-no-stacks to the cdk deploy command with #28387, but this flag should be respected on all commands that fail if stacks are not present (e.g., synth, diff, deploy, etc.)

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.137.0

Environment details (OS name and version, etc.)

MacOS Sonoma

@blimmer blimmer added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 11, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Apr 11, 2024
@pahud
Copy link
Contributor

pahud commented Apr 12, 2024

@msambol added --ignore-no-stacks to the cdk deploy command with #28387, but this flag should be respected on all commands that fail if stacks are not present (e.g., synth, diff, deploy, etc.)

Yes this makes sense.

@pahud pahud added p2 effort/medium Medium work item – several days of effort cli Issues related to the CDK CLI and removed needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2024
@msambol
Copy link
Contributor

msambol commented Apr 14, 2024

I'll take a look here......

@msambol
Copy link
Contributor

msambol commented Apr 14, 2024

This is more than I want to tackle right now. If someone else wants to take this, feel free. I'll put it in my backlog, though.

@nmussy
Copy link
Contributor

nmussy commented Apr 17, 2024

I might give it a shot at some point, but @TheRealAmazonKendra mentioned that there are possible future refactoring efforts regarding the CLI, see #29695 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants