aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.51k stars 434 forks source link

Error: DotnetCliPackageBuilder:RunPackageAction - [WinError 267] The directory name is invalid #1332

Open sjoerdhooft opened 4 years ago

sjoerdhooft commented 4 years ago

Describe the bug

CodeUri in Function has invalid directory name

To Reproduce

New-AWSPowerShellLambdaPackage -ScriptPath checkdomainavailable.ps1 -OutputPackage checkdomainavailable.zip

CheckDomainAvailableFunction: Type: AWS::Serverless::Function Properties: CodeUri: lambda/check-domain-available/checkdomainavailable.zip Handler: checkdomainavailable::checkdomainavailable.Bootstrap::ExecuteFunction Runtime: dotnetcore3.1 Role: !GetAtt OnBoardingR53LambdaRole.Arn Events: APIEvent: Type: Api Properties: Path: /checkdomainavailable Method: post RestApiId: !Ref OnBoardingAPI

Deployment will fail with the following output: An error occurred while deploying a SAM Application. Check the logs for more information by running the "View AWS Toolkit Logs" command from the Command Palette. Starting SAM Application deployment... Building SAM Application... Error with child process: Building function 'StartPaymentFunction' ,Running NodejsNpmBuilder:NpmPack ,Running NodejsNpmBuilder:CopyNpmrc ,Running NodejsNpmBuilder:CopySource ,Running NodejsNpmBuilder:NpmInstall ,Running NodejsNpmBuilder:CleanUpNpmrc ,Building function 'CheckDomainAvailableFunction' ,Running DotnetCliPackageBuilder:GlobalToolInstall , ,Tool 'amazon.lambda.tools' was reinstalled with the latest stable version (version '4.1.0'). ,Running DotnetCliPackageBuilder:RunPackageAction ,Error: DotnetCliPackageBuilder:RunPackageAction - [WinError 267] The directory name is invalid

Expected behavior

The function should be deployed to Lambda

Desktop (please complete the following information):

Additional context

In the template an additional nodejs function, as well as API and IAM roles are also deployed. This worked fine before I added the dotnetcore function.

Testing performed

I already tried moving the generated zip file to other directories anad different runtime dotnetcore2.1

justinmk3 commented 4 years ago

What version of sam cli are you using?

sam --version

AWS: Deploy SAM Application is a wrapper around the sam deploy CLI command. Can you try running sam deploy directly in your terminal and see what that yields?

The particular sam deploy ... command that the Toolkit tried, should be in the logs somewhere. If you can't find it in the logs, you can cd to your project directory where the template.yaml lives and try this command (replace "mystack" and "us-east-1" as appropriate):

sam deploy --template-file template.yaml --stack-name mystack --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --region us-east-1

Related: https://github.com/aws/aws-sam-cli/issues/2029

justinmk3 commented 4 years ago

Found a hint here: https://github.com/aws/aws-toolkit-jetbrains/issues/1230#issuecomment-578699315

sam build currently expects the CodeUri property to point to the root of the Maven project, not the build artifact (jar file).

sjoerdhooft commented 4 years ago

Hi Justin,

sam version: SAM CLI, version 1.2.0

I tried the sam deploy command manually and it was successful, so that fixes my problem for now, but I still would like to use the vscode toolkit.

By the way, I used a simplified version of my template for this:

Resources:
  CheckDomainAvailableFunction: 
    Type: AWS::Serverless::Function 
    Properties:
      CodeUri: C:\AzureRepos\reponame\WebAppPS\checkdomainavailable.zip
      Handler: checkdomainavailable::checkdomainavailable.Bootstrap::ExecuteFunction
      Runtime: dotnetcore2.1

I will test later with a full version, but it seems to be in whatever is wrapping it.

BTW, I did see the jetbrains link so I already tried moving the file to different location. Maybe to clarify, what directory would sam build consider the root of the project? I assumed it was the directory with the template.yaml file. Is that correct.

justinmk3 commented 4 years ago

I tried the sam deploy command manually and it was successful,

Can you share the exact command? Was it pointing to a template.yaml with CodeUri pointing to a .zip ?

what directory would sam build consider the root of the project?

Looks like C:\AzureRepos\reponame\WebAppPS would be the project root in this case.

So this would be your template.yaml (can you try this?):

Resources:
  CheckDomainAvailableFunction: 
    Type: AWS::Serverless::Function 
    Properties:
      CodeUri: C:\AzureRepos\reponame\WebAppPS
      Handler: checkdomainavailable::checkdomainavailable.Bootstrap::ExecuteFunction
      Runtime: dotnetcore2.1

If that doesn't work, try C:\AzureRepos\reponame as the project root.

sjoerdhooft commented 4 years ago

Hi, sorry it took a while, but I tried a full test. If I use sam deploy from commandline everything works as expected, under all circumstances.

Full command: sam deploy --template-file template.yaml --stack-name sam-pstestfull --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --region eu-west-1 --s3-bucket s3bucketname --profile profilename

This is the relevant template.yaml:

  CheckDomainAvailableFunction: 
    Type: AWS::Serverless::Function 
    Properties:
      CodeUri: lambda/check-domain-available/checkdomainavailable.zip
      Handler: checkdomainavailable::checkdomainavailable.Bootstrap::ExecuteFunction
      Runtime: dotnetcore2.1
      Role: !GetAtt OnBoardingR53LambdaRole.Arn
      Events:
        APIEvent:
          Type: Api
          Properties:
            Path: /checkdomainavailable
            Method: post
            RestApiId: !Ref OnBoardingAPI

I already tried C:\AzureRepos\reponame\WebAppPS and C:\AzureRepos\reponame and both fail using vscode AWS Toolkit.

justinmk3 commented 4 years ago

Status