Ying Ting Loo
11/22/2023, 10:07 AMasync def download_s3_obj(key: str, aiohttp_session: client.ClientSession, s3_client, bucket, local_path):
request_url = s3_client.generate_presigned_url("get_object", {"Bucket": bucket, "Key": key})
async with aiohttp_session.get(URL(request_url, encoded=True)) as response:
async with concurrency("s3-download", occupy=10):
file_path = local_path + "/" + key
with open(file_path, "wb") as file:
file.write(await response.read())
return file_path
Bianca Hoch
11/22/2023, 10:02 PMYing Ting Loo
11/24/2023, 2:07 AM@task(tags=["download-s3"])
async def download_s3(video_name: str, bucket_name: str, local_path: str, aws_key, aws_secret):
s3_client = boto3.client(
"s3",
aws_access_key_id=aws_key,
aws_secret_access_key=aws_secret,
config=Config(signature_version="s3v4", region_name="eu-central-1"),
)
aio_session = client.ClientSession()
filepath_list = await download_s3_obj(video_name, aio_session, s3_client, bucket_name, local_path)
await aio_session.close()
return filepath_list
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by