-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cli: overrideTemplate is stored in working directory rather than assembly directory (i.e. import does not work) #22928
Description
Describe the bug
Recently, I have had issues using cdk import that seem to stem from the overridden template being generated in my working directory rather than the assembly directory. Obviously, when deploy tries to use the generated template, it is expecting it to come from my assembly directory. Please see the Possible Solution section below for details.
Expected Behavior
cdk import should work without any issues
Current Behavior
Error message from cdk import:
[0%] start: Building and publishing 04926632678b4ce87690ab5dff6a51bed012b313a6dbc96b8be43c23aba2a6b1:current
[100%] fail: ENOENT: no such file or directory, open 'C:\Users\Me\my-repo\cdk.out\assembly-MyStage\MyStack1234ABCD.template.json-04926632678b4ce87690ab5dff6a51bed012b313a6dbc96b8be43c23aba2a6b1.yaml'
❌ MyStage/MyStack (MyStack) failed: Error: Failed to publish one or more assets. See the error messages above for more information.
Note that the MyStack1234ABCD.template.json-04926632678b4ce87690ab5dff6a51bed012b313a6dbc96b8be43c23aba2a6b1.yaml file is added to my working directory just before it gets to this stage of the process.
Reproduction Steps
I don't have a simple repo to reproduce the issue, but in the Possible Solution section below, I believe I identified the line of code that needs to be updated.
Possible Solution
I believe this line:
| await fs.writeFile(templateFile, templateJson, { encoding: 'utf-8' }); |
Should be changed to:
await fs.writeFile(path.join(stack.assembly.directory, templateFile), templateJson, { encoding: 'utf-8' }); Additional Information/Context
For some reason, I did not used to get this issue. I have been using cdk import since shortly after it was released and only recently did I start having issues. I update cdk regularly, so I don't know exactly what version introduced the issue, or if there is something different in my configuration that is causing the issue to surface, but I know that when I go back to 2.46.0 I still have the issue. Also, when I go into node_modules and manually update the line mentioned above, everything works as it is supposed to.
CDK CLI Version
2.50.0 (build 4c11af6)
Framework Version
2.50.0
Node.js Version
16.15.1
OS
Windows 10 Enterprise
Language
Typescript
Language Version
4.8.4
Other information
No response