aws / aws/aws-lambda-runtime-interface-emulator

`sam local start-api` broken due to missing `lambda-runtime-invoked-function-arn` header since v1.13.0

未關閉
#11 10 則留言 12 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Go
星號
1.1k
分支
118
平均合併
42 分鐘
30 天內合併 PR
2

描述

### Description:

Up to version v1.12.0, I was able to test my API Gateway REST API using `sam local start-api` with a Lambda built on top of https://github.com/awslabs/aws-lambda-rust-runtime. However, this functionality stopped working in v1.13.0 due to the missing `lambda-runtime-invoked-function-arn` header that the runtime expects:
```
2020-12-04 17:54:54,881 | Found one Lambda function with name 'ApiFunction'
2020-12-04 17:54:54,881 | Invoking ignored (provided)
2020-12-04 17:54:54,881 | Environment variables overrides data is standard format
2020-12-04 17:54:54,881 | Loading AWS credentials from session with profile 'None'
2020-12-04 17:54:54,896 | Resolving code path. Cwd=/Users/daramos/...[redacted], CodeUri=.aws-sam/build-backend/ApiFunction
2020-12-04 17:54:54,897 | Resolved absolute path to code is /Users/daramos/...[redacted].../.aws-sam/build-backend/ApiFunction
2020-12-04 17:54:54,897 | Code /Users/daramos/...[redacted].../.aws-sam/build-backend/ApiFunction is not a zip/jar file
2020-12-04 17:54:54,940 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-provided:rapid-1.13.0.

2020-12-04 17:54:54,940 | Mounting /Users/daramos/Documents/Projects/...[redacted].../.aws-sam/build-backend/ApiFunction as /var/task:ro,delegated inside runtime container
2020-12-04 17:54:55,581 | Starting a timer for 3 seconds for function 'ApiFunction'
START RequestId: 5d85e30d-cda5-47dc-a1a6-4ed2ed87268c Version: $LATEST
thread 'main' panicked at 'no entry found for key "lambda-runtime-invoked-function-arn"', /Users/daramos/.cargo/git/checkouts/aws-lambda-rust-runtime-7c865cce90132439/13aa8f0/lambda/src/types.rs:131:35
```

The code runs fine on production AWS Lambda, so I believe this is a bug in the SAM CLI's local emulation, not in the Rust runtime. For reference, the runtime expects several headers to be provided by Lambda:
https://github.com/awslabs/aws-lambda-rust-runtime/blob/13aa8f01813e6949ca91aedafb286591fdf32217/lambda/src/types.rs#L123-L139

It looks like aws/aws-sam-cli#2425 may have introduced this regression (cc @sriram-mv). The code that previously set these headers was removed in that PR:
https://github.com/aws/aws-sam-cli/blob/559e4a564ba37906f2081c0de415b39bc9b2c3c1/samcli/local/rapid/init.go#L482-L486

### Steps to reproduce:

Use `sam local start-api` to test a REST API locally. In my case, using AWS Labs's Rust runtime.

### Observed result:

Lambda function panics due to missing headers (the same Lambda works fine on AWS).

### Expected result:

Lambda should execute without error.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: Mac OS 10.15.7
2. `sam --version`: 1.13.0 (also tested on 1.13.2 and latest `develop` HEAD).

`Add --debug flag to command you are running`

貢獻指南

開啟貢獻指南

研究方向

從 samcli/local/rapid/init.go 的第 482-486 行附近開始,將 header 設定與 Rust runtime 的 lambda/src/types.rs 第 123-139 行進行比較。使用提供的 AWS Labs Rust runtime 情境執行 sam local start-api;當本機 Lambda 收到預期的 headers,並在沒有因缺少 key 而 panic 的情況下執行時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
aws, docker, go, rust
領域
api, devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。