[PYTHON] A note that connects to Lambda via AWS API Gateway (HTTP API) to process POST data

Don't forget to hurry.

If you pass the JSON encoded version when throwing it to the API, you can get the JSON after Base64 decoding. In that case, JSON parsing processing is performed instead of parsing the request query.

import json
import base64
import urllib.parse

def lambda_handler(event, context):

    #Decode because the POST parameter is BASE64 encoded
    decoded_body = base64.b64decode(event['body']).decode()
    #Convert POST parameters to dict type
    post_params = urllib.parse.parse_qs(decoded_body)

    result = {}
    result['message'] = 'Response from lambda'

    #See POSTed data(Note that it is an array)
    result['name'] = post_params['name'][0]
    result['email'] = post_params['email'][0]

    return {
        'statusCode': 200,
        'body': json.dumps(result)

Recommended Posts

A note that connects to Lambda via AWS API Gateway (HTTP API) to process POST data
Pass Cognito Id to Lambda via API Gateway
AWS Amplify + API Gateway + Lambda + Python returns a normal response
[AWS] Create API with API Gateway + Lambda
Send images taken with ESP32-WROOM-32 to AWS (API Gateway → Lambda → S3)
[Python] I wrote a REST API using AWS API Gateway and Lambda.
How to create a serverless machine learning API with AWS Lambda
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
Regularly post to Twitter using AWS lambda!
Try implementing a Cisco Spark bot with AWS Lambda + Amazon API Gateway (Python)
[AWS SAM] Create API with DynamoDB + Lambda + API Gateway
LINE BOT with Python + AWS Lambda + API Gateway
[AWS] Try tracing API Gateway + Lambda with X-Ray
Amazon API Gateway and AWS Lambda Python version
How to post a ticket from the Shogun API