PolarBear10
PolarBear10

Reputation: 2305

Create models in Django using AWS S3 data and point to them

I would like to create models in Django using existing data in AWS S3

def create_model(**kwargs):
    return Video.objects.create(**kwargs)

for s3_object_mp4 in my_bucket.objects.all():

    path_mp4, key_mp4 = os.path.split(s3_object_mp4.key)
    create_model(video_name=str('key_mp4'),
                         video_url='??')

And I used this to point to the created data:

client = boto3.client('s3', 'eu-central-1')
url = client.generate_presigned_url('get_object',Params={'Bucket': bucket_name, 'Key': key_mp4}, ExpiresIn=604800)

Two questions here:

1) If this link will expire, does that mean on expiration I have to delete, and re-populate my models every 7 days as max ?

2) Will amazon then charge everytime a user watches a video on the html (url) ? and then another time when repopulating the whole database because the links expired?

Upvotes: 1

Views: 288

Answers (1)

Dwight Gunning
Dwight Gunning

Reputation: 2525

1) Your pre-signed URLs will expire. Deleting and re-populating the models is one option. Another option would be to perform an update in place.

2) S3 is priced on the data stored and the requests. According to this answer the generation of pre-signed URLs is entirely client-side and therefore free.

Upvotes: 1

Related Questions