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

使用GitHub Actions部署SAM Lambda函数时出现.deps.json文件缺失错误

.NET Lambda通过GitHub Actions部署时缺失.deps.json文件的问题

部署后的Lambda函数执行时触发以下错误:

Error: .NET binaries for Lambda function are not correctly installed in the /var/task directory of the image when the image was built. The /var/task directory is missing the required .deps.json file.
INIT_REPORT Init Duration: 25.79 ms Phase: init Status: error   Error Type: Runtime.ExitError

使用AWS Toolkit直接发布的函数可正常执行,本地Lambda模拟工具运行也无问题。

复现步骤

  • 使用VS2022通过AWS Toolkit创建AWS Serverless Application(.NET Core - C#)项目
  • 项目配置:名称为sam-lambda-helloworld,解决方案存于独立目录
  • 选择Blueprint为Annotations Framework Sample
  • (可选)删除多余函数简化项目
  • 添加.github/workflows/deploy-staging.yml文件,内容如下:
name: Deploy Lambda to Staging
on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v3

    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '8.0.x'

    - name: Install dependencies
      run: dotnet restore sam-lambda-helloworld/sam-lambda-helloworld.csproj

    - name: Publish project
      run: dotnet publish sam-lambda-helloworld/sam-lambda-helloworld.csproj -c Release -o ./sam-lambda-helloworld/publish --self-contained true -r linux-x64

    - name: Package SAM Application
      run: |
        cd sam-lambda-helloworld
        sam package \
          --template-file serverless.template \
          --s3-bucket ***yours3bucket*** \
          --output-template-file packaged.yml \
          --region ***yourregion***
      env:
        AWS_ACCESS_KEY_ID: ***INSERT_CODEDEPLOY_ID***
        AWS_SECRET_ACCESS_KEY: ***INSERT_SECRET***

    - name: Upload Packaged Template
      uses: actions/upload-artifact@v4
      with:
        name: sam-lambda-helloworld-packaged-template
        path: sam-lambda-helloworld/packaged.yml

  deploy:
    runs-on: ubuntu-latest
    needs: build

    steps:
    - name: Download Packaged Template
      uses: actions/download-artifact@v4
      with:
        name: sam-lambda-helloworld-packaged-template

    - name: Deploy SAM Application
      run: |
        sam deploy \
          --template-file packaged.yml \
          --stack-name Stack-Lambda-HelloWorld \
          --capabilities CAPABILITY_IAM \
          --region ***yourregion***
      env:
        AWS_ACCESS_KEY_ID: ***INSERT_CODEDEPLOY_ID***
        AWS_SECRET_ACCESS_KEY: ***INSERT_SECRET***

该流程可成功创建CloudFormation堆栈、API网关及Lambda函数,但测试函数时会触发上述错误。

已尝试的操作

  • 确认项目中GenerateRuntimeConfigurationFiles默认设为true
  • 修改部署包类型,仅按预期改变了上传的工件,但未解决错误
  • 手动修改serverless.template将codeUri设为./publish可解决问题,但Lambda Annotations框架会自动将其覆盖为.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 04:52:11