Access AWS API Gateway with IAM roles from Python
<p>I have an AWS API Gateway that I would like to secure using <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/permissions.html" rel="nofollow" title="IAM Roles">IAM Roles</a> .</p>

<p>I am looking for a package to help me accessing it using Python. I am trying to avoid implementing the entire <a href="http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html" rel="nofollow" title="Version 4 Signing Process">Version 4 Signing Process</a>. I am sure there must be some library I can use.</p>

<p>I looked into <a href="https://github.com/DavidMuller/aws-requests-auth" rel="nofollow" title="aws-requests-auth">aws-requests-auth</a>  but it requires a "aws_service" to generate the signature. I looked also to boto3 but I am not able to find any way to just add authentication headers to a general request.</p>

<p>You can use <a href="https://github.com/DavidMuller/aws-requests-auth" rel="nofollow" title="aws-requests-auth">aws-requests-auth</a> to generate the signature for your request to API Gateway with <strong>execute-api</strong> as the service name. </p>

<pre><code>import requests
from aws_requests_auth.aws_auth import AWSRequestsAuth

auth = AWSRequestsAuth(aws_access_key='YOURKEY',
                       aws_secret_access_key='YOURSECRET',
                       aws_host='restapiid.execute-api.us-east-1.amazonaws.com',
                       aws_region='us-east-1',
                       aws_service='execute-api')

headers = {'params': 'ABC'}
response = requests.get('https://restapiid.execute-api.us-east-1.amazonaws.com/stage/resource_path',
                        auth=auth, headers=headers)
</code></pre>

python amazon-iam aws-api-gateway