aws / aws/aws-lambda-java-libs
Custom client context parser error
- Vorherrschende Sprache
- Java
- Sterne
- 548
- Forks
- 241
- Ø Merge
- 2 T. 5 Min.
- Gemergte PRs (30 T.)
- 11
Beschreibung
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!
Beitragsleitfaden
Rechercherichtung
Beginne mit LambdaClientContext.java in der verlinkten Implementierung und reproduziere den Fehler mit dem bereitgestellten aws lambda invoke-Befehl. Vergleiche die vom Parser akzeptierte Struktur des benutzerdefinierten Werts mit der verlinkten AWS Invoke-Dokumentation und ermittle anschließend, ob das Problem eine Verhaltenskorrektur oder eine klarere Dokumentation erfordert. Als abgeschlossen gilt die Aufgabe, wenn die beabsichtigte Einschränkung festgestellt und anhand des gemeldeten Payloads verifiziert wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- aws, java
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100