Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

API GatewayからLambdaに渡される入力パラメタの形式

{
    "body-json": {},
    "params": {
        "path": {},
        "querystring": {
            "parameter1": "value1",
            "parameter2": "value2"
        },
        "header": {}
    },
    "stage-variables": {},
    "context": {
        "account-id": "999999999999",
        "api-id": "xxxxxxxxxx",
        "api-key": "xxx-xxx-api-key",
        "authorizer-principal-id": "",
        "caller": "XXXXXXXXXXXXXXXXXXXXX",
        "cognito-authentication-provider": "",
        "cognito-authentication-type": "",
        "cognito-identity-id": "",
        "cognito-identity-pool-id": "",
        "http-method": "GET",
        "stage": "xxx-xxx-stage",
        "source-ip": "xxx-xxx-source-ip",
        "user": "XXXXXXXXXXXXXXXXXXXXX",
        "user-agent": "aws-internal/3 aws-sdk-java/1.12.201 Linux/5.4.181-109.354.amzn2int.x86_64 OpenJDK_64-Bit_Server_VM/25.322-b06 java/1.8.0_322 vendor/Oracle_Corporation cfg/retry-mode/standard",
        "user-arn": "arn:aws:iam::999999999999:user/your-user-id",
        "request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "resource-id": "xxxxxx",
        "resource-path": "/path-to-resource"
    }
}
  • API GatewayでメソッドのオーソライザにLambda関数を指定した場合には、プロキシ統合の場合と同じ形式でLambda関数へパラメタが渡される。マッピングテンプレートは使用できない。

呼出元に返したいJSONの形式があらかじめ決められてるとか、JSONでなくてXMLでレスポンスを返したいとかの場合、けっきょくプロキシ統合は使えなくなる。なので、プロキシ統合の場合と同じパラメタの形式になるマッピングテンプレートがあればいいんだけど……