aws / aws/aws-lambda-java-libs

Custom client context parser error

Aperta
#212 0 commenti 5 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
548
Fork
241
Merge medio
2g 5m
PR unite (30g)
11

Descrizione

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!

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.