diff --git a/events/apigw.go b/events/apigw.go index 8a47d336..8db0d2e5 100644 --- a/events/apigw.go +++ b/events/apigw.go @@ -60,28 +60,37 @@ type APIGatewayV2HTTPRequest struct { // APIGatewayV2HTTPRequestContext contains the information to identify the AWS account and resources invoking the Lambda function. type APIGatewayV2HTTPRequestContext struct { - RouteKey string `json:"routeKey"` - AccountID string `json:"accountId"` - Stage string `json:"stage"` - RequestID string `json:"requestId"` - Authorizer struct { - JWT struct { - Claims map[string]string `json:"claims"` - Scopes []string `json:"scopes"` - } `json:"jwt"` - } `json:"authorizer"` - APIID string `json:"apiId"` // The API Gateway HTTP API Id - DomainName string `json:"domainName"` - DomainPrefix string `json:"domainPrefix"` - Time string `json:"time"` - TimeEpoch int64 `json:"timeEpoch"` - HTTP struct { - Method string `json:"method"` - Path string `json:"path"` - Protocol string `json:"protocol"` - SourceIP string `json:"sourceIp"` - UserAgent string `json:"userAgent"` - } `json:"http"` + RouteKey string `json:"routeKey"` + AccountID string `json:"accountId"` + Stage string `json:"stage"` + RequestID string `json:"requestId"` + Authorizer APIGatewayV2HTTPRequestContextAuthorizerDescription `json:"authorizer"` + APIID string `json:"apiId"` // The API Gateway HTTP API Id + DomainName string `json:"domainName"` + DomainPrefix string `json:"domainPrefix"` + Time string `json:"time"` + TimeEpoch int64 `json:"timeEpoch"` + HTTP APIGatewayV2HTTPRequestContextHTTPDescription `json:"http"` +} + +// APIGatewayV2HTTPRequestContextAuthorizerDescription contains authorizer information for the request context. +type APIGatewayV2HTTPRequestContextAuthorizerDescription struct { + JWT APIGatewayV2HTTPRequestContextAuthorizerJWTDescription `json:"jwt"` +} + +// APIGatewayV2HTTPRequestContextAuthorizerJWTDescription contains JWT authorizer information for the request context. +type APIGatewayV2HTTPRequestContextAuthorizerJWTDescription struct { + Claims map[string]string `json:"claims"` + Scopes []string `json:"scopes"` +} + +// APIGatewayV2HTTPRequestContextHTTPDescription contains HTTP information for the request context. +type APIGatewayV2HTTPRequestContextHTTPDescription struct { + Method string `json:"method"` + Path string `json:"path"` + Protocol string `json:"protocol"` + SourceIP string `json:"sourceIp"` + UserAgent string `json:"userAgent"` } // APIGatewayRequestIdentity contains identity information for the request caller. diff --git a/events/apigw_test.go b/events/apigw_test.go index 89eab6ff..0e2b0c0b 100644 --- a/events/apigw_test.go +++ b/events/apigw_test.go @@ -230,6 +230,12 @@ func TestApiGatewayV2HTTPRequestMarshaling(t *testing.T) { t.Errorf("could not extract authorizer claim from JWT: %v", authContext) } + // validate HTTP details + http := inputEvent.RequestContext.HTTP + if http.Path != "/my/path" { + t.Errorf("could not extract HTTP details: %v", http) + } + // serialize to json outputJSON, err := json.Marshal(inputEvent) if err != nil {