Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): template created during import should be written to assets …
…folder (#29830) ### Issue # (if applicable) Closes #22928 #22530 I'm reopening as the original was closed due to inactivity. ### Reason for this change When the template is synthesized, if it is larger than 50kb and cannot be inlined in the CFN request, CLI writes it to the filesystem to be uploaded to S3. Unlike regular deployments `import` overrides the template, when it does so the code responsible for writing the large template to the filesystem writes to the project root. This code reproduces the issue: ``` import * as cdk from "aws-cdk-lib"; import { Construct } from "constructs"; import * as sqs from "aws-cdk-lib/aws-sqs"; import * as iam from "aws-cdk-lib/aws-iam"; export class AwsCdkImportBugStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); for (let i = 0; i < 70; i++) { const q = new sqs.Queue(this, `AwsCdkImportBugQueue${i}`, { visibilityTimeout: cdk.Duration.seconds(300), enforceSSL: true, }); } // new sqs.Queue(this, `AwsCdkImportBugQueue`, { // visibilityTimeout: cdk.Duration.seconds(300), // enforceSSL: true, // removalPolicy: cdk.RemovalPolicy.RETAIN, // }); } } ``` Deploy the stack, uncomment the queue, and try to import. This error happens: ``` $ npx cdk import AwsCdkImportBugStack AwsCdkImportBugStack/AwsCdkImportBugQueue/Resource (AWS::SQS::Queue): enter QueueUrl (empty to skip): https://sqs.eu-central-1.amazonaws.com/<cut>/AwsCdkBugStack-keep186A2ECA-IznVNwytuY1b AwsCdkImportBugStack/AwsCdkImportBugQueue/Policy/Resource (AWS::SQS::QueuePolicy): enter Id (empty to skip): Skipping import of AwsCdkImportBugStack/AwsCdkImportBugQueue/Policy/Resource AwsCdkImportBugStack: importing resources into stack... [0%] start: Publishing 06a2c6415fd2982e3285e9d615e5f9b99d1d795a9064479fbe6b88455ac62f6c:current [100%] fail: ENOENT: no such file or directory, open '/home/nburtsev/projects/aws-cdk-import-bug/cdk.out/AwsCdkImportBugStack.template.json-06a2c6415fd2982e3285e9d615e5f9b99d1d795a9064479fbe6b88455ac62f6c.yaml' ❌ AwsCdkImportBugStack failed: Error: Failed to publish one or more assets. See the error messages above for more information. at publishAssets (/home/nburtsev/projects/aws-cdk-import-bug/node_modules/aws-cdk/lib/index.js:420:84876) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async deployStack (/home/nburtsev/projects/aws-cdk-import-bug/node_modules/aws-cdk/lib/index.js:430:391) at async ResourceImporter.importResources (/home/nburtsev/projects/aws-cdk-import-bug/node_modules/aws-cdk/lib/index.js:433:171694) at async ResourceImporter.importResourcesFromMap (/home/nburtsev/projects/aws-cdk-import-bug/node_modules/aws-cdk/lib/index.js:433:171357) at async CdkToolkit.import (/home/nburtsev/projects/aws-cdk-import-bug/node_modules/aws-cdk/lib/index.js:433:205058) at async exec4 (/home/nburtsev/projects/aws-cdk-import-bug/node_modules/aws-cdk/lib/index.js:488:54378) Failed to publish one or more assets. See the error messages above for more information. ``` The file is created, it's just in the project root not in cdk.out: ``` ~/projects/aws-cdk-import-bug $ ls -la total 284 drwxr-xr-x 7 nburtsev users 4096 Mar 22 10:48 . drwxr-xr-x 8 nburtsev users 4096 Mar 22 10:11 .. -rw-r--r-- 1 nburtsev users 64131 Mar 22 10:48 AwsCdkImportBugStack.template.json-06a2c6415fd2982e3285e9d615e5f9b99d1d795a9064479fbe6b88455ac62f6c.yaml drwxr-xr-x 2 nburtsev users 4096 Mar 22 10:12 bin -rw-r--r-- 1 nburtsev users 3185 Mar 22 10:12 cdk.json drwxr-xr-x 2 nburtsev users 4096 Mar 22 10:48 cdk.out <cut> ``` ### Description of changes I've just added a path.join similar to how it is done in regular template generation. ### Description of how you validated changes I've added a test case but I believe tests are broken globally as per @TheRealAmazonKendra ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information