aws-lambdaaws-powershell

AWS LambdaPSCore creating package doesnt work


Im currently on an ubuntu 22.04 from aws ec2 and i also set the aws credentials. i want to crate the lambda package for a .ps1 script using this command New-AWSPowerShellLambdaPackage -ScriptPath test.ps1 -OutputPackage test.zip but when i run the command i receive this

Staging deployment at /tmp/test
Configuring PowerShell to version 7.4.1
Generating C# project /tmp/test/test.csproj used to create Lambda function bundle.
Generating /tmp/test/Bootstrap.cs to load PowerShell script and required modules in Lambda environment.
Generating aws-lambda-tools-defaults.json config file with default values used when publishing project.
Copying PowerShell script to staging directory
Saving module AWS.Tools.Common
Resolved full output package path as /home/ubuntu/test/src/../Scripts/lamda_package/test.zip
Creating deployment package at /home/ubuntu/test/src/../Scripts/lamda_package/test.zip
Restoring .NET Lambda deployment tool
Initiate packaging
Exception: /root/.local/share/powershell/Modules/AWSLambdaPSCore/4.0.0.0/Private/_DeploymentFunctions.ps1:279
Line |
 279 |              throw $msg
     |              ~~~~~~~~~~
     | Error publishing PowerShell Lambda Function: 255 CALLSTACK: Command                        Arguments
     | Location -------                        ---------                                                                                                                --------
     | _packageProject                {OutputPackage=/home/ubuntu/test/src/../Scripts/lamda_package/test.zip, BuildDirectory=/tmp/test, FunctionArchitecture=} _DeploymentFunctions.ps1:
     | line 277 New-AWSPowerShellLambdaPackage {ScriptPath=../Scripts/test.ps1, OutputPackage=../Scripts/lamda_package/test.zip}
     | New-AWSPowerShellLambdaPackage.ps1: … <ScriptBlock>                  {}
     | <No file>

i also have all the required modules installed

PS /home/ubuntu/test/src> get-InstalledModule

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
4.1.543              AWSPowerShell.NetCore               PSGallery            The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell…
2.2.5                PowerShellGet                       PSGallery            PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts…
4.0.0.0              AWSLambdaPSCore                     PSGallery            The AWS Lambda Tools for Powershell can be used to create and deploy AWS Lambda functions written in PowerShe…
1.0.2.5              AWS.Tools.Installer                 PSGallery            The AWS.Tools.Installer module makes it easier to install, update and uninstall other AWS.Tools modules (see …
1.4.8.1              PackageManagement                   PSGallery            PackageManagement (a.k.a. OneGet) is a new way to discover and install software packages from around the web.…

and dotnet 8 installed, what can i do in orded to create the package?


Solution

  • fixed this by adding an iam role with Lambda access permissions, and also install zip on my ec2