How to create cloudfront signed URL from mobile app?

0

I can achieve it thorough java in my mobile app but it is insecure to store the secret key in the client side. Attackers can harm the server. So what is the best way to create singed URL for mobile apps?

I want signed URL of list of videos for my feed like youtube. What is the best way to achieve that? Please provide some code.

1 Answer
0
Accepted Answer

There are several ways to do this here is one.

To create a signed URL for an Amazon S3 object in Python, you can use the boto3 library and the client.generate_presigned_url() method. This method allows you to create a URL that you can share with others that provides temporary access to download or upload an object in your bucket.

Here is an example of how you can use generate_presigned_url() to create a signed URL that allows a user to download an object from your bucket: (If you used this code as a lambda function or with secrets manager you would not need to embed credentials)

import boto3

# Replace ACCESS_KEY and SECRET_KEY with your Amazon S3 access key and secret key
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)

# Replace BUCKET_NAME and OBJECT_KEY with the name of your bucket and the key of the object you want to create a signed URL for
url = s3.generate_presigned_url(
    ClientMethod='get_object',
    Params={
        'Bucket': BUCKET_NAME,
        'Key': OBJECT_KEY
    }
)

print(url)

If you need help generating code for most languages I suggest using CodeWhisperer, which is in free preview. https://aws.amazon.com/codewhisperer/

profile pictureAWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions