question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[core] Unable to Synthesize CDK in 1.57: Assets must be defined indirectly within a "Stage" or an "App" scope

See original GitHub issue

After upgrading to 1.57 I get the following error when trying to synthesize my application:

unable to determine cloud assembly output directory. Assets must be defined indirectly within a "Stage" or an "App" scope

I tried specifying outdir in my App as well as my Stage, but neither works (in App throws same error, in Stage throws nested stage error).

Reproduction Steps

I haven’t quite nailed down the triggering code, but here’s my general setup:

export interface MyStackProps extends cdk.StackProps {
    source: s3deploy.ISource;
    code: lambda.Code;
}

class MyStack extends cdk.Stack {
    constructor(scope: cdk.Construct, props: MyStackProps) {
        super(scope, "MyStack", props)

       ...

        new lambda.Function(this, "ApiHandler", {
          code: props.code,
        });

        new s3deploy.BucketDeployment(this, "DeployWithInvalidation", {
          sources: [props.source],
          destinationBucket: someDistributionBucket,
          distribution: someDistribution,
        });
    }
}

class MyStage extends cdk.Stage {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StageProps) {
    super(scope, id, props);

    new MyStack(this, {
       // Changing these values to `{} as any` still throws the same scope error
        code:  lambda.Code.fromAsset("../api/dist"),
        source: s3deploy.Source.asset("../app/build"),
    });
  }
}

class PipelineStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const sourceArtifact = new codepipeline.Artifact();
    const cloudAssemblyArtifact = new codepipeline.Artifact("CloudAssemblyArtifact");

    const pipeline = new pipelines.CdkPipeline(this, "Pipeline", {
      pipelineName: "MyAppPipeline",
      cloudAssemblyArtifact,

      sourceAction: new codepipeline_actions.GitHubSourceAction({...}),

      synthAction: pipelines.SimpleSynthAction.standardNpmSynth({
        sourceArtifact,
        cloudAssemblyArtifact,
        ...
      }),
    });

    pipeline.addApplicationStage(new MyStage(this, "Prod"));
  }
}

const app = new cdk.App();
new PipelineStack(app, "PipelineStack");

What did you expect to happen?

The CDK app synthesizes correctly.

What actually happened?

Synthesis fails with the message unable to determine cloud assembly output directory. Assets must be defined indirectly within a "Stage" or an "App" scope

Environment

  • CLI Version : 1.57
  • Framework Version: 1.57
  • Node.js Version: v14.3.0
  • OS : Ubuntu (on WSL2)
  • Language (Version): TypeScript (3.9.7)

Other

Here’s where the error is being thrown


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:36 (8 by maintainers)

github_iconTop GitHub Comments

12reactions
GCSDCcommented, Aug 17, 2020

I had the same issue and fixed it with these steps:

  1. Set version of all cdk related packages to “ˆ1.59.0”
"devDependencies": {
  "@aws-cdk/assert": "^1.59.0",
  "@types/jest": "^25.2.1",
  "@types/node": "10.17.5",
  "aws-cdk": "^1.59.0",
  "jest": "^25.5.0",
  "ts-jest": "^25.3.1",
  "ts-node": "^8.1.0",
  "typescript": "~3.7.2"
},
"dependencies": {
  "@aws-cdk/aws-apigateway": "^1.59.0",
  "@aws-cdk/aws-codepipeline": "^1.59.0",
  "@aws-cdk/aws-codepipeline-actions": "^1.59.0",
  "@aws-cdk/aws-lambda": "^1.59.0",
  "@aws-cdk/core": "^1.59.0",
  "@aws-cdk/pipelines": "^1.59.0",
  "@types/aws-lambda": "^8.10.61",
  "source-map-support": "^0.5.16"
}
  1. Delete both node_modules and package-lock.json

  2. Run npm install

9reactions
fongiecommented, Aug 14, 2020

I had this problem in v1.58.0 when following the CDK Pipelines blog post. I have a local npm package reference (file:…/etc) as well. Removing the local package did not fix it, but downgrading to pinned 1.56.0 fixed it for me, even when reintroducing the local package.

Maybe this issue should be reopened?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common AWS CDK issues
Assets must be defined indirectly within a "Stage" or an "App" scope . The modules that make up the AWS Construct Library are...
Read more >
aws-cdk.core - PyPI
This library includes the basic building blocks of the AWS Cloud Development Kit (AWS CDK). It defines the core classes that are used...
Read more >
@aws-cdk/aws-dynamodb | Yarn - Package Manager
Here is a minimal deployable DynamoDB table definition: const table = new dynamodb.Table(this, 'Table', { partitionKey: { name: 'id', type: dynamodb.
Read more >
Introduction to CDK - Activate Early stage path
AWS CDK apps are composed of building blocks known as constructs. ... All AWS resources defined within the scope of a stack, either...
Read more >
When to Use AWS CDK Constructs vs Stacks
Under the hood, Constructs are deconstructed into AWS ... Each component must be defined in an App. Each CDK project starts with an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found