Created
August 19, 2023 08:51
-
-
Save naveenrobo/54d86080199fbc73120ff4a339bb837a to your computer and use it in GitHub Desktop.
Generate S3 persigned url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
from botocore.client import Config | |
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
AWS_ACCESS_KEY = "" | |
AWS_SECRET_KEY = "" | |
BUCKET_NAME = "" | |
@app.route('/get_presigned_url', methods=['POST']) | |
def get_presigned_url(): | |
object_key = request.json.get('object_key') | |
expires_in = 36000 # URL expiration time in seconds | |
s3_client = boto3.client( | |
's3', aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY, region_name='ap-southeast-1', config=Config(signature_version='s3v4')) | |
presigned_url = s3_client.generate_presigned_url( | |
'put_object', | |
Params={'Bucket': BUCKET_NAME, 'Key': object_key}, | |
ExpiresIn=expires_in, | |
HttpMethod='PUT' | |
) | |
return jsonify({'presigned_url': presigned_url}) | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment