I tried to call API Gateway by sending a request from a local python program. You can limit the call because you can limit the call by setting the API Key. I think it would be easier to create a screen for processing calls and restrict access to it ...
When creating a Lambda function and setting APIGateWay as a trigger, specify REST API as ↓ to set security to ʻAPI Key`.

For APIGateWay, change ʻAPI key requirement from method requesttotrue`.

Deploy API from action
import requests
import traceback
if  __name__ == "__main__":
    try:
        
        #API Key is the API Key confirmed by API Gateway
        headers = {'x-api-key': 'APIKey'}
        #The part of xxxxxxxx is the value of each API/The part of test2 specifies the resource name here greet
        url='https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/default/test2'
        #Pattern of success
        rSucess = requests.get(url, headers=headers)
        print(rSucess.status_code)
        print(rSucess.content)
        #Failure pattern
        rFail = requests.get(url)
        print(rFail.status_code)
        print(rFail.content)
    except :
        print(traceback.format_exc())
200
b'"Hello from Lambda!"'
403
b'{"message":"Forbidden"}'
        Recommended Posts