Locked lesson.
About this lesson
Using Amazon AWS S3 to store our database images.
Exercise files
Download this lesson’s related exercise files.
Amazon AWS Part 1.docx59.1 KB Amazon AWS Part 1 - Solution.docx
59.6 KB
Quick reference
Amazon AWS Part 1
In this video we'll begin to set up Amazon AWS to handle our Image storing.
When to use
Heroku will allow us to upload images to our Postgres database, but will delete them after an hour or so. We need to use AWS S3 to store the images.
Instructions
First: Sign up for an Amazon AWS account at Aws.Amazon.com
Next: Enter your credit card, don't worry - S3 should only cost $1 or less per month and you can cancel at any time.
Next: Once you sign into AWS, look at the URL at the top of your web browser. Make a note of the region designation at the end of your URL. Write it down.
Look at the menu at the top of the screen. Note the region name (mine was Oregon). Write it down.
Next: Click on Services >> S3 and create a new bucket with a unique name. Designate it to your Region.
Check your bucket permissions, make sure "Everyone" has Read and Write permissions.
Next: Add the aws-sdk Gem to your Gemfile, run bundle install.
Next: Check out Heroku's documentation of the AWS-SDK gem at:
https://devcenter.heroku.com/articles/paperclip-s3
Hints & tips
- Sign up for AWS at aws.amazon.com
- Create a Bucket, give "Everyone" read and write permissions
- Install the AWS-SDK Gem
- Check out the Heroku AWS-SDK Documentation https://devcenter.heroku.com/articles/paperclip-s3
- 00:04 Moving right along, so we can upload images in our development environment and
- 00:09 we can upload images in our production environment at Heroku, but
- 00:12 Heroku wont allow us to keep those images there.
- 00:14 If we upload an image, a couple of hours later,
- 00:17 Heroku will delete it from the database automatically.
- 00:19 And that's just because Heroku's not in the business of storing images.
- 00:23 They don't want to be an image storing service,
- 00:25 so they won't allow their databases to keep images.
- 00:28 So we can get around that by using something called Amazon AWS.
- 00:31 And AWS stands for Amazon Web Services, and it's the leading service online for
- 00:36 web hosting.
- 00:37 In fact, Heroku themselves host their service on AWS.
- 00:41 I mean, everybody uses AWS, there's servers,
- 00:43 there's all kinds of stuff on here, so this is what we're gonna use.
- 00:45 We're gonna be using something called S3, which is Simple Storage Solution.
- 00:49 And so go ahead and sign up for an account if you don't have one already.
- 00:52 I think it's free to sign up, but you have to pay based on what you use.
- 00:56 So it's a pay as you go type thing.
- 00:57 I recommend that you do actually put your credit card in and
- 01:00 sign up with a credit card and go ahead and pay for S3 for a month.
- 01:04 My S3 bill last month was like a buck 20 for the entire month,
- 01:07 it's not very expensive.
- 01:08 For this course, for everything we're gonna do,
- 01:11 your bill's gonna be way less than a dollar.
- 01:12 I mean, it might be 15 cents or something, it's very cheap.
- 01:15 I mean, even if you only keep it for a month,
- 01:17 I do recommend that you do that in order to learn how to use this,
- 01:20 cuz it's really useful and you'll use this thing forever.
- 01:23 I mean, in any app you ever build, if you ever wanna store images, you'll use this.
- 01:26 So I recommended you do that, go ahead and sign up, and
- 01:29 head over the Management Console after you've signed in.
- 01:31 And the first thing to notice is this URL up here, the region=us-west-2.
- 01:36 And you probably picked your region when you signed up, but
- 01:39 we need to make a note of this, so go ahead and copy that.
- 01:42 And I'm just gonna open a notepad, and I'm gonna type in Region: us-west-2,
- 01:45 and then come over here and look right here.
- 01:47 It says Oregon, that's the specific region, US West (Oregon).
- 01:51 So I'm gonna type that down too, okay.
- 01:55 So your screen may look a little bit different.
- 01:57 They're always changing this around, but head over to Services and click S3.
- 02:03 And S3 works with buckets.
- 02:05 You put things in a bucket.
- 02:06 We're gonna be putting our images in a bucket.
- 02:08 So we need to create a bucket, and
- 02:09 you can see I've already got a couple of them created, but create a bucket.
- 02:12 Now this needs to be a unique name, so pinteresting123,
- 02:17 and then select your region.
- 02:19 Try and pick the same one that we noticed earlier.
- 02:22 I'm at US West (Oregon), we wrote that down, so click that.
- 02:26 And then click Create.
- 02:29 That bucket name is not available, so we need to pick something, 123456.
- 02:36 Okay, so next, we wanna copy down the name of that bucket.
- 02:40 So in our case its pinteresting123456, pull up my notepad.
- 02:45 I'm just gonna type bucket, and we need to look here at permissions just
- 02:50 to make sure everybody has read and write permissions.
- 02:56 So I clicked on everybody, click Save.
- 03:00 Okay, so that works.
- 03:02 Okay, so I think we're good to go here.
- 03:04 Now, we need to install a gem that lets us access all of this stuff.
- 03:08 And so head over to RubyGems, and
- 03:10 the gem we're gonna be using is called aws-sdk, so click on that.
- 03:15 42 million downloads, and copy this to the clipboard.
- 03:18 Head over to our gemfile, paste it in, save the file as always.
- 03:22 Run your bundle install.
- 03:23 And normally we want to look up the documentation, but the documentation for
- 03:28 this is really bad.
- 03:29 But since we're gonna be storing our images on Heroku,
- 03:32 Heroku actually has a documentation guide that's much better than that.
- 03:35 So head over to Google and just type in Heroku Paperclip AWS,
- 03:39 'cause after all, this is Paperclip, that's the thing that manages our images.
- 03:44 And you see right away there's this file, and if we scroll down,
- 03:48 this shows us exactly what we need to do.
- 03:51 We'll save this for the next video, 'cause we need to do a couple other things yet
- 03:55 before we get to this.
- 03:57 So in the next video, we'll setup our AWS_ACCESS_KEY_ID and
- 04:00 our SECRET_ACCESS_KEY.
Lesson notes are only available for subscribers.