2023-12-10

Goal

Set up a way to serve images using AWS S3. Then, start to design the Django Models for the different apps.

Notes

Today I wanted to set up a way to serve images from a private AWS S3 bucket. To do this I first needed to install boto3 and django-storages

pip install boto3 django-storages

Then I followed the instructions in this video to create a new IAM User within my AWS account. I then went in and adjusted the security credentials to generate programmatic access via my AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, both of which I stored in my Environment Variables. I then loaded these environment variables in the following way in my hithub/settings.py file:

AWS_ACCESS_KEY_ID = 'your-access-key-id'
AWS_SECRET_ACCESS_KEY = 'your-secret-access-key'
AWS_STORAGE_BUCKET_NAME = 'your-s3-bucket-name'
AWS_S3_REGION_NAME = 'your-region'  # e.g., 'us-east-1'
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'

# For media files
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/media/'

I was able to access AWS by generating a pre-signed URL, but that only worked temporarily

Results

  • Established an IAM User on AWS that has full access to S3
  • Started configuring hithub/settings.py to include a place for media storage

Next Time

  • Allow the user to access pre-signed URLs

Previous Note 2023-12-09 Next Note 2023-12-11