Skip to content

Latest commit

 

History

History

python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Installing python dependencies

pip install -r ./requirements.txt

Making requests using a Multi-Region Access Point (MRAP) in Amazon S3

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.

Examples Overview

Examples

Example 1

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)

Example 2

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)

Example 3

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)

Example 4

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}')

Example 5

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}')