Making API Call
-
Install python dependencies
pip install aws-requests-auth -
Import
from aws_requests_auth.aws_auth import AWSRequestsAuth from aws_requests_auth.boto_utils import BotoAWSRequestsAuth import json import requests -
Authenticate
-
With AWS Credentials configured
auth = BotoAWSRequestsAuth( aws_region=api_region, aws_host=api_endpoint, aws_service='execute-api' ) -
If you are using IAM User Credentials
auth = AWSRequestsAuth( aws_access_key=access_key, aws_secret_access_key=secret_key, aws_region=api_region, aws_host=api_endpoint, aws_service='execute-api' )
Note
aws_host
- Refers to API Endpoint
- Suppose you have an API
https://test.myapi.com/get-info, aws_host will betest.myapi.com.
-
-
Make API Call
response = requests.get( my_api, auth=auth ) response_dict = json.loads(response.text)Note
- Here
my_apiwill be the api to which we would like to make call. - In our example, it will be
https://test.myapi.com/get-info
- Here