Using AWS S3 Buckets with Heroku and Rails
Upon graduating Flatiron School’s Software Engineering Bootcamp, I wanted to deploy my capstone project that I was so proud of. I thought ahead and initialized my database with Postgresql so it would be compatible with Heroku. What I didn’t take in to account how much storage 78 images takes, let alone all the other data. So what now? Looking at Heroku’s docs, I see that ASW S3 (simple storage solution) Buckets suit my needs.
You can have up to two access keys to make AWS API calls. Access keys can be found in My Account → Security Credentials. If you don’t already have one, make one. use heroku config:set AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY
heroku config:set AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=xxxto set both keys.
- Open the AWS S3 Console
- Create a bucket, the name must be globally unique across all AWS buckets. Make sure to check name constrictions.
- Set object ownership
- Set or block public accessibility.
- Choose your region and create.
For this project, I did direct uploads (not through my app). Because the images can not be modified. Eventually, I want the admin users to be able to use their own images, but this was the best solution for the sake of saving time.
gem 'aws-sdk', '~> 2'and
gem 'image_processing', '~> 1.2'to your gemfile and
- Make sure you have a .env file to hide your
- Set Active Storage services in