You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
785 B
Python

2 years ago
import boto3
from botocore.exceptions import ClientError
2 years ago
from yt_dlp_stream_to_s3.config import (
AWS_ENDPOINT_URL,
AWS_SECRET_ACCESS_KEY,
AWS_ACCESS_KEY_ID,
)
from yt_dlp_stream_to_s3.errors import YtDlpStreamToS3ConnectionError
2 years ago
try:
s3 = boto3.client(
"s3",
endpoint_url=AWS_ENDPOINT_URL,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
aws_access_key_id=AWS_ACCESS_KEY_ID,
)
2 years ago
except Exception:
raise YtDlpStreamToS3ConnectionError(
f"Could not connect to S3 service {AWS_ENDPOINT_URL}"
)
def create_presigned_url(bucket_name, object_name, expiration=3600):
return s3.generate_presigned_url(
"get_object",
Params={"Bucket": bucket_name, "Key": object_name},
ExpiresIn=expiration,
)