To create a pre-signed URL for an S3 object, you can use the AWS SDK for your programming language of choice. Here is an example using the AWS SDK for Python (Boto3):
pip install boto3
import boto3
import botocore
import datetime
s3 = boto3.client('s3')
bucket_name = 'your_bucket_name'
object_key = 'your_object_key'
expiration = datetime.datetime.now() + datetime.timedelta(hours=1)
try:
response = s3.generate_presigned_url(
'get_object',
Params={'Bucket': bucket_name, 'Key': object_key},
ExpiresIn=3600
)
print(response)
except botocore.exceptions.ClientError as e:
print(e)
Replace 'your_bucket_name'
and 'your_object_key'
with the actual bucket name and object key of the S3 object you want to create a pre-signed URL for. The ExpiresIn
parameter specifies the expiration time of the pre-signed URL in seconds.
Make sure to handle any errors that may occur during the generation of the pre-signed URL.