[core] Unable to Synthesize CDK in 1.57: Assets must be defined indirectly within a "Stage" or an "App" scope
See original GitHub issueAfter 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:
- Created 3 years ago
- Comments:36 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had the same issue and fixed it with these steps:
Delete both node_modules and package-lock.json
Run npm install
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?