API Gateway + Cognito Authorizer + Lambda関数でeventから得られるjsonのメモ

表題そのまま。

Cognito Authorizer差し込んだAPI Gateway経由でLambda関数を起動した時に、Lambda関数のeventから取得できるjsonのメモ。取得日は2022年7月11日。

パラメータ

APIはREST APIで、Webアプリ上からaxiosで叩いている。

usernameを拾うなら event.requestContext.authorizer.claims.cognito:username

{
   "resource":"/testapi",
   "path":"/testapi",
   "httpMethod":"GET",
   "headers":{
      "Accept":"application/json, text/plain, */*",
      "Authorization":"xxxx"
      "CloudFront-Forwarded-Proto":"https",
      "CloudFront-Is-Desktop-Viewer":"true",
      "CloudFront-Is-Mobile-Viewer":"false",
      "CloudFront-Is-SmartTV-Viewer":"false",
      "CloudFront-Is-Tablet-Viewer":"false",
      "CloudFront-Viewer-Country":"US",
      "Content-Type":"application/json",
      "Host":"example.com",
      "User-Agent":"axios/0.27.2",
      "Via":"1.1 xxxx.cloudfront.net (CloudFront)",
      "X-Amz-Cf-Id":"xxxx==",
      "X-Amzn-Trace-Id":"Root=1-xxxx-xxxx",
      "X-Forwarded-For":"xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx",
      "X-Forwarded-Port":"443",
      "X-Forwarded-Proto":"https",
      "X-Requested-With":"XMLHttpRequest"
   },
   "multiValueHeaders":{
      "Accept":[
         "application/json, text/plain, */*"
      ],
      "Authorization":[
         "xxxx"
      ],
      "CloudFront-Forwarded-Proto":[
         "https"
      ],
      "CloudFront-Is-Desktop-Viewer":[
         "true"
      ],
      "CloudFront-Is-Mobile-Viewer":[
         "false"
      ],
      "CloudFront-Is-SmartTV-Viewer":[
         "false"
      ],
      "CloudFront-Is-Tablet-Viewer":[
         "false"
      ],
      "CloudFront-Viewer-Country":[
         "US"
      ],
      "Content-Type":[
         "application/json"
      ],
      "Host":[
         "xxxx"
      ],
      "User-Agent":[
         "axios/0.27.2"
      ],
      "Via":[
         "1.1 xxxx.cloudfront.net (CloudFront)"
      ],
      "X-Amz-Cf-Id":[
         "xxxx=="
      ],
      "X-Amzn-Trace-Id":[
         "Root=1-xxxx-xxxx"
      ],
      "X-Forwarded-For":[
         "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx"
      ],
      "X-Forwarded-Port":[
         "443"
      ],
      "X-Forwarded-Proto":[
         "https"
      ],
      "X-Requested-With":[
         "XMLHttpRequest"
      ]
   },
   "queryStringParameters":"None",
   "multiValueQueryStringParameters":"None",
   "pathParameters":"None",
   "stageVariables":"None",
   "requestContext":{
      "resourceId":"xxxx",
      "authorizer":{
         "claims":{
            "sub":"xxxx-xxxx-xxxx-xxxx-xxxx",
            "aud":"xxxx",
            "event_id":"xxxx-xxxx-xxxx-xxxx-xxxx",
            "token_use":"id",
            "auth_time":"1657514663",
            "iss":"https://cognito-idp.ap-northeast-1.amazonaws.com/ap-northeast-1_xxxx",
            "cognito:username":"xxxx",
            "exp":"Mon Jul 11 05:44:22 UTC 2022",
            "iat":"Mon Jul 11 04:44:23 UTC 2022"
         }
      },
      "resourcePath":"/testapi",
      "httpMethod":"GET",
      "extendedRequestId":"xxxx=",
      "requestTime":"11/Jul/2022:04:44:26 +0000",
      "path":"/apitest",
      "accountId":"xxxx",
      "protocol":"HTTP/1.1",
      "stage":"dev",
      "domainPrefix":"hoge",
      "requestTimeEpoch":1657514666712,
      "requestId":"xxxx-xxxx-xxxx-xxxx-xxxx",
      "identity":{
         "cognitoIdentityPoolId":"None",
         "accountId":"None",
         "cognitoIdentityId":"None",
         "caller":"None",
         "sourceIp":"xxx.xxx.xx.xxx",
         "principalOrgId":"None",
         "accessKey":"None",
         "cognitoAuthenticationType":"None",
         "cognitoAuthenticationProvider":"None",
         "userArn":"None",
         "userAgent":"axios/0.27.2",
         "user":"None"
      },
      "domainName":"example.com",
      "apiId":"xxxx"
   },
   "body":"None",
   "isBase64Encoded":false
}

長い。

関連記事

スポンサーリンク

カテゴリーaws

コメントを残す

メールアドレスが公開されることはありません。