You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04环境下AWSPowerShellLambdaPackage打包失败求助

解决AWS PowerShell Lambda打包失败(错误码255)的问题

问题场景

在AWS EC2的Ubuntu 22.04实例上,已配置AWS凭证,执行以下命令打包PowerShell脚本为Lambda包时失败:

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

报错信息

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>

已确认的环境配置

已安装所有必需模块:

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.…

同时已安装.NET 8。

解决方案

按以下步骤逐一排查解决:

  • 确保输出目录存在且权限充足
    报错中输出路径为/home/ubuntu/test/Scripts/lamda_package/test.zip,先确认目录存在并赋予当前用户读写权限:

    mkdir -p /home/ubuntu/test/Scripts/lamda_package
    chown -R ubuntu:ubuntu /home/ubuntu/test/Scripts/lamda_package
    
  • 明确指定FunctionArchitecture参数
    AWSLambdaPSCore 4.x版本需要明确指定架构,避免默认值不兼容。根据EC2实例架构选择x86_64或arm64:

    New-AWSPowerShellLambdaPackage -ScriptPath ../Scripts/test.ps1 -OutputPackage ../Scripts/lamda_package/test.zip -FunctionArchitecture x86_64
    
  • 更新AWSLambdaPSCore模块至最新版本
    当前使用的4.0.0.0版本可能存在已知问题,更新到最新版本:

    Update-Module AWSLambdaPSCore -Force
    
  • 手动安装.NET Lambda工具
    确保依赖的.NET Lambda工具完整安装:

    dotnet tool install -g Amazon.Lambda.Tools
    

    安装完成后重启PowerShell再执行打包命令。

  • 使用绝对路径替代相对路径
    避免相对路径解析错误,改用绝对路径指定脚本和输出包:

    New-AWSPowerShellLambdaPackage -ScriptPath /home/ubuntu/test/Scripts/test.ps1 -OutputPackage /home/ubuntu/test/Scripts/lamda_package/test.zip -FunctionArchitecture x86_64
    
  • 开启详细日志定位问题
    添加-Verbose参数获取更详细的错误信息,便于定位具体失败原因:

    New-AWSPowerShellLambdaPackage -ScriptPath ../Scripts/test.ps1 -OutputPackage ../Scripts/lamda_package/test.zip -Verbose
    

内容的提问来源于stack exchange,提问作者nitu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 08:13:15