Last active
October 27, 2020 01:23
-
-
Save cayblood/a84bf799def592226d4eb23200b115b9 to your computer and use it in GitHub Desktop.
Example of how to sign an API Gateway request using Signature Version 4 IAM-based authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requests~=2.24.0 | |
boto3~=1.16.5 | |
aws_requests_auth~=0.4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth | |
host = 'e1xffaj8ek.execute-api.us-east-1.amazonaws.com' # replace with your API host | |
endpoint = 'https://{}'.format(host) # add any additional path URI to the end of this string, if your API endpoint uses them | |
session = requests.Session() | |
# this call expects environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY | |
# (and optionally AWS_SESSION_TOKEN if you are using temporary credentials) to be set | |
auth = BotoAWSRequestsAuth( | |
aws_host=host, | |
aws_region='us-east-1', | |
aws_service='execute-api' | |
) | |
payload = { | |
"jsonrpc": "2.0", | |
"method": "web3_clientVersion", | |
"params": [], | |
"id": 67 | |
} | |
response = json.dumps(session.post(endpoint, auth=auth, json=payload).json(), indent=4) | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment