-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[core] unable to run CDK diff in upgrading from 1.51.0 to 1.62.0: : Assets must be defined indirectly within a "Stage" or an "App" scope #10314
Comments
Can you try to also remove your lock file ( |
I would also guess it's a version mismatch somewhere. Make sure all |
@rix0rrr there is also the "multiple copies of |
Oh good fine. In that case, running |
I had this and a delete of the package-lock.json and the node_modules folder fixed it for me. Must've been the package-lock.json as just a clear out of the node_modules didn't do it for me. |
hmm yeah i tried the node modules + package lock deletion steps, as well as making sure all my versions were pinned to 1.62.0, but no luck. ill try |
I am hitting this bug with CDK versions 1.64.0 and 1.64.1. There are two ways of triggering this bug:
I am experiencing number 2 above (lambda with Here is an example:
I've tried deleting node_modules, package-lock.json, and cdk.out, and have triple checked all aws-cdk packages are at the exact same, pinned version. Then done
As soon as I downgrade to 1.52.0 (or 1.57.0) then everything works fine. |
@Shogan Can you share a repro? |
@Shogan I have been running into the same issue. On a whim, I added my 'assets' directory to my package.json file, in the "directories" property and both {
...
"directories": {
"assets": "assets"
}
...
} |
Thanks @jamiepeloquin, but not exactly sure which assets directory to specify here? Do you mean the cdk.out assets directory? I tried with just 'assets' but didn't see any difference. @jogold I've homed in on the issue now, initially I set up a simple AWS CDK app and could not reproduce. However my existing project still emitted the problem. It happens when you have a cdk library project, and then create a nested cdk app project within that library, referencing the library itself with the parent directory path. E.g. importing the library from the app with path Here is a cut-down minimal reproduction project. See README.md for reproducing steps once cloned. https://github.com/Shogan/aws-cdk-issue-10314-repro Hope that helps! |
@Shogan Sorry for the hazy advice… I have a directory named “assets” in the root of my CDK project. This is where I put my Lambda code (each Lambda Function gets its own subdirectory). I hope the example below helps to clarify my finding. Example:Project structure (abbreviated)
My Lambda Resourceconst myLambdaFunction = new lambda.Function(this, 'MyLambdaFunction', {
code: lambda.Code.fromAsset(path.join(__dirname,'../assets/my-lambda-function/')),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_12_X,
timeout: cdk.Duration.seconds(5)
}); My package.json{
"directories": {
"assets": "assets",
"lib": "lib"
},
} |
@Shogan you are nesting different copies of You should use a monorepo/lerna for this kind of architecture. |
Thanks for this @jamiepeloquin. I did give it a try as per your workaround but that didn't help in my situation. Probably down to the particular nesting strategy I was using of an app inside a library repo. @jogold, thanks for the link and explanation. This makes sense now. I had nested things in this way just for local development. I think it's important to note though, that with previous versions of CDK this setup worked fine. (E.g. if I switch back to 1.52.0 or prior it is fine). |
Getting the same issue as @Shogan but not with my own lambdas but using AwsCustomResource ... I'll try to replace them by my own custom resource implementation ... (same as above, work fine with 1.52.0 version) |
I think I've tracked this issue down. As @jogold pointed out, it has to do with nesting different copies of Generally speaking I don't think it sits well with CDK to enforce a single instance of the code, not just the same version number. Therefore the example repo @Shogan created is still a good starting point. The issue occurs with any kind of assets. Lambda Functions with Code Assets are an obvious one as they are often pulled out into a reusable library. However like @flochaz this also appears to happen when the code asset is just a parameter to a lambda lib. The reason being that a lambda with Enough of the prelude. The issue surfaces because stages are enforced for asset staging as of 1.57.0. Specifically this change by @eladb Now, Stages have been around for a long time. However they have been pretty much optional and I guess where only used with the new pipelines. Long story short, they use a different mechanic to determine if a thing is a stage object. The All other "global" packages use a mechanism with Unless there is a good reason for this difference, I'd suggest to use the same mechanism for Stages which will fix this issue. If someone could confirm the direction, I'm happy to provide a PR as it is holding us back. I'd also suggest to include a test for nested code copies. |
I've created the simplest example I can think of, reproducing the problem here: Extra useful information about the issue can be found here: Please let me know if there is anything I can do to help solve the issue |
…thin Stage or App' error (#11113) A recent change surfaces an issue where Stage objects from different code copies don't recognize each other as a Stage. This paht aligns the way how a Stage determines if something is a Stage to the same mechanism that App and Stack use. Thanks to @Shogan and @jogold for narrowing the issue down fixes #10314 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
@eladb is this fix already part of a release? Dont know where to look it up. Facing this issue too in respect to typescript / lerna packages and CDK code (especially lambdas) spread across different lerna packages even with the CDK packages pinned at one exact version (in my case 1.70.0) |
I think this will be released in 1.72.0, so you need to be patient 😃 @logemann We faced a similar problems but found no satisfying solution with lerna (see: #10977 (comment)) My conclusion is that there are 4 solutions to this:
Please comment if other solutions exists? We are still evaluating what path to take, going forward. |
We've just updated a bunch of our lerna stacks to 1.72.0 and it finally works again! 🎉 |
yup just updated to 1.72.0 and it works. Thanks! |
I just upgraded my cdk version from
1.51.0
to1.62.0
, and I updated the code so thatnpm build
runs successfully for the project. I then tried to do a diff of my stacks withcdk diff <stackname>
and it failed with this error:In googling that I came across #9546 and I followed the directions to make sure all my cdk packages were pinned at the exact same version. after doing that I still ran into the error. I do use custom lambda functions packaged like so:
which worked just fine before the upgrade, but now it still is failing with the same error, that issue i linked above mentioned that using lambda assets could cause this. and I am unsure of how to proceed to fix this, and also why this suddenly became an issue.
Reproduction Steps
use a custom lambda asset like so:
What did you expect to happen?
cdk diff to pass without error
What actually happened?
cdk diff returned this error:
Verbose output:
Environment
Other
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: