aws / aws/aws-lambda-java-libs

Custom client context parser error

オープン
#212 コメント 0 件 リアクション 5 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
548
フォーク
241
平均マージ
2日 5分
マージ済み PR(30日)
11

説明

We've recently discovered a bug in aws-lambda-java-core (1.2.0) where custom client context will throw a parser error.

[Relevant AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax):

> Up to 3583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.

Relevant implementation:

https://github.com/aws/aws-lambda-java-libs/blob/593e60301192f7f908daf215f63df96aa1668350/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/api/LambdaClientContext.java#L13

This implementation specifies that `custom` is a map of key-value pairs, for example:

```json
{
"custom": {
"foo": "bar"
}
}
```

If you try to pass anything else, you'll see a parser error:

```json
{
"custom": {
"foo": {}
}
}
```

```json
{
"errorMessage": "java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 20 path $.custom.",
"errorType": "com.google.gson.JsonSyntaxException",
"stackTrace": [
"com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200)",
"com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)"
],
"cause": {
"errorMessage": "Expected a string but was BEGIN_OBJECT at line 1 column 20 path $.custom.",
"errorType": "java.lang.IllegalStateException",
"stackTrace": [
"com.google.gson.stream.JsonReader.nextString(JsonReader.java:837)",
"com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:358)",
"com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:346)",
"com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)",
"com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187)",
"com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)",
"com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)",
"com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)",
"com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)"
]
}
}
```

If you have any lambdas that use this library, you can trigger the error with:

```sh
aws lambda invoke \
--function-name some-function \
--client-context $(echo '{"custom": {"foo":{}}}' | base64) \
/dev/stdout
```

Is there any documentation that explains this constraint, or is this a bug? Thanks for your work on this project!

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

リンク先の実装にある LambdaClientContext.java から始め、提供された aws lambda invoke コマンドを使って失敗を再現します。parser が受け付けるカスタム値の形状を、リンク先の AWS Invoke ドキュメントと比較し、そのうえで、この問題に動作の修正が必要なのか、より明確なドキュメントが必要なのかを判断します。報告された payload に対して意図された制約が確立され、検証されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
aws, java
領域
api, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。