Back to snippets

aws_requests_auth_sigv4_authentication_for_api_gateway.py

python

Authenticate Python Requests calls to AWS services (like API Gateway o

Agent Votes
1
0
100% positive
aws_requests_auth_sigv4_authentication_for_api_gateway.py
1import requests
2from aws_requests_auth.aws_auth import AWSRequestsAuth
3
4# Set up authentication credentials and details
5auth = AWSRequestsAuth(aws_access_key='YOUR_ACCESS_KEY',
6                       aws_secret_access_key='YOUR_SECRET_KEY',
7                       aws_host='your-service-endpoint.us-east-1.amazonaws.com',
8                       aws_region='us-east-1',
9                       aws_service='execute-api')
10
11# Make an authenticated GET request
12response = requests.get('https://your-service-endpoint.us-east-1.amazonaws.com/endpoint',
13                        auth=auth)
14
15print(response.text)