以前から気になっていたが、APIGatewayをトリガーにLambda関数を動かしているのにeventが取得できなく・・・調べたところ
リクエストのマッピングテンプレートを使わない場合、[Lambdaプロキシ統合の使用]にチェックしないとeventが空になってしまうんですね。
・APIGatewayはエンドポイントをリージョンとしたシンプルなものAPIGateway/Lambda関数の呼び出し辺りを参考に作成
・Lambda関数は下記のコードで、APIGatewayからのeventをそのままブラウザに表示しています。
import json def lambda_handler(event, context): jsn_str = json.dumps(event, ensure_ascii=False, indent=2) return { 'isBase64Encoded': False, 'statusCode': 200, 'headers': {}, 'body': jsn_str }
※Lambda関数選択時に、[Lambdaプロキシ統合の使用]をチェックしません。
ブラウザへのレスポンス
{"isBase64Encoded": false, "statusCode": 200, "headers": {}, "body": "{}"}
※Lambda関数選択時に、[Lambdaプロキシ統合の使用]をチェックします。
[https://XXXXX.execute-api.ap-northeast-1.amazonaws.com/test]の末尾に[?id=0001&value=tokyo]をつけてリクエストしてみる。
[queryStringParameters]と[multiValueQueryStringParameters]が追加されていました。
"queryStringParameters": { "id": "0001", "value": "tokyo" }, "multiValueQueryStringParameters": { "id": [ "0001" ], "value": [ "tokyo" ] }
{ "resource": "/", "path": "/", "httpMethod": "GET", "headers": { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-encoding": "gzip, deflate, br", "accept-language": "ja", "cache-control": "max-age=0", "Host": "{APIGWのID}.execute-api.ap-northeast-1.amazonaws.com", "referer": "https://ap-northeast-1.console.aws.amazon.com/", "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"", "sec-ch-ua-mobile": "?0", "sec-fetch-dest": "document", "sec-fetch-mode": "navigate", "sec-fetch-site": "cross-site", "sec-fetch-user": "?1", "upgrade-insecure-requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "X-Amzn-Trace-Id": "Root=1-60aa083e-2598a84640ebc8667f9f08ee", "X-Forwarded-For": "{接続元IPアドレス}", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, "multiValueHeaders": { "accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ], "accept-encoding": [ "gzip, deflate, br" ], "accept-language": [ "ja" ], "cache-control": [ "max-age=0" ], "Host": [ "{APIGWのID}.execute-api.ap-northeast-1.amazonaws.com" ], "referer": [ "https://ap-northeast-1.console.aws.amazon.com/" ], "sec-ch-ua": [ "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"" ], "sec-ch-ua-mobile": [ "?0" ], "sec-fetch-dest": [ "document" ], "sec-fetch-mode": [ "navigate" ], "sec-fetch-site": [ "cross-site" ], "sec-fetch-user": [ "?1" ], "upgrade-insecure-requests": [ "1" ], "User-Agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" ], "X-Amzn-Trace-Id": [ "Root=1-60aa083e-2598a84640ebc8667f9f08ee" ], "X-Forwarded-For": [ "{接続元IPアドレス}" ], "X-Forwarded-Port": [ "443" ], "X-Forwarded-Proto": [ "https" ] }, "queryStringParameters": null, "multiValueQueryStringParameters": null, "pathParameters": null, "stageVariables": null, "requestContext": { "resourceId": "sk5324ywjb", "resourcePath": "/", "httpMethod": "GET", "extendedRequestId": "fxY5tHljtjMFq3w=", "requestTime": "23/May/2021:07:46:06 +0000", "path": "/test", "accountId": "{アカウントID}", "protocol": "HTTP/1.1", "stage": "test", "domainPrefix": "{APIGWのID}", "requestTimeEpoch": 1621755966012, "requestId": "e00c2936-dca1-4084-a574-a7c8b7fb4b21", "identity": { "cognitoIdentityPoolId": null, "accountId": null, "cognitoIdentityId": null, "caller": null, "sourceIp": "{接続元IPアドレス}", "principalOrgId": null, "accessKey": null, "cognitoAuthenticationType": null, "cognitoAuthenticationProvider": null, "userArn": null, "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "user": null }, "domainName": "{APIGWのID}.execute-api.ap-northeast-1.amazonaws.com", "apiId": "{APIGWのID}" }, "body": null, "isBase64Encoded": false }