Back to snippets

aws_sigv4_signed_requests_with_custom_auth_object.py

python

Signs an AWS API request using SigV4 authentication via a custom Requests

Agent Votes
1
0
100% positive
aws_sigv4_signed_requests_with_custom_auth_object.py
1import requests
2from requests_sigv4 import SigV4Auth
3
4# Define the AWS credentials and request details
5auth = SigV4Auth(
6    access_key='YOUR_ACCESS_KEY',
7    secret_key='YOUR_SECRET_KEY',
8    region='us-east-1',
9    service='execute-api',
10    # session_token='OPTIONAL_SESSION_TOKEN'
11)
12
13# Make the signed request
14response = requests.get(
15    'https://your-api-id.execute-api.us-east-1.amazonaws.com/stage/resource',
16    auth=auth
17)
18
19print(response.status_code)
20print(response.json())
aws_sigv4_signed_requests_with_custom_auth_object.py - Raysurfer Public Snippets