Mitch
09/12/2024, 6:03 PMMarvin
09/12/2024, 6:04 PMpython
from prefect import flow, task
import hashlib
import boto3
@task
def upload_to_s3(bucket_name, key, data, hash_alg='md5'):
s3 = boto3.client('s3')
# Compute hash
if hash_alg == 'sha256':
hash = hashlib.sha256(data).hexdigest()
else:
hash = hashlib.md5(data).hexdigest()
s3.put_object(Bucket=bucket_name, Key=key, Body=data, Metadata={'hash': hash})
@flow
def my_flow():
data = b'Your data'
upload_to_s3('my-bucket', 'my-key', data, hash_alg='sha256')
my_flow()
This way you can control the hash function used for your uploads.
Feel free to check out more details in the Prefect AWS S3 integration docs:
Prefect AWS S3 IntegrationMitch
09/12/2024, 6:05 PMMarvin
09/12/2024, 6:06 PMput_object
method within a Prefect task:
python
from prefect import flow, task
import boto3
@task
def upload_to_s3(bucket_name, key, data, checksum_algorithm='sha256'):
s3_client = boto3.client('s3')
s3_client.put_object(Bucket=bucket_name, Key=key, Body=data, ChecksumAlgorithm=checksum_algorithm.upper())
@flow
def my_flow():
data = b'Your data content'
upload_to_s3('my-bucket', 'my-key', data, checksum_algorithm='sha256')
my_flow()
This example shows how to use the ChecksumAlgorithm
parameter to specify the hash function for S3 uploads. This way, you can leverage Boto3's capabilities alongside Prefect.
For more details on the Boto3 put_object
method, you can refer to Boto3 S3 Documentation.
If you need deeper Prefect-specific integration features, you might want to follow the latest updates or raise a feature request in the Prefect GitHub repository.
Links for reference:
- Prefect AWS S3 Integration
- Boto3 S3 Client put_object
If you have other specifics in mind or run into issues, feel free to ask!