aws / aws-lambda-go

Libraries, samples and tools to help Go developers develop AWS Lambda functions.
Apache License 2.0
3.65k stars 555 forks source link

RequestContext.Authorizer differs between REST gateway vs HTTP gateway #549

Closed alexanderwink closed 10 months ago

alexanderwink commented 10 months ago

Describe the bug

Transitioning from REST gateway to HTTP gateway (v1)

My authorizer end with something like this:

authResponse.Context = map[string]interface{}{ "field1": fieldvalue1, "field2": fieldvalue2, }

When using REST gateway I can get the authorizer context by the RequestContext.Authorizer map which is a map[string]interface{}

But when using HTTP gateway the RequestContext.Authorizer map does not look the same.

Here is a printout from the logs

REST gateway map[field1: fieldvalue1 field2: fieldvalue2]

HTTP gateway map[lambda:map[[dbName:treks_dev userId:11](field1: fieldvalue1 field2: fieldvalue2)]]

This makes transitioning from REST to HTTP gateway cumbersome since it requires code changes in all functions that use the autorizer.

Expected Behavior

I expect the response (v1) from HTTP gateway to be identical to the response from the REST gateway so that changing from REST to HTTP gateway is possible without code changes to the functions.

Current Behavior

HTTP gateway response has an extra level of map[string]interface{} within the Context map. It does not look like this was intended.

Reproduction Steps

Any authorizer that returns a context. Access the authorizer context in a function (REST gateway) like this: context := request.RequestContext.Authorizer field1 := context["field1"].(string)

Change to HTTP gateway and the second line will cause a NPE since there a map in a map in this case and field1 is only available in the inner map.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

v1.44.0

Environment details (Version of Go (go version)? OS name and version, etc.)

go version go1.21.6, running on AWS provided.al2