Skip to content

Commit 4e03420

Browse files
piotrkubisabmoffatt
authored andcommitted
Add support for multi-value parameters in API Gateway proxy events (#136)
* Add extra fields to APIGatewayProxyRequest * Update the samples of the API Gateway Proxy events * Add multiValueHeaders * Add multiValueQueryStringParameters * Add requestContext.identity.accessKey
1 parent fb8f88d commit 4e03420

File tree

3 files changed

+80
-24
lines changed

3 files changed

+80
-24
lines changed

events/apigw.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ package events
44

55
// APIGatewayProxyRequest contains data coming from the API Gateway proxy
66
type APIGatewayProxyRequest struct {
7-
Resource string `json:"resource"` // The resource path defined in API Gateway
8-
Path string `json:"path"` // The url path for the caller
9-
HTTPMethod string `json:"httpMethod"`
10-
Headers map[string]string `json:"headers"`
11-
QueryStringParameters map[string]string `json:"queryStringParameters"`
12-
PathParameters map[string]string `json:"pathParameters"`
13-
StageVariables map[string]string `json:"stageVariables"`
14-
RequestContext APIGatewayProxyRequestContext `json:"requestContext"`
15-
Body string `json:"body"`
16-
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"`
7+
Resource string `json:"resource"` // The resource path defined in API Gateway
8+
Path string `json:"path"` // The url path for the caller
9+
HTTPMethod string `json:"httpMethod"`
10+
Headers map[string]string `json:"headers"`
11+
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
12+
QueryStringParameters map[string]string `json:"queryStringParameters"`
13+
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
14+
PathParameters map[string]string `json:"pathParameters"`
15+
StageVariables map[string]string `json:"stageVariables"`
16+
RequestContext APIGatewayProxyRequestContext `json:"requestContext"`
17+
Body string `json:"body"`
18+
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"`
1719
}
1820

1921
// APIGatewayProxyResponse configures the response to be returned by API Gateway for the request
@@ -45,6 +47,7 @@ type APIGatewayRequestIdentity struct {
4547
CognitoIdentityID string `json:"cognitoIdentityId"`
4648
Caller string `json:"caller"`
4749
APIKey string `json:"apiKey"`
50+
AccessKey string `json:"accessKey"`
4851
SourceIP string `json:"sourceIp"`
4952
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
5053
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
@@ -90,16 +93,18 @@ type APIGatewayCustomAuthorizerRequest struct {
9093

9194
// APIGatewayCustomAuthorizerRequestTypeRequest contains data coming in to a custom API Gateway authorizer function.
9295
type APIGatewayCustomAuthorizerRequestTypeRequest struct {
93-
Type string `json:"type"`
94-
MethodArn string `json:"methodArn"`
95-
Resource string `json:"resource"`
96-
Path string `json:"path"`
97-
HTTPMethod string `json:"httpMethod"`
98-
Headers map[string]string `json:"headers"`
99-
QueryStringParameters map[string]string `json:"queryStringParameters"`
100-
PathParameters map[string]string `json:"pathParameters"`
101-
StageVariables map[string]string `json:"stageVariables"`
102-
RequestContext APIGatewayCustomAuthorizerRequestTypeRequestContext `json:"requestContext"`
96+
Type string `json:"type"`
97+
MethodArn string `json:"methodArn"`
98+
Resource string `json:"resource"`
99+
Path string `json:"path"`
100+
HTTPMethod string `json:"httpMethod"`
101+
Headers map[string]string `json:"headers"`
102+
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
103+
QueryStringParameters map[string]string `json:"queryStringParameters"`
104+
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
105+
PathParameters map[string]string `json:"pathParameters"`
106+
StageVariables map[string]string `json:"stageVariables"`
107+
RequestContext APIGatewayCustomAuthorizerRequestTypeRequestContext `json:"requestContext"`
103108
}
104109

105110
// APIGatewayCustomAuthorizerResponse represents the expected format of an API Gateway authorization response.

events/testdata/apigw-custom-auth-request-type-request.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,35 @@
2727
"CloudFront-Is-Desktop-Viewer": "true",
2828
"Content-Type": "application/x-www-form-urlencoded"
2929
},
30+
"multiValueHeaders": {
31+
"X-AMZ-Date": ["20170718T062915Z"],
32+
"Accept": ["*/*"],
33+
"HeaderAuth1": ["headerValue1"],
34+
"CloudFront-Viewer-Country": ["US"],
35+
"CloudFront-Forwarded-Proto": ["https"],
36+
"CloudFront-Is-Tablet-Viewer": ["false"],
37+
"CloudFront-Is-Mobile-Viewer": ["false"],
38+
"User-Agent": ["..."],
39+
"X-Forwarded-Proto": ["https"],
40+
"CloudFront-Is-SmartTV-Viewer": ["false"],
41+
"Host": ["....execute-api.us-east-1.amazonaws.com"],
42+
"Accept-Encoding": ["gzip, deflate"],
43+
"X-Forwarded-Port": ["443"],
44+
"X-Amzn-Trace-Id": ["..."],
45+
"Via": ["...cloudfront.net (CloudFront)"],
46+
"X-Amz-Cf-Id": ["..."],
47+
"X-Forwarded-For": ["..., ..."],
48+
"Postman-Token": ["..."],
49+
"cache-control": ["no-cache"],
50+
"CloudFront-Is-Desktop-Viewer": ["true"],
51+
"Content-Type": ["application/x-www-form-urlencoded"]
52+
},
3053
"queryStringParameters": {
3154
"QueryString1": "queryValue1"
3255
},
56+
"multiValueQueryStringParameters": {
57+
"QueryString1": ["queryValue1"]
58+
},
3359
"pathParameters": {},
3460
"stageVariables": {
3561
"StageVar1": "stageValue1"

events/testdata/apigw-request.json

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,34 @@
2222
"X-Forwarded-For": "54.240.196.186, 54.182.214.83",
2323
"X-Forwarded-Port": "443",
2424
"X-Forwarded-Proto": "https"
25-
},
25+
},
26+
"multiValueHeaders": {
27+
"Accept": ["*/*"],
28+
"Accept-Encoding": ["gzip, deflate"],
29+
"cache-control": ["no-cache"],
30+
"CloudFront-Forwarded-Proto": ["https"],
31+
"CloudFront-Is-Desktop-Viewer": ["true"],
32+
"CloudFront-Is-Mobile-Viewer": ["false"],
33+
"CloudFront-Is-SmartTV-Viewer": ["false"],
34+
"CloudFront-Is-Tablet-Viewer": ["false"],
35+
"CloudFront-Viewer-Country": ["US"],
36+
"Content-Type": ["application/json"],
37+
"headerName": ["headerValue"],
38+
"Host": ["gy415nuibc.execute-api.us-east-1.amazonaws.com"],
39+
"Postman-Token": ["9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f"],
40+
"User-Agent": ["PostmanRuntime/2.4.5"],
41+
"Via": ["1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)"],
42+
"X-Amz-Cf-Id": ["pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A=="],
43+
"X-Forwarded-For": ["54.240.196.186, 54.182.214.83"],
44+
"X-Forwarded-Port": ["443"],
45+
"X-Forwarded-Proto": ["https"]
46+
},
2647
"queryStringParameters": {
27-
"name": "me"
28-
},
48+
"name": "me"
49+
},
50+
"multiValueQueryStringParameters": {
51+
"name": ["me"]
52+
},
2953
"pathParameters": {
3054
"proxy": "hello/world"
3155
},
@@ -42,7 +66,8 @@
4266
"accountId": "theAccountId",
4367
"cognitoIdentityId": "theCognitoIdentityId",
4468
"caller": "theCaller",
45-
"apiKey": "theApiKey",
69+
"apiKey": "theApiKey",
70+
"accessKey": "ANEXAMPLEOFACCESSKEY",
4671
"sourceIp": "192.168.196.186",
4772
"cognitoAuthenticationType": "theCognitoAuthenticationType",
4873
"cognitoAuthenticationProvider": "theCognitoAuthenticationProvider",

0 commit comments

Comments
 (0)