今更

HTTP API (V2) はこちら↓


リソース /{param1}/{param2}/hello のメソッド ANY でLambda関数を呼び出せるようにし、ステージ v1 を作成し、以下の curl コマンドで叩いたときのイベントの中身

コマンド
curl -X POST -H 'Content-Type: application/json' -H 'X-Foo: bar' -d '{"aaa":123}' 'https://9999999999.execute-api.ap-northeast-1.amazonaws.com/v1/xxx/yyy/hello?hoge=hg&piyo=py'
イベントの中身
{
  "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-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-Foo": ["bar"],
    "X-Forwarded-For": ["1.1.1.1"],
    "X-Forwarded-Port": ["443"],
    "X-Forwarded-Proto": ["https"]
  },
  "queryStringParameters": {
    "hoge": "hg",
    "piyo": "py"
  },
  "multiValueQueryStringParameters": {
    "hoge": ["hg"],
    "piyo": ["py"]
  },
  "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": "{\"aaa\":123}",
  "isBase64Encoded": false
}
  • APIのパス (ステージ名を含む) は requestContext.path
  • HTTPメソッドは httpMethod
  • リクエスト元IPアドレスは requestContext.identity.sourceIp
  • リクエストヘッダは headers
  • リクエストボディは body
  • クエリパラメータは queryStringParameters
  • パスパラメータは pathParameters
  • API Gatewayのリソースのパスは resource
  • API Gatewayのステージ名は requestContext.stage
  • API Gatewayのステージ変数は stageVariables