aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Vague error message if zip command is missing in AWSLambdaPSCore

Open pcgeek86 opened this issue 3 years ago • 5 comments

Description

When setting up AWSLambdaPSCore on a fresh EC2 instance running Ubuntu Server 20.04 LTS, some dependencies for the AWSLambdaPSCore module are not pre-installed. If you attempt to publish a PowerShell-based AWS Lambda function, you receive a very bizarre error message.

  • zip command is not installed by default

Expected Behavior

The Publish-AWSPowerShellLambda command should run dependency checks early on, before running the dotnet restore command, so that any missing utilities can be installed, and DOTNET_ROOT is set correctly. Any missing dependencies should be listed out, along with remediation commands, to provide a pleasant user experience for this command.

I've also come across an issue where libhostfxr.so could not be found. I think that's somehow related to DOTNET_ROOT, but I'm not entirely sure, as I can't seem to intentionally reproduce it. I think it had something to do with having .NET Core 5.0 installed, but not 3.1.

Here's a list of dependency checks that I'm currently aware of, which should be executed each time an invocation of Publish-AWSPowerShellLambda is made:

  • .NET Core SDK installed
  • DOTNET_ROOT set correctly (if required)
  • libhostfxr.so can be located
  • zip command is installed

There may be other dependency checks that should be included as well, so please feel free to add them to this issue report.

Reproduction Steps

bash> sudo snap install powershell --classic
bash> pwsh
PS > Install-Module -Name AWSLambdaPSCore -Scope CurrentUser -Force
PS > Publish-AWSPowerShellLambda ..........
Zipping publish folder /tmp/generatetonsofdata.ps1/bin/Release/netcoreapp3.1/publish to /tmp/generatetonsofdata.ps1/bin/Release/netcoreapp3.1/generatetonsofdata.ps1.zip
Failed to find the "zip" utility program in path. This program is required to maintain Linux file permissions in the zip archive.
Exception: /home/ubuntu/.local/share/powershell/Modules/AWSLambdaPSCore/2.0.0.0/Private/_DeploymentFunctions.ps1:203
Line |
 203 |              throw $msg
     |              ~~~~~~~~~~
     | Error publishing PowerShell Lambda Function: 255 CALLSTACK: Command                     Arguments -------                     ---------
     | _deployProject              {ProfileName=, PowerShellFunctionHandler=, Region=, EnvironmentVariables=, Tags=, PublishNewVersion=, DisableInteractive=,
     | FunctionRole=arn:aws:iam::665453315… Publish-AWSPowerShellLambda {Name=generatetonsofdata, ScriptPath=./generatetonsofdata.ps1/generatetonsofdata.ps1.ps1,
     | IAMRoleArn=arn:aws:iam::665453315198:role/lambdaworkspacescleanup}    <ScriptBlock>               {}

Environment

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Linux 5.4.0-1038-aws #40-Ubuntu SMP Fri Feb 5 23:50:40 UTC 2021
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Resolution

  • [ ] :wave: I can/would-like-to implement a fix for this problem myself

This is a :bug: bug-report

pcgeek86 avatar Mar 09 '21 17:03 pcgeek86

Hi @pcgeek86,

Good morning.

I'm not sure if this is a PowerShell CmdLet issue, rather an environmental issue. From what I understand, PowerShell CmdLet tries to invoke AWS Lambda tools to deploy the function https://github.com/aws/aws-lambda-dotnet/blob/34a4e6dd70f92be0438022ce7480a539d7763600/PowerShell/Module/Private/_DeploymentFunctions.ps1#L182.

The Lambda tools basically creates a ZIP file for lambda deployment and then publishes the function. Hence, the ZIP command is pretty much a prerequisite for deploying Lambda. It is quite possible that ZIP utility is not installed by default on EC2 Ubuntu image, which is something you would need to configure.

Thanks, Ashish

ashishdhingra avatar Mar 09 '21 18:03 ashishdhingra

Hello @ashishdhingra, I think you might have missed the point. You're right that it's not a problem with the cmdlet, but it is a user experience enhancement, to avoid frustration during the development and deployment process.

Example Analogy

For example, let's say that I was developing a PowerShell module, or a module for any other language. Let's say that my module has dependencies on other external utilities or modules. If someone tries to use my module, and it randomly fails, with a vague error message, then they would not be happy that they have to do a bunch of digging to find out the root cause of the failure. Instead, if my module includes some pre-flight validation checks to ensure that all dependencies are in place, before actually attempting to execute the core functionality of that feature, then the user / customer will have a significantly improved experience.

This same practice is widely used in the software industry, to avoid poor user experiences. I'm sure you have come across similar examples before.

To reiterate, this is a user experience improvement, not an actual bug with how the cmdlet works. However, I have run into these vague error messages many times, and I keep having to go out to Google to research the problem and find out how to fix it.

If I am encountering this problem multiple times, then I'm sure other AWS customers will encounter the problem as well. The customer obsessed thing to do would be to perform pre-flight checks and not waste the customer's time attempting to run a dotnet restore, followed by a zip command, that is guaranteed to fail.

pcgeek86 avatar Mar 09 '21 18:03 pcgeek86

@pcgeek86 Thanks for your response. I will convert this to feature-request and have developer look at it.

ashishdhingra avatar Mar 09 '21 19:03 ashishdhingra

Recently spent some time troubleshooting the same issue. This was as clean install of Ubuntu 20.04 LTS on WSL 2. Easy fix, just took a while for me to figure it out.

PrimerFender avatar Jun 20 '21 20:06 PrimerFender

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

github-actions[bot] avatar Aug 13 '22 00:08 github-actions[bot]