AWS API GatewayからLambdaに渡ってくるREST APIイベントの中身
今更
HTTP API (V2) はこちら↓
AWS API GatewayからLambdaに渡ってくるHTTP API (V2) イベントの中身
リソース /{param1}/{param2}/hello
のメソッド ANY
でLambda関数を呼び出せるようにし、ステージ v1
を作成し、以下の curl
コマンドで叩いたときのイベントの中身
curl -X POST -H 'Content-Type: application/json' -H 'X-Foo: bar' -H 'X-Baz: eee' -H 'X-Baz: ff,f' -d '{"zzz":123}' 'https://9999999999.execute-api.ap-northeast-1.amazonaws.com/v1/xxx/yyy/hello?hoge=hg&piyo=py&fuga=aaa&fuga=b,bb&yahe%5B0%5D=ccc&yahe%5B1%5D=ddd'
{
"resource": "/{param1}/{param2}/hello",
"path": "/xxx/yyy/hello",
"httpMethod": "POST",
"headers": {
"Accept": "*/*",
"Content-Type": "application/json",
"Host": "9999999999.execute-api.ap-northeast-1.amazonaws.com",
"User-Agent": "curl/7.79.1",
"X-Amzn-Trace-Id": "Root=1-62204502-626249395173cb4853d09727",
"X-Baz": "ff,f",
"X-Foo": "bar",
"X-Forwarded-For": "1.1.1.1",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"multiValueHeaders": {
"Accept": ["*/*"],
"Content-Type": ["application/json"],
"Host": ["9999999999.execute-api.ap-northeast-1.amazonaws.com"],
"User-Agent": ["curl/7.79.1"],
"X-Amzn-Trace-Id": ["Root=1-62204502-626249395173cb4853d09727"],
"X-Baz": ["eee", "ff,f"],
"X-Foo": ["bar"],
"X-Forwarded-For": ["1.1.1.1"],
"X-Forwarded-Port": ["443"],
"X-Forwarded-Proto": ["https"]
},
"queryStringParameters": {
"fuga": "b,bb",
"hoge": "hg",
"piyo": "py",
"yahe[0]": "ccc",
"yahe[1]": "ddd"
},
"multiValueQueryStringParameters": {
"fuga": ["aaa", "b,bb"],
"hoge": ["hg"],
"piyo": ["py"],
"yahe[0]": ["ccc"],
"yahe[1]": ["ddd"]
},
"pathParameters": {
"param1": "xxx",
"param2": "yyy"
},
"stageVariables": null,
"requestContext": {
"resourceId": "xxxxxx",
"resourcePath": "/{param1}/{param2}/hello",
"httpMethod": "POST",
"extendedRequestId": "OY-4YEXcNjMFiVA=",
"requestTime": "03/Mar/2022:04:33:06 +0000",
"path": "/v1/xxx/yyy/hello",
"accountId": "000000000000",
"protocol": "HTTP/1.1",
"stage": "v1",
"domainPrefix": "9999999999",
"requestTimeEpoch": 1646281986215,
"requestId": "3ca94c8f-cdd8-4b7a-a7a2-3a01a04e3d34",
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"sourceIp": "1.1.1.1",
"principalOrgId": null,
"accessKey": null,
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "curl/7.79.1",
"user": null
},
"domainName": "9999999999.execute-api.ap-northeast-1.amazonaws.com",
"apiId": "9999999999"
},
"body": "{\"zzz\":123}",
"isBase64Encoded": false
}
- APIのパス (ステージ名を含む) は
requestContext.path
- HTTPメソッドは
httpMethod
- リクエスト元IPアドレスは
requestContext.identity.sourceIp
- リクエストヘッダは
headers
(※名前は小文字になっていることもあるが条件不明。同じ名前で複数の値が指定された場合は最後のものがセットされる。multiValueHeaders
ならば配列で個別に取得できるので、リクエストヘッダに同名のものを含む場合はそちらを使用すること) - リクエストボディは
body
- クエリパラメータは
queryStringParameters
(※同じ名前で複数の値が指定された場合はカンマ区切りでセットされるが、値自体にカンマが含まれる場合でもエスケープはされない。multiValueQueryStringParameters
ならば配列で個別に取得できるので、クエリストリングに同名のものを含む場合はそちらを使用すること) - パスパラメータは
pathParameters
- API Gatewayのリソースのパスは
resource
- API Gatewayのステージ名は
requestContext.stage
- API Gatewayのステージ変数は
stageVariables