Call APIGateWay with APIKey in python requests

Overview

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 ...

API GateWay settings

Python program to call

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

Call APIGateWay with APIKey in python requests
Retry with python requests
[Python] Dealing with multiple call errors in ray.init
Scraping with selenium in Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Debugging with pdb in Python
Working with sounds in Python
Scraping with Selenium in Python
Tweet with image in Python
Combined with permutations in Python
Call the API with python3.
Dynamically call methods in Python
Install CaboCha in Ubuntu environment and call it with Python.
Number recognition in images with Python
Testing with random numbers in Python
GOTO in Python with Sublime Text 3
Scraping with Selenium in Python (Basic)
CSS parsing with cssutils in Python
[Python] POST wav files with requests [POST]
Get the weather with Python requests
Get the weather with Python requests 2
Open UTF-8 with BOM in Python
Use Python in pyenv with NeoVim
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
Password generation in texto with python
Use OpenCV with Python 3 in Window
Until dealing with python in Atom
Send multipart / form-data with python requests
Get started with Python in Blender
Working with DICOM images in Python
Write documentation in Sphinx with Python Livereload
Get additional data in LDAP with python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
Stress Test with Locust written in Python
Python3> in keyword> True with partial match?
Exclusive control with lock file in Python
Device monitoring with On-box Python in IOS-XE
Try working with binary data in Python
Draw Nozomi Sasaki in Excel with python
Tips for dealing with binaries in Python
Display Python 3 in the browser with MAMP
Page cache in Python + Flask with Flask-Caching
Post Test 3 (Working with PosgreSQL in Python)
How to work with BigQuery in Python
Playing card class in Python (with comparison)
Dealing with "years and months" in Python
Process multiple lists with for in Python
Replace non-ASCII with regular expressions in Python
Connect with mysql.connector with ssh tunnel in Python 3.7
One liner webServer (with CGI) in python
Call sudo in Python and autofill password
Easy image processing in Python with Pillow
To work with timestamp stations in Python
Read text in images with python OCR
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
Create a record with attachments in KINTONE using the Python requests module
Quadtree in Python --2
CURL in python