pip install -r ./requirements.txt
You can access data in Amazon S3 through a Multi-Region Access Point (MRAP) using the hostname of the Multi-Region Access Point.
The hostname for the request is <MRAP_alias>.accesspoint.s3-global.amazonaws.com
. For more details, see Multi-Region Access Point hostnames.
- If all you need is to get the headers with most common config.
- If you want to define boto3 session first and pass it to SigV4ASign.
- If you need high customization.
- Full example to get signed headers and make an API call.
- Full example to upload data/file though Amazon S3 Multi-Region Access Point (MRAP) into Amazon S3 bucket
If all you need is to get the headers with most common config.
from sigv4a_sign import SigV4ASign
service = 's3'
region = '*'
method = 'GET'
url = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>'
headers = SigV4ASign().get_headers_basic(service, region, method, url)
print(headers)
If you want to define boto3 session first and pass it to SigV4ASign
.
from sigv4a_sign import SigV4ASign
service = 's3'
region = '*'
method = 'GET'
url = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>'
session = boto3.Session(aws_access_key_id='<aws_access_key_id>', aws_secret_access_key='<aws_secret_access_key>')
# class from ./sigv4a_sign.py
headers = SigV4ASign(session).get_headers_basic(service, region, method, url)
print(headers)
If you need high customization.
from sigv4a_sign import SigV4ASign
service = 's3'
region = '*'
aws_request_config = {
'method': 'GET',
'url': 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>',
}
# class from ./sigv4a_sign.py
headers = SigV4ASign().get_headers(service, region, aws_request_config)
print(headers)
Full example to get signed headers and make an API call.
from sigv4a_sign import SigV4ASign
# pip install requests
import requests
service = 's3'
region = '*'
method = 'GET'
url = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>'
headers = SigV4ASign().get_headers_basic(service, region, method, url)
r = requests.get(url, headers=headers)
print(f'status_code: {r.status_code} \nobject text: {r.text}')
Full example to upload data/file through MRAP into an S3 bucket.
from sigv4a_sign import SigV4ASign
# pip install requests
import requests
service = 's3'
region = '*'
method = 'PUT'
url = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>'
data = 'hello world'
aws_request_config = {
'method': 'PUT',
'url': url,
'data': data
}
headers = SigV4ASign().get_headers(service, region, aws_request_config)
r = requests.put(url, data=data, headers=headers)
print(f'status_code: {r.status_code}')