Skip to content

Custom client context parser error #212

Open
@christianbundy

Description

@christianbundy

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:

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

Relevant implementation:

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

{
  "custom": {
    "foo": "bar"
  }
}

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

{
  "custom": {
    "foo": {}
  }
}
{
  "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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions