LoginSignup
13
11

More than 5 years have passed since last update.

aws LambdaとAPI Gatewayではまったところ

Posted at

やりたいこと

  • API GatewayとLambdaを使ってパラメータの値を返すAPIを作りたい
  • 以上

はまったところ

  • Lambdaのテストは通ってるのにAPI Gatewayを通すと502
  • パラメータが拾えないんですけど

Lambdaのテストは通ってるのにAPI Gatewayを通すと502

ドキュメント読めという話なんですが、最低以下のフォーマットを満たしていないといけないようです。

{
    "statusCode": httpStatusCode,
    "body": "..."
}

パラメータが拾えないんですけど

結論から言うとeventの中のqueryStringParametersにパラメータが入ってます。
ググると出てくるような
これは以下を実行すると確認できます。

Python

import json

print('Loading function')


def lambda_handler(event, context):
    return {
        "isBase64Encoded": "true",
        "statusCode": 200,
        "headers": {},
        "body": json.dumps(event)
    }

Nodejs

'use strict';

console.log('Loading function');

exports.handler = (event, context, callback) => {
    callback(null, {
        "statusCode": 200,
        "body": JSON.stringify(event)
    });
};
13
11
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
13
11