3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

API GatewayからLambdaFunction呼び出し時のHTTP GETパラメータ

Posted at

AWSのAPI Gatewayから、統合しているlambda関数を呼び出す際に、HTTP GETパラメータを渡す方法がわからなかったので調べてみた。

結論:
API GatewayからのGETパラメータをlambda関数から参照する際は、

queryStringParameters

を使う。

例)
https://xxxxxx.execute-api.ap-northeast-1.amazonaws.com/stage?foo=bar
のリクエストパラメータをlambdaで利用する場合、lambda関数(node.js)内では

event.queryStringParameters.foo

で参照できる。

ほか、API Gatewayで統合したLambda関数ではevent変数で以下の項目が利用できる模様。

{
    "resource": "/",
    "path": "/",
    "httpMethod": "GET",
    "headers": null,
    "queryStringParameters": {
        "foo": "bar"
    },
    "pathParameters": null,
    "stageVariables": null,
    "requestContext": {
        "accountId": "xxxxxxxxxxxx",
        "resourceId": "xxxxxxxxxxx",
        "stage": "test-invoke-stage",
        "requestId": "test-invoke-request",
        "identity": {
            "cognitoIdentityPoolId": null,
            "accountId": "xxxxxxxxxxxx",
            "cognitoIdentityId": null,
            "caller": "xxxxxxxxxxxxxxx",
            "apiKey": "test-invoke-api-key",
            "sourceIp": "test-invoke-source-ip",
            "accessKey": "xxxxxxxxxxxxxxxx",
            "cognitoAuthenticationType": null,
            "cognitoAuthenticationProvider": null,
            "userArn": "arn:aws:iam::xxxxxxx:user/xxxxxxxxx",
            "userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)",
            "user": "xxxxxxxxxxxxxxxxxx"
        },
        "resourcePath": "/",
        "httpMethod": "GET",
        "apiId": "xxxxxxxxx"
    },
    "body": null,
    "isBase64Encoded": false
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?