aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.49k stars 1.17k forks source link

Bug: [WinError 3] The system cannot find the path specified #7053

Closed dan933 closed 3 months ago

dan933 commented 3 months ago

Description:

When using sam build I got the following error:

Error: [WinError 3] The system cannot find the path specified: '.aws-sam\build\TradesGateway\CreateSuperUser\node_modules\@aws-sdk\credential-provider-node\node_modules\@aws-sdk\client-sso-oidc\dist-es\auth\httpAuthExtensionConfiguration.js

full error ``` Error: [WinError 3] The system cannot find the path specified: '.aws-sam\\build\\TradesGateway\\CreateSuperUser\\node_modules\\@aws-sdk\\credential-provider-node\\node_modules\\@aws-sdk\\client-sso-oidc\\dist-es\\auth\\httpAuthExtensionConfiguration.js' Traceback: File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 783, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\cli\cli_config_file.py", line 347, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\decorators.py", line 92, in new_func return ctx.invoke(f, obj, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 783, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\telemetry\metric.py", line 185, in wrapped raise exception # pylint: disable=raising-bad-type ^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\telemetry\metric.py", line 150, in wrapped return_value = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\utils\version_checker.py", line 43, in wrapped actual_result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\cli\main.py", line 95, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\command.py", line 175, in cli do_cli( File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\command.py", line 240, in do_cli with BuildContext( File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\build_context.py", line 185, in __enter__ self.set_up() File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\build_context.py", line 216, in set_up self._build_dir = self._setup_build_dir(self._build_dir, self._clean) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\build_context.py", line 467, in _setup_build_dir shutil.rmtree(build_dir) File "shutil.py", line 787, in rmtree File "shutil.py", line 629, in _rmtree_unsafe File "shutil.py", line 629, in _rmtree_unsafe File "shutil.py", line 629, in _rmtree_unsafe [Previous line repeated 7 more times] File "shutil.py", line 634, in _rmtree_unsafe File "shutil.py", line 632, in _rmtree_unsafe ```

I control click on the path and the file does exist.

I have run this code recently and the resources successfully built and deployed, I'm not too sure what has changed.

Steps to reproduce:

I have an sam template with nested AWS::Serverless::Applications

One is an API gateway that contains a lambda function

  TradesGateway:
    Type: AWS::Serverless::Application
    Properties:
      Parameters:
        CognitoUserPoolId: !GetAtt Cognito.Outputs.CognitoUserPoolId
        Stage: !Ref Stage
        DBUser: !Ref DBUser
        DBPassword: !Ref DBPassword
        DBName: !Ref DBName
        superUserToken: !Ref superUserToken
      Location: gateway-service/gateway.yaml
    DependsOn:
    - Cognito
    - TradesAppVpc
    - DB
  CreateSuperUser:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: src/auth-services/
      Handler: createSuperUser/createSuperUser.handler
      Runtime: nodejs20.x
      Architectures:
      - x86_64
      MemorySize: 128
      Timeout: 30
      Description: Create super user
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /super-user/create
            Method: POST
            RestApiId: !Ref TradesGateway
            Auth:
              Authorizer: SuperUserAuthorizer
      Policies:
        - AWSLambdaBasicExecutionRole
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - cognito-idp:AdminCreateUser
                - cognito-idp:AdminAddUserToGroup
                - cognito-idp:AdminGetUser
                - cognito-idp:*
              Resource: !Sub 'arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/${CognitoUserPoolId}'

The CodeUri src/auth-services/ Has a package.json file that contains the following

{
  "name": "auth-services",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-cognito-identity-provider": "^3.556.0",
    "drizzle-orm": "^0.30.9",
    "postgres": "^3.4.4",
    "@middy/core": "^5.3.2",
    "@middy/http-error-handler": "^5.3.2",
    "@middy/http-header-normalizer": "^5.3.2",
    "@middy/http-json-body-parser": "^5.3.2",
    "http-errors": "^2.0.0"
  }
}

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

{
  "version": "1.116.0",
  "system": {
    "python": "3.11.8",
    "os": "Windows-10-10.0.22631-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "1.8.0-dev"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
  1. OS: Windows 11
  2. sam --version: 1.116.0
  3. AWS region: ap-southeast-2
Debug Flag Results ``` Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '35281d10-e415-4b78-8701-d3f2a997ee15', 'installationId': '10cf6eca-c014-4575-af67-d030eee179a3', 'sessionId': '9ecf0710-f3d5-4d3f-816f-ae059ee8e0c4', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.8', 'samcliVersion': '1.116.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': '3f532e426edb4a28cae24acc7fd3710e390d888ae282fa55d24479415da6e11a', 'projectName': '633a6425fe620c0a7ae67cca6534721acf155109b996592270dc69d82c263aaa', 'initialCommit': '49949bef54acfa9045e6714d0b55e027630d2380871b23a6768be818381c2cc2'}, 'duration': 330, 'exitReason': 'FileNotFoundError', 'exitCode': 255}}]} 2024-05-12 16:36:00,733 | Unable to find Click Context for getting session_id. 2024-05-12 16:36:00,736 | Sending Telemetry: {'metrics': [{'events': {'requestId': '88e7a8a7-dc9b-4fc3-a791-6725db3a089c', 'installationId': '10cf6eca-c014-4575-af67-d030eee179a3', 'sessionId': '9ecf0710-f3d5-4d3f-816f-ae059ee8e0c4', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.8', 'samcliVersion': '1.116.0', 'commandName': 'sam build', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '9eb3f03f2bd841b083a66e6c2b6f315a', 'time_stamp': '2024-05-12 06:36:00.273', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '8b5976734611478393c3c7b4a7264008', 'time_stamp': '2024-05-12 06:36:00.289', 'exception_name': None}]}}}]} 2024-05-12 16:36:01,707 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) 2024-05-12 16:36:01,708 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) ```

I apologies if I have not correctly laid out this issue as this is the first issue I have submitted

mndeveci commented 3 months ago

Hi @dan933,

Thanks for reporting this issue. Can you re-run sam build by removing the .aws-sam folder? I wonder if that would help the fix for the issue.

Also, I saw that you are using Windows, did you enable long path configuration on your machine? It might create problems when path of the file gets longer.

dan933 commented 3 months ago

Thank you @mndeveci, I removed the .aws-sam build folder and this solved the issue I really appreciate the help. I did not have long file paths enabled I have enabled it incase this causes problems in the future.

mndeveci commented 3 months ago

Sounds good! Please let us know if you experience other issues in the future

github-actions[bot] commented 3 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.