Last active
April 27, 2023 19:44
-
-
Save pkage/9a58b838275ae61cc41736f8f98f74aa to your computer and use it in GitHub Desktop.
RequesterPays presigned URL failure with AWS4-HMAC-SHA256
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
from botocore.client import Config | |
client = boto3.client( | |
's3', | |
'us-west-2', | |
# replace with your credentials | |
aws_access_key_id='AWS_ACCESS_KEY_ID', | |
aws_secret_access_key='AWS_SECRET_ACCESS_KEY', | |
# !!! comment/uncomment this line to fail the request | |
config=Config(signature_version='s3v4') | |
) | |
# example RequesterPays bucket in us-west-2 | |
bucket = 'usgs-landsat' | |
key = 'collection02/level-1/standard/etm/2022/163/033/LE07_L1TP_163033_20220506_20220901_02_T1/LE07_L1TP_163033_20220506_20220901_02_T1_B2.TIF' | |
# should return a valid URL | |
asset_link = client.generate_presigned_url( | |
ClientMethod='get_object', | |
Params={ | |
'Bucket': bucket, | |
'Key': key, | |
'RequestPayer': 'requester' | |
}, | |
ExpiresIn=(60 * 60 * 24) # 24h | |
) | |
# if signature_version is s3v4 or v4, this will not be a valid URL | |
print(f'signed url: {asset_link}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. | |
[[package]] | |
name = "boto3" | |
version = "1.26.121" | |
description = "The AWS SDK for Python" | |
category = "main" | |
optional = false | |
python-versions = ">= 3.7" | |
files = [ | |
{file = "boto3-1.26.121-py3-none-any.whl", hash = "sha256:827342a6b94b18daed937b0743f43958d1d3b9d5423ec995c19ae74b82cd54bc"}, | |
{file = "boto3-1.26.121.tar.gz", hash = "sha256:f87d694c351eba1dfd19b5bef5892a1047e7adb09c57c2c00049de209a8ab55d"}, | |
] | |
[package.dependencies] | |
botocore = ">=1.29.121,<1.30.0" | |
jmespath = ">=0.7.1,<2.0.0" | |
s3transfer = ">=0.6.0,<0.7.0" | |
[package.extras] | |
crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] | |
[[package]] | |
name = "botocore" | |
version = "1.29.122" | |
description = "Low-level, data-driven core of boto 3." | |
category = "main" | |
optional = false | |
python-versions = ">= 3.7" | |
files = [ | |
{file = "botocore-1.29.122-py3-none-any.whl", hash = "sha256:c3b41078d235761b9c5dc22f534a76952622ef96787b96bbd10242ec4d73f2a5"}, | |
] | |
[package.dependencies] | |
jmespath = ">=0.7.1,<2.0.0" | |
python-dateutil = ">=2.1,<3.0.0" | |
urllib3 = ">=1.25.4,<1.27" | |
[package.extras] | |
crt = ["awscrt (==0.16.9)"] | |
[[package]] | |
name = "jmespath" | |
version = "1.0.1" | |
description = "JSON Matching Expressions" | |
category = "main" | |
optional = false | |
python-versions = ">=3.7" | |
files = [ | |
{file = "jmespath-1.0.1-py3-none-any.whl", hash = "sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980"}, | |
{file = "jmespath-1.0.1.tar.gz", hash = "sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe"}, | |
] | |
[[package]] | |
name = "python-dateutil" | |
version = "2.8.2" | |
description = "Extensions to the standard Python datetime module" | |
category = "main" | |
optional = false | |
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" | |
files = [ | |
{file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, | |
{file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, | |
] | |
[package.dependencies] | |
six = ">=1.5" | |
[[package]] | |
name = "s3transfer" | |
version = "0.6.0" | |
description = "An Amazon S3 Transfer Manager" | |
category = "main" | |
optional = false | |
python-versions = ">= 3.7" | |
files = [ | |
{file = "s3transfer-0.6.0-py3-none-any.whl", hash = "sha256:06176b74f3a15f61f1b4f25a1fc29a4429040b7647133a463da8fa5bd28d5ecd"}, | |
{file = "s3transfer-0.6.0.tar.gz", hash = "sha256:2ed07d3866f523cc561bf4a00fc5535827981b117dd7876f036b0c1aca42c947"}, | |
] | |
[package.dependencies] | |
botocore = ">=1.12.36,<2.0a.0" | |
[package.extras] | |
crt = ["botocore[crt] (>=1.20.29,<2.0a.0)"] | |
[[package]] | |
name = "six" | |
version = "1.16.0" | |
description = "Python 2 and 3 compatibility utilities" | |
category = "main" | |
optional = false | |
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" | |
files = [ | |
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, | |
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, | |
] | |
[[package]] | |
name = "urllib3" | |
version = "1.26.15" | |
description = "HTTP library with thread-safe connection pooling, file post, and more." | |
category = "main" | |
optional = false | |
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" | |
files = [ | |
{file = "urllib3-1.26.15-py2.py3-none-any.whl", hash = "sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42"}, | |
{file = "urllib3-1.26.15.tar.gz", hash = "sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305"}, | |
] | |
[package.extras] | |
brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] | |
secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] | |
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] | |
[metadata] | |
lock-version = "2.0" | |
python-versions = "^3.10" | |
content-hash = "12f4ca016178492e790295d85f13aa82f28ced5978bcc39f52585f53d4b68935" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tool.poetry] | |
name = "sscce" | |
version = "0.1.0" | |
description = "" | |
authors = ["Patrick Kage <patrick.r.kage@gmail.com>"] | |
readme = "README.md" | |
[tool.poetry.dependencies] | |
python = "^3.10" | |
boto3 = "^1.26.121" | |
[build-system] | |
requires = ["poetry-core"] | |
build-backend = "poetry.core.masonry.api" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment