- Newest
- Most votes
- Most comments
Yes, you can use presigned URLs with AWS Elemental MediaConvert, but with some important considerations.
AWS Elemental MediaConvert typically works with S3 destinations where you specify the S3 bucket path for your output files. The service has specific settings associated with S3 destinations, including options for access control, encryption, and storage class.
For your use case of using a presigned PUT URL instead of a direct S3 path, this isn't directly supported as a built-in feature of MediaConvert. MediaConvert is designed to work with S3 buckets as destinations where it has permissions to write the output files.
However, you could implement a workflow where:
- MediaConvert outputs to an S3 bucket
- A Lambda function is triggered by the completion of the MediaConvert job
- The Lambda function generates presigned URLs for the output files
- Your application uses these presigned URLs to access or move the files as needed
Alternatively, if you need to upload files to S3 using presigned URLs as part of your workflow before or after the MediaConvert processing, you can generate presigned URLs programmatically using the AWS SDK. This would allow temporary, secure access for uploading content to S3 without requiring AWS credentials.
Presigned URLs can be created with specific permissions (like PUT) and an expiration time, giving you control over how and when the URLs can be used to interact with your S3 objects.
Sources
Search - AWS Elemental MediaConvert API Reference
Amazon S3 examples using SDK for JavaScript (v3) - AWS SDK Code Examples
Create a presigned URL for Amazon S3 using an AWS SDK - AWS SDK Code Examples
answered a year ago
Hello,
Currently, AWS MediaConvert does not directly support using presigned URLs as output destinations. The service requires an S3 bucket as the destination for processed media files.
Here are your available options:
-
Standard S3 Output Approach:
{ "Settings": { "OutputGroups": [{ "OutputGroupSettings": { "Type": "FILE_GROUP_SETTINGS", "FileGroupSettings": { "Destination": "s3://your-bucket/output/" } } }] } } -
Workaround Solution: If you absolutely need to use presigned URLs, you can:
import boto3 from datetime import datetime, timedelta def create_workflow(): # 1. Set up MediaConvert job with temporary S3 location s3_temp_location = "s3://your-bucket/temp/" # Create MediaConvert job mediaconvert_job = { "Settings": { "OutputGroups": [{ "OutputGroupSettings": { "Type": "FILE_GROUP_SETTINGS", "FileGroupSettings": { "Destination": s3_temp_location } } }] } } # 2. Set up S3 event notification for job completion s3_client = boto3.client('s3') # 3. Create Lambda function to handle the completed file def handle_completed_file(event, context): # Get file details from event bucket = event['Records'][0]['s3']['bucket']['name'] key = event['Records'][0]['s3']['object']['key'] # Generate presigned URL for PUT presigned_url = s3_client.generate_presigned_url( 'put_object', Params={ 'Bucket': 'destination-bucket', 'Key': key }, ExpiresIn=3600 # URL valid for 1 hour ) # Copy file using presigned URL response = requests.put(presigned_url, data=s3_client.get_object( Bucket=bucket, Key=key )['Body'].read()) -
Alternative Approach - API Gateway Integration:
def create_api_workflow(): # 1. Create API Gateway endpoint # 2. Set up MediaConvert job as before # 3. Create Lambda function to handle API requests def api_handler(event, context): # Generate presigned URL presigned_url = generate_presigned_url() # Return URL in response return { 'statusCode': 200, 'body': json.dumps({ 'presigned_url': presigned_url }) } -
Best Practices:
a. IAM Role Configuration:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject" ], "Resource": [ "arn:aws:s3:::your-bucket/*" ] }, { "Effect": "Allow", "Action": [ "mediaconvert:CreateJob" ], "Resource": "*" } ] }b. Error Handling:
def handle_mediaconvert_job(job_id): try: # Monitor job status mediaconvert = boto3.client('mediaconvert') response = mediaconvert.get_job(Id=job_id) if response['Job']['Status'] == 'COMPLETE': # Handle successful completion process_output() elif response['Job']['Status'] == 'ERROR': # Handle error handle_error(response['Job']['ErrorMessage']) except Exception as e: logger.error(f"Error processing MediaConvert job: {str(e)}") raise -
Monitoring and Cleanup:
def cleanup_temp_files(): try: s3_client = boto3.client('s3') # Delete temporary files older than 24 hours response = s3_client.list_objects_v2( Bucket='your-bucket', Prefix='temp/' ) for obj in response['Contents']: if (datetime.now() - obj['LastModified'].replace(tzinfo=None)).days >= 1: s3_client.delete_object( Bucket='your-bucket', Key=obj['Key'] ) except Exception as e: logger.error(f"Error cleaning up temp files: {str(e)}")
While direct presigned URL output isn't supported, these workarounds can help achieve similar functionality. Consider the additional complexity and maintenance requirements when implementing these solutions.
I hope you find this helpful. If yes, please accept/upvote my answer. Thank you!
Relevant content
asked 3 years ago
