A note that calls the API using python's ʻurllib.request` module.
lambda should return the received ʻevent`.
import json
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': event
}
API Gateway provides various methods (GET, POST, PUT).
true
.Execute [Deploy API] and get the URI. (If you update something with API Gateway, deploy it every time! It will not be reflected unless you do it. ← I'm really into this.)
Select [Create] from [Usage Plan], select the API stage, set the rate burst quota, and create the API key.
import json
import urllib.request, urllib.error
request_url = "https://xxxx.execute-api.ap-northeast-1.amazonaws.com/stage"
api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
def lambda_handler(event, context):
headers = {'x-api-key': api_key, "Content-Type":"application/json"}
request_json = {
"key":"val"
}
req = urllib.request.Request(url=request_url, method="GET", headers=headers, data=json.dumps(request_json).encode())
with urllib.request.urlopen(req) as res:
body = res.read().decode()
return json.loads(body)
Corrected the following https://qiita.com/j_tamura/items/5a22b102a58d1fa93a78
Recommended Posts