Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws/aws-lambda-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.15.0
Choose a base ref
...
head repository: aws/aws-lambda-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.16.0
Choose a head ref
  • 3 commits
  • 5 files changed
  • 3 contributors

Commits on Mar 27, 2020

  1. support for HTTP api gateway (#274)

    * support for HTTP api gateway
    
    * payload keys and struct rename
    
    * field adds
    
    * APIGatewayV2HTTPRequest struct name update
    
    * de-serialization test case for new v2 http
    
    * log update
    
    * Remove RouteID - it's not present in the payload
    
    * test case update
    
    * Update apigw.go
    
    * Update apigw.go
    
    Had a chat with one of the gateway devs, who pointed out that the shape of Authorizer wouldn't be extensible for future shapes of authorizers
    
    * Update apigw.go
    
    * Update apigw_test.go
    
    * Update apigw-v2-request.json
    
    * Update apigw.go
    
    Co-authored-by: Shashank Sachan <thinkesta@gmail.com>
    Co-authored-by: Bryan Moffatt <bmoffatt@users.noreply.github.com>
    3 people authored Mar 27, 2020
    Copy the full SHA
    8375058 View commit details
  2. Try moving codecov integration to github action (#275)

    * Try moving codecov integration into github action
    
    * Update tests.yml
    
    try using the github action instead
    bmoffatt authored Mar 27, 2020
    Copy the full SHA
    5365894 View commit details
  3. Delete .travis.yml

    bmoffatt authored Mar 27, 2020
    Copy the full SHA
    18b6069 View commit details
Showing with 133 additions and 36 deletions.
  1. +5 −1 .github/workflows/tests.yml
  2. +0 −35 .travis.yml
  3. +42 −0 events/apigw.go
  4. +29 −0 events/apigw_test.go
  5. +57 −0 events/testdata/apigw-v2-request.json
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -31,4 +31,8 @@ jobs:

- name: go test
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...


- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

42 changes: 42 additions & 0 deletions events/apigw.go
Original file line number Diff line number Diff line change
@@ -42,6 +42,48 @@ type APIGatewayProxyRequestContext struct {
APIID string `json:"apiId"` // The API Gateway rest API Id
}

// APIGatewayV2HTTPRequest contains data coming from the new HTTP API Gateway
type APIGatewayV2HTTPRequest struct {
Version string `json:"version"`
RouteKey string `json:"routeKey"`
RawPath string `json:"rawPath"`
RawQueryString string `json:"rawQueryString"`
Cookies []string `json:"cookies"`
Headers map[string]string `json:"headers"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
PathParameters map[string]string `json:"pathParameters"`
RequestContext APIGatewayV2HTTPRequestContext `json:"requestContext"`
StageVariables map[string]string `json:"stageVariables"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded"`
}

// 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"`
}

// APIGatewayRequestIdentity contains identity information for the request caller.
type APIGatewayRequestIdentity struct {
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId"`
29 changes: 29 additions & 0 deletions events/apigw_test.go
Original file line number Diff line number Diff line change
@@ -209,3 +209,32 @@ func TestApiGatewayRestApiOpenApiRequestMarshaling(t *testing.T) {

assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestApiGatewayV2HTTPRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

// de-serialize into Go object
var inputEvent APIGatewayV2HTTPRequest
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// validate custom authorizer context
authContext := inputEvent.RequestContext.Authorizer
if authContext.JWT.Claims["claim1"] != "value1" {
t.Errorf("could not extract authorizer claim from JWT: %v", authContext)
}

// serialize to json
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

assert.JSONEq(t, string(inputJSON), string(outputJSON))
}
57 changes: 57 additions & 0 deletions events/testdata/apigw-v2-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "2.0",
"routeKey": "$default",
"rawPath": "/my/path",
"rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value",
"cookies": [
"cookie1",
"cookie2"
],
"headers": {
"Header1": "value1",
"Header2": "value2"
},
"queryStringParameters": {
"parameter1": "value1,value2",
"parameter2": "value"
},
"pathParameters": {
"proxy": "hello/world"
},
"requestContext": {
"routeKey": "$default",
"accountId": "123456789012",
"stage": "$default",
"requestId": "id",
"authorizer": {
"jwt": {
"claims": {
"claim1": "value1",
"claim2": "value2"
},
"scopes": [
"scope1",
"scope2"
]
}
},
"apiId": "api-id",
"domainName": "id.execute-api.us-east-1.amazonaws.com",
"domainPrefix": "id",
"time": "12/Mar/2020:19:03:58+0000",
"timeEpoch": 1583348638390,
"http": {
"method": "GET",
"path": "/my/path",
"protocol": "HTTP/1.1",
"sourceIp": "IP",
"userAgent": "agent"
}
},
"stageVariables": {
"stageVariable1": "value1",
"stageVariable2": "value2"
},
"body": "{\r\n\t\"a\": 1\r\n}",
"isBase64Encoded": false
}