AWS Lambdaの`event`を確認
API GatewayのGETメソッドでAWS Lambda関数を統合している場合に、eventで受け取る値を確認しました。
以下のような#AWS Lambdaを実行しました。
export const handler = async (event) => {
console.log(JSON.stringify(event));
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
API Gatewayからテスト
実行結果
{
"resource": "/",
"path": "/",
"httpMethod": "GET",
"headers": {
"header2": "value2",
"header1": "value1"
},
"multiValueHeaders": {
"header2": [
"value2"
],
"header1": [
"value1"
]
},
"queryStringParameters": {
"param1": "value1",
"param2": "value2"
},
"multiValueQueryStringParameters": {
"param1": [
"value1"
],
"param2": [
"value2"
]
},
"pathParameters": null,
"stageVariables": null,
"requestContext": {
"resourceId": "zbkgq2150i",
"resourcePath": "/",
"httpMethod": "GET",
"extendedRequestId": "Vo6HgFCYoAMFchg=",
"requestTime": "03/Apr/2024:07:50:07 +0000",
"path": "/",
"accountId": "123456789123",
"protocol": "HTTP/1.1",
"stage": "test-invoke-stage",
"domainPrefix": "testPrefix",
"requestTimeEpoch": 1712130607770,
"requestId": "05f4bb29-e600-4968-aeb8-12e062caa698",
"identity": {
"cognitoIdentityPoolId": null,
"cognitoIdentityId": null,
"apiKey": "test-invoke-api-key",
"principalOrgId": null,
"cognitoAuthenticationType": null,
"userArn": "arn:aws:iam::123456789123:user/xxx-xxx",
"apiKeyId": "test-invoke-api-key-id",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
"accountId": "123456789123",
"caller": "AIDAQGIBVCFDQW6HXLIGK",
"sourceIp": "test-invoke-source-ip",
"accessKey": "ASIAQGIBVCFDRFRRWRO5",
"cognitoAuthenticationProvider": null,
"user": "AIDAQGIBVCFDQW6HXLIGK"
},
"domainName": "testPrefix.testDomainName",
"apiId": "vjs9lsoti0"
},
"body": null,
"isBase64Encoded": false
}
自分用のメモでした。