Skip to content
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

(cdk import): (imports of a certain size cause ENOENT error) #22530

Closed
tbreysse opened this issue Oct 17, 2022 · 7 comments
Closed

(cdk import): (imports of a certain size cause ENOENT error) #22530

tbreysse opened this issue Oct 17, 2022 · 7 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p1 package/tools Related to AWS CDK Tools or CLI response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@tbreysse
Copy link

Describe the bug

Currently, it seems that there is a bug with the 'cdk import' functionality which causes an ENOENT error when attempting to import multiple resources in certain templates.

Error:

 [100%] fail:ENOENT: no such file or directory, open '\cdk-sample\ cdk.out\ test-stack.template.json-4dd9ae34ff7bf1fc59854e70adaf75041674eba29d3d02e7a34f8521ce.yaml' 

After some extensive testing, I have not been able to find a definite root cause, but it seems that the issue appears to be related to template size and number of resources imported.

Expected Behavior

The expected behavior is that the import process will successfully import the resources without error

Current Behavior

After importing a certain number of resources the import command fails with an ENOENT error.

Reproduction Steps

  1. Create a CDK stack with the following code:
from constructs import Construct
from aws_cdk import (
    Stack,
    aws_iam,
    aws_apigateway,
    aws_lambda
)
import aws_cdk as cdk

class SampleAppStack(Stack):
    
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest1', 
            _replace_name='sampleTest1',
            #_alias='test'
        )

        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest2', 
            _replace_name='sampleTest2', 
            #_alias='test'
        )

        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest3', 
            _replace_name='sampleTest3', 
            #_alias='test'
        )
        
        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest4', 
            _replace_name='sampleTest4',
            #_alias='test'
        )       
        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest5', 
            _replace_name='sampleTest5', 
           #_alias='test'
        )
        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest6', 
            _replace_name='sampleTest6',
            #_alias='ST'
        )    
        
        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest7', 
            _replace_name='sampleTest7',
            #_alias='ST'
        )
        
        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest8', 
            _replace_name='sampleTest8',
            #_alias='test'
        )
         
        lambda_function = self.create_lambda_function(
            'manufacture-sampleTest9', 
            _replace_name = 'sampleTest9',
            #_alias='test'
        )
               
    def set_lambda_variables(self, _lmd_func):
        _lmd_func.add_environment(
            'testParam1', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 
        _lmd_func.add_environment(
            'testParam2', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 
        _lmd_func.add_environment(
            'testParam3', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 
        _lmd_func.add_environment(
            'testParam4', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 


    def create_lambda_function(self, _lambda_name: str, _replace_name: str, _alias=None):
        result_lambda = aws_lambda.Function(
            self,
            id='id-{}'.format(_lambda_name),
            function_name='lmd-an2-st-t20-common-{}'.format(_lambda_name),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        self.set_lambda_variables(result_lambda)
        function_version = result_lambda.current_version
        if _alias:
            _function_alias = aws_lambda.Alias(
                self,
                id='id-alias-{}'.format(_lambda_name),
                alias_name='{}'.format(_alias),
                version=function_version)
        cfn_lambda = result_lambda.node.default_child
        cfn_lambda.override_logical_id(_replace_name)
    
  1. Manually create an Alias for each of the created functions in the Lambda console.
  2. Uncomment the alias definition for reach resource in the code
  3. Run cdk import and import each of the Aliases.

For a second reproduction you can utilize the following template which shows the same behavior, but only after importing 10 Aliases as opposed to 6 which is the number that can import before failure for the above template.

from constructs import Construct
from aws_cdk import (
    Stack,
    aws_iam,
    aws_apigateway,
    aws_lambda
)
import aws_cdk as cdk

class Cdkpython3Stack(Stack):
    
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)
        result_lambda1 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest1'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest1'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda2 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest2'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest2'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda3 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest3'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest3'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda4 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest4'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest4'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda5 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest5'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest5'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda6 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest6'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest6'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda7 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest7'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest7'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda8 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest8'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest8'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        result_lambda9 = aws_lambda.Function(
            self,
            id='id-{}'.format('manufacture-sampleTest9'),
            function_name='lmd-an2-st-t20-common-{}'.format('manufacture-sampleTest9'),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )

        self.set_lambda_variables(result_lambda1)
        self.set_lambda_variables(result_lambda2)
        self.set_lambda_variables(result_lambda3)
        self.set_lambda_variables(result_lambda4)
        self.set_lambda_variables(result_lambda5)
        self.set_lambda_variables(result_lambda6)
        self.set_lambda_variables(result_lambda7)
        self.set_lambda_variables(result_lambda8)
        self.set_lambda_variables(result_lambda9)


        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest1'),
            alias_name='{}'.format('ST'),
            version=result_lambda1.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest2'),
            alias_name='{}'.format('ST'),
            version=result_lambda2.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest3'),
            alias_name='{}'.format('ST'),
            version=result_lambda3.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest4'),
            alias_name='{}'.format('ST'),
            version=result_lambda4.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest5'),
            alias_name='{}'.format('ST'),
            version=result_lambda5.latest_version)
        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest6'),
            alias_name='{}'.format('ST'),
            version=result_lambda6.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest7'),
            alias_name='{}'.format('ST'),
            version=result_lambda7.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest8'),
            alias_name='{}'.format('ST'),
            version=result_lambda8.latest_version)

        _function_alias = aws_lambda.Alias(
            self,
            id='id-alias-{}'.format('manufacture-sampleTest9'),
            alias_name='{}'.format('ST'),
            version=result_lambda9.latest_version)
               
    def set_lambda_variables(self, _lmd_func):
        _lmd_func.add_environment(
            'testParam1', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 
        _lmd_func.add_environment(
            'testParam2', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 
        _lmd_func.add_environment(
            'testParam3', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 
        _lmd_func.add_environment(
            'testParam4', '''"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "''' 
                ) 


    def create_lambda_function(self, _lambda_name: str, _replace_name: str, _alias=None):
        result_lambda = aws_lambda.Function(
            self,
            id='id-{}'.format(_lambda_name),
            function_name='lmd-an2-st-t20-common-{}'.format(_lambda_name),
            runtime=aws_lambda.Runtime.PYTHON_3_9,
            code=aws_lambda.Code.from_asset('lambda'),
            handler='hello.handler',
        )
        self.set_lambda_variables(result_lambda)
        function_version = result_lambda.current_version
        cfn_lambda = result_lambda.node.default_child
        cfn_lambda.override_logical_id(_replace_name)

Possible Solution

N/A

Additional Information/Context

As mentioned in the reproduction steps, the behavior of this bug is peculiar.

With the first provided reproduction template, you can import 6 Aliases before the failure occurs. The error will occur for any additional imports after 6.

With the second provided template, you can successfully import 9 Aliases, but once you try to import a 10th, the same error occurs again. Also the error occurs with both Python and TypeScript stacks.

It is understandable that issue such as this may occur since the cdk import feature is still currently in preview, however this behavior seems worth reporting.

CDK CLI Version

2.41.0

Framework Version

No response

Node.js Version

14.17.0

OS

Windows 10

Language

Typescript, Python

Language Version

No response

Other information

No response

@tbreysse tbreysse added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 17, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Oct 17, 2022
@mascur mascur added p1 package/tools Related to AWS CDK Tools or CLI effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-lambda Related to AWS Lambda labels Oct 18, 2022
@mascur
Copy link
Contributor

mascur commented Oct 18, 2022

Hi @tbreysse,

I was able to successfully reproduce this issue. Thank you for reporting this! We will try to look at this soon.

If anyone has any ideas on where the root cause of this issue may be occurring please feel free to comment below!

@kaizencc kaizencc removed their assignment Oct 28, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 10, 2022

@mascur does this reproduce anywhere besides Windows?

The ENOENT thoroughly confuses me. That means "file not found", but I don't see how template size would impact that.

The best I can think of is that there might be a race condition somewhere that only shows itself on Windows...

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 10, 2022

I also wonder what kind of file test-stack.template.json-4dd9ae34ff7bf1fc59854e70adaf75041674eba29d3d02e7a34f8521ce.yaml is supposed to be...

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 10, 2022

@mascur can you throw a repro up on GitHub?

@rix0rrr rix0rrr added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 6, 2023
@github-actions
Copy link

github-actions bot commented Jan 6, 2023

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 6, 2023
@woodyfeng-swingvy
Copy link

@mascur @rix0rrr
Take OP's output for example:

[100%] fail:ENOENT: no such file or directory, open '\cdk-sample\cdk.out\test-stack.template.json-4dd9ae34ff7bf1fc59854e70adaf75041674eba29d3d02e7a34f8521ce.yaml' 

The problem is the YAML file was generated under the project root, not the output directory
i.e. it would be at

'\cdk-sample\test-stack.template.json-4dd9ae34ff7bf1fc59854e70adaf75041674eba29d3d02e7a34f8521ce.yaml'

I hope this helps.

P.S. The content of the generated YAML looks just like a .template.json file

@camitz
Copy link

camitz commented Apr 29, 2024

@woodyfeng-swingvy is right.

mergify bot pushed a commit that referenced this issue May 10, 2024
…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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p1 package/tools Related to AWS CDK Tools or CLI response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

6 participants