1 00:00:00,240 --> 00:00:02,900 Okay, so now let's talk about S3 websites. 2 00:00:02,900 --> 00:00:04,810 S3 can host static websites, 3 00:00:04,810 --> 00:00:07,830 and have them accessible on the World Wide Web, 4 00:00:07,830 --> 00:00:10,360 and the website URLs will be very simple. 5 00:00:10,360 --> 00:00:11,720 It will be an HTTP endpoint, 6 00:00:11,720 --> 00:00:13,210 and it can look like this 7 00:00:13,210 --> 00:00:15,630 or like this depends on the region you're in. 8 00:00:15,630 --> 00:00:17,880 The idea is that it starts with the bucket name, 9 00:00:17,880 --> 00:00:20,920 dot s3-website and then the AWS-region, 10 00:00:20,920 --> 00:00:23,560 dot amazonaws dot com. 11 00:00:23,560 --> 00:00:26,240 And if you enable it for a website, 12 00:00:26,240 --> 00:00:28,170 but you don't set a bucket policy 13 00:00:28,170 --> 00:00:30,500 that allows public access to your buckets, 14 00:00:30,500 --> 00:00:32,900 you will get a 403 forbidden error, 15 00:00:32,900 --> 00:00:35,310 and we'll see how to fix this in this hands-on. 16 00:00:35,310 --> 00:00:39,203 So let's go ahead and enable our S3 bucket as a websites. 17 00:00:40,200 --> 00:00:41,430 Okay, so let's go ahead, 18 00:00:41,430 --> 00:00:44,280 and make this bucket a static websites. 19 00:00:44,280 --> 00:00:47,130 So first to do so let's just make sure to remove 20 00:00:47,130 --> 00:00:49,210 the bucket policy we had from before. 21 00:00:49,210 --> 00:00:50,970 I'm just going to delete it 22 00:00:50,970 --> 00:00:54,290 so we can upload objects without any problems. 23 00:00:54,290 --> 00:00:57,350 Okay, great. So now let's go back into our objects. 24 00:00:57,350 --> 00:01:01,000 We want to upload an index dot HTML file 25 00:01:01,000 --> 00:01:04,379 and to find it you going to the course downloads code, 26 00:01:04,379 --> 00:01:07,150 and you will find an index dot html. 27 00:01:07,150 --> 00:01:09,460 Which is a very simple html document, 28 00:01:09,460 --> 00:01:10,890 which is called my first webpage 29 00:01:10,890 --> 00:01:13,080 says I love coffee, hello world, 30 00:01:13,080 --> 00:01:15,950 and this will load the coffee dot JPEG file. 31 00:01:15,950 --> 00:01:18,780 The rest right here is for now commented code. 32 00:01:18,780 --> 00:01:21,540 This will be used when I demonstrate course. 33 00:01:21,540 --> 00:01:24,320 Okay, so pretty easy and pretty good so far. 34 00:01:24,320 --> 00:01:27,530 Next we'll also have error dot html file 35 00:01:27,530 --> 00:01:29,680 which just says, uh oh, there was an error, 36 00:01:29,680 --> 00:01:31,320 and I'm going to remove this by the way. 37 00:01:31,320 --> 00:01:32,940 Okay, great. 38 00:01:32,940 --> 00:01:34,780 So let's go ahead 39 00:01:34,780 --> 00:01:38,120 and upload these two files. 40 00:01:38,120 --> 00:01:39,710 So I'm going to add files, 41 00:01:39,710 --> 00:01:42,360 and I'm going to upload both the index html, 42 00:01:42,360 --> 00:01:45,100 and errors dot html. 43 00:01:45,100 --> 00:01:48,300 Here we go so both of these files have been uploaded, 44 00:01:48,300 --> 00:01:51,720 and next I want to scroll down 45 00:01:51,720 --> 00:01:55,440 and click on upload. Here we go. 46 00:01:55,440 --> 00:01:59,840 So now our buckets contains these four files, 47 00:01:59,840 --> 00:02:02,420 and we want to able to have a look at them. 48 00:02:02,420 --> 00:02:05,530 So to do so we're going to go into properties, 49 00:02:05,530 --> 00:02:08,220 and make our buckets a website. 50 00:02:08,220 --> 00:02:13,210 So if I scroll down and I go to static website hosting. 51 00:02:13,210 --> 00:02:14,640 I can see is disabled right now 52 00:02:14,640 --> 00:02:16,850 but let's go ahead and edit it. 53 00:02:16,850 --> 00:02:21,090 We want to enable it, we will host a static websites. 54 00:02:21,090 --> 00:02:25,230 And then the index document is called index dot html, 55 00:02:25,230 --> 00:02:28,140 and the air document error dot HTML. 56 00:02:28,140 --> 00:02:31,163 Which correspond to the two files we have just uploaded. 57 00:02:32,150 --> 00:02:33,800 We will save the changes, 58 00:02:33,800 --> 00:02:36,880 and now our buckets is ready to be a static website host. 59 00:02:36,880 --> 00:02:39,250 So if I scroll down all the way down, 60 00:02:39,250 --> 00:02:42,530 we can find the buckets website end points. 61 00:02:42,530 --> 00:02:44,670 So let's try it out I'm going to copy this. 62 00:02:44,670 --> 00:02:47,100 Open a new tab and paste it. 63 00:02:47,100 --> 00:02:50,380 And what do we find? Well, we see 403 forbidden. 64 00:02:50,380 --> 00:02:54,750 So we are not allowed to access our buckets. 65 00:02:54,750 --> 00:02:56,500 And this makes sense, right? 66 00:02:56,500 --> 00:02:58,770 Because if we go back all the way up, 67 00:02:58,770 --> 00:03:02,830 currently the buckets and the objects are not public. 68 00:03:02,830 --> 00:03:05,930 And it turns out that we're trying to access them publicly. 69 00:03:05,930 --> 00:03:07,480 So how do we do so? 70 00:03:07,480 --> 00:03:10,220 Well, two steps, we go to permissions. 71 00:03:10,220 --> 00:03:13,970 First we want to disable the Block public access setting. 72 00:03:13,970 --> 00:03:15,880 Otherwise we'll never be able to be, 73 00:03:15,880 --> 00:03:16,830 to make our bucket public. 74 00:03:16,830 --> 00:03:21,360 So let's edit this and untick block all public access. 75 00:03:21,360 --> 00:03:24,910 And this is going to allow us to make some objects public. 76 00:03:24,910 --> 00:03:28,230 And to set a public buckets policy. 77 00:03:28,230 --> 00:03:30,500 So I'd confirm it. That's the first step. 78 00:03:30,500 --> 00:03:33,080 And second step is we're going to bucket policy, 79 00:03:33,080 --> 00:03:34,920 and we're going to write a bucket policy 80 00:03:34,920 --> 00:03:36,850 which allows public access. 81 00:03:36,850 --> 00:03:39,470 So let's go into policy generator one more time, 82 00:03:39,470 --> 00:03:42,830 is going to be an S3 buckets type of policy. 83 00:03:42,830 --> 00:03:46,460 We're going to allow anyone, so principals star. 84 00:03:46,460 --> 00:03:48,220 To do this time not to put objects, 85 00:03:48,220 --> 00:03:52,030 but to get objects so let's do a get objects, 86 00:03:52,030 --> 00:03:57,030 and VRN is going to be again the buckets ARN slash star. 87 00:03:58,040 --> 00:04:00,410 Saying anyone can do a get object 88 00:04:00,410 --> 00:04:02,310 on any object of these buckets. 89 00:04:02,310 --> 00:04:03,400 This makes sense. 90 00:04:03,400 --> 00:04:08,030 I click on add statements, generate policy, copy this, 91 00:04:08,030 --> 00:04:11,350 and paste it here and here we go. 92 00:04:11,350 --> 00:04:15,060 Now this buckets policy has made my S3 bucket public. 93 00:04:15,060 --> 00:04:18,720 How do I know? Well now under access, it says public. 94 00:04:18,720 --> 00:04:19,730 And there's a little warning sign 95 00:04:19,730 --> 00:04:23,150 because AWS doesn't really want you to have public buckets, 96 00:04:23,150 --> 00:04:24,950 and they want to be you to be very careful 97 00:04:24,950 --> 00:04:28,690 anytime you make anything public on Amazon S3. 98 00:04:28,690 --> 00:04:32,800 Okay, so now if we go back to this URL, 99 00:04:32,800 --> 00:04:34,460 and refresh it. 100 00:04:34,460 --> 00:04:37,470 We can see there is I love coffee, hello world, 101 00:04:37,470 --> 00:04:38,920 and the coffee dot JPEG file. 102 00:04:38,920 --> 00:04:40,770 So this works great. 103 00:04:40,770 --> 00:04:44,060 If I go to slash coffee dot JPEG. 104 00:04:44,060 --> 00:04:47,570 I should only be able to see at coffee dot JPEG files. 105 00:04:47,570 --> 00:04:50,691 And if I tap a random URL for example, 106 00:04:50,691 --> 00:04:54,760 does not exist dot JPEG, 107 00:04:54,760 --> 00:04:56,810 I'm going to get to there was an error, 108 00:04:56,810 --> 00:04:59,800 which corresponds to the error that html file 109 00:04:59,800 --> 00:05:01,580 we have defined from before. 110 00:05:01,580 --> 00:05:02,840 So all good. 111 00:05:02,840 --> 00:05:05,610 We have made our extra bucket now 112 00:05:05,610 --> 00:05:08,090 a static website hosts, which is great. 113 00:05:08,090 --> 00:05:10,040 And I will see you in the next lecture.