Created
September 4, 2017 15:39
-
-
Save ashee/2cf0eff290ff07ed6a23a208823c4563 to your computer and use it in GitHub Desktop.
AWS signature 4
This file contains hidden or 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
#!/usr/bin/env python | |
import os | |
import ConfigParser | |
import logging | |
import requests | |
from requests_aws4auth import AWS4Auth | |
# These two lines enable debugging at httplib level (requests->urllib3->http.client) | |
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA. | |
# The only thing missing will be the response.body which is not logged. | |
try: | |
import http.client as http_client | |
except ImportError: | |
# Python 2 | |
import httplib as http_client | |
http_client.HTTPConnection.debuglevel = 1 | |
# You must initialize logging, otherwise you'll not see debug output. | |
logging.basicConfig() | |
logging.getLogger().setLevel(logging.DEBUG) | |
requests_log = logging.getLogger("requests.packages.urllib3") | |
requests_log.setLevel(logging.DEBUG) | |
requests_log.propagate = True | |
config = ConfigParser.ConfigParser() | |
config.read(os.path.expanduser('~/.aws/credentials')) | |
auth = AWS4Auth( | |
config.get('default','aws_access_key_id'), | |
config.get('default','aws_secret_access_key'), | |
'us-west-2', 'es') | |
endpoint = 'https://your_aws_resource.us-west-2.es.amazonaws.com' | |
response = requests.get(endpoint, auth=auth) | |
print response.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment