Is it possible to create CloudFront signed URL with some time limits for one particular file located in S3 file in Glue Job using python3+?
I saw it’s possible to do it in Lambda, but couldn’t find anything in docs for Python and especially Glue job. Can anyone give some tips?
def load_private_key(key_path):
with open(key_path, 'rb') as key_file:
return serialization.load_pem_private_key(
key_file.read(),
password=None,
backend=default_backend()
)
def rsa_signer(message):
private_key = load_private_key('private_key.pem')
signature = private_key.sign(
message,
padding.PSS(
mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH
),
hashes.SHA256()
)
return signature
def get_signer_url(url):
if key_pair_id:
cf_signer = CloudFrontSigner(key_pair_id, rsa_signer)
current_date = datetime.now()
retention_period = current_date + timedelta(days=93)
signed_url = cf_signer.generate_presigned_url(url, date_less_than=retention_period)
print(signed_url)
return signed_url
url = "https://distr.cloudfront.net/path/to/resource"
signed_url = get_signer_url(url)
Getting errors like module ‘cryptography.hazmat.primitives.padding’ has no attribute ‘PSS’, or ‘hashes’ not found, etc. Although I am using newest version. I am pretty new to all of these, and wanted to get some tips or advices.