Aws:Lambda:GetValueFromPostedJSONByApiGateway
                APIGatewayでPOSTされたJSONから値を取得する
そういえばGETメソッドしか使ったことが無かったのでPOSTを触ってみた。
curlのリクエスト文
Windowsではこんな書式でPOSTするとJSONが送れるらしい。(-d オプション)
curl -X POST -d "{\"id\":\"0001\",\"value\":\"tokyo\"}" -H "Content-Type: application/json" https://XXXXX.execute-api.ap-northeast-1.amazonaws.com/test
Lambda関数サンプル
import json
  
def lambda_handler(event, context):
    jsn_dict = json.loads(event['body']) #一度[body]を辞書型に変換して
    return {
        'isBase64Encoded': False,
        'statusCode': 200,
        'headers': {},
        'body': json.dumps(jsn_dict['id']) #[キー]を指定して[値]を取得する
    }
Aws/Lambda/GetValueFromPostedJSONByApiGateway.txt · 最終更新:  by 127.0.0.1
                
                