1 00:00:00,060 --> 00:00:03,300 Okay, so let's talk about a serverless hosted website, 2 00:00:03,300 --> 00:00:05,020 maybe called myblog.com. 3 00:00:05,020 --> 00:00:07,610 So our website should scale globally, 4 00:00:07,610 --> 00:00:11,410 and we rarely write blogs, we often read blogs. 5 00:00:11,410 --> 00:00:12,640 So our blogs is seen by 6 00:00:12,640 --> 00:00:14,470 hundreds of thousands of people online, 7 00:00:14,470 --> 00:00:17,350 and we rarely add blogs, maybe one a day, one a week, 8 00:00:17,350 --> 00:00:19,970 but most of the time these blogs are being read. 9 00:00:19,970 --> 00:00:24,380 And so most of my website is going to be purely static files 10 00:00:24,380 --> 00:00:25,360 and maybe a little bit of my website 11 00:00:25,360 --> 00:00:28,060 is going to be a dynamic REST API. 12 00:00:28,060 --> 00:00:30,630 I want to implement caching where possible 13 00:00:30,630 --> 00:00:32,890 to relieve save cost and save latency, 14 00:00:32,890 --> 00:00:34,780 and have a great user experience. 15 00:00:34,780 --> 00:00:38,270 And any new users that subscribes to my website, to my blog, 16 00:00:38,270 --> 00:00:41,110 I really want them to receive a warm welcome Email, 17 00:00:41,110 --> 00:00:42,680 and this should be serverless. 18 00:00:42,680 --> 00:00:44,740 And any photo uploaded to the blog, 19 00:00:44,740 --> 00:00:47,100 I also want to have a thumbnail being generated, 20 00:00:47,100 --> 00:00:49,580 also serverless because I really like serverless. 21 00:00:49,580 --> 00:00:52,520 So how do we implement all these requirements? 22 00:00:52,520 --> 00:00:54,580 Number one, we want to serve content, 23 00:00:54,580 --> 00:00:56,150 it's static and it's global. 24 00:00:56,150 --> 00:00:57,950 So if you remember, we have our client, 25 00:00:57,950 --> 00:01:01,330 and our static content may be stored in Amazon S3. 26 00:01:01,330 --> 00:01:03,240 So how do we expose that bucket? 27 00:01:03,240 --> 00:01:05,800 Remember the Amazon S3 bucket is in specific region. 28 00:01:05,800 --> 00:01:07,270 How do we expose this globally? 29 00:01:07,270 --> 00:01:09,320 Well we can use Amazon CloudFront, 30 00:01:09,320 --> 00:01:12,700 and Amazon CloudFront is a global distribution CDN, 31 00:01:12,700 --> 00:01:14,880 and so basically our clients is going to 32 00:01:14,880 --> 00:01:17,830 interact with edge locations on Amazon CloudFront, 33 00:01:17,830 --> 00:01:20,780 and it's going to cage data coming straight from Amazon S3. 34 00:01:21,880 --> 00:01:24,240 Okay super easy, we've seen CloudFront, 35 00:01:24,240 --> 00:01:26,300 we've seen S3, as a classic architecture. 36 00:01:26,300 --> 00:01:28,520 Now how do we do this securely? 37 00:01:28,520 --> 00:01:30,170 Now that's a very common question as well, 38 00:01:30,170 --> 00:01:32,650 so we have the client it's interacting with CloudFront, 39 00:01:32,650 --> 00:01:34,280 and it's a global distribution still, 40 00:01:34,280 --> 00:01:36,620 but now, we're going to use OAI, 41 00:01:36,620 --> 00:01:40,010 or an Origin Access Identity from CloudFront to S3. 42 00:01:40,010 --> 00:01:42,579 Basically saying, okay, we're going to add a bucket policy, 43 00:01:42,579 --> 00:01:45,120 and the bucket policy on S3 will say, 44 00:01:45,120 --> 00:01:49,660 you only authorize the OAI, so CloudFront, to read, 45 00:01:49,660 --> 00:01:50,680 the rest cannot. 46 00:01:50,680 --> 00:01:53,020 And so that secures it, because now our clients 47 00:01:53,020 --> 00:01:56,200 they cannot go directly to the S3 bucket to get the content. 48 00:01:56,200 --> 00:01:57,680 They have to go through CloudFront, 49 00:01:57,680 --> 00:02:01,430 and in this way we've secured our infrastructure. 50 00:02:01,430 --> 00:02:04,380 Okay, so now we have this, and this is really good. 51 00:02:04,380 --> 00:02:07,870 How do we add a public serverless REST API? 52 00:02:07,870 --> 00:02:10,690 Well for this we'll have a REST HTTPS cloud talking 53 00:02:10,690 --> 00:02:13,930 to Amazon API Gateway, invoking a Lambda function, 54 00:02:13,930 --> 00:02:16,500 maybe querying and reading from DynamoDB, 55 00:02:16,500 --> 00:02:18,070 and because we have so many reads, 56 00:02:18,070 --> 00:02:21,865 maybe DAX is a great caching layer we could use, okay? 57 00:02:21,865 --> 00:02:24,170 So far very easy. 58 00:02:24,170 --> 00:02:25,217 If we're going global, 59 00:02:25,217 --> 00:02:28,890 maybe we could be leveraging DynamoDB global databases 60 00:02:28,890 --> 00:02:31,490 to reduce the latencies in part of the world. 61 00:02:31,490 --> 00:02:33,170 That also could be a really good way 62 00:02:33,170 --> 00:02:35,580 of maybe speeding up our infrastructure 63 00:02:35,580 --> 00:02:37,000 and our architecture. 64 00:02:37,000 --> 00:02:39,910 Okay so this is fine, we have everything we need. 65 00:02:39,910 --> 00:02:43,070 Now let's talk about the user welcome email flow. 66 00:02:43,070 --> 00:02:45,770 Well here, remember when a user subscribes 67 00:02:45,770 --> 00:02:48,430 I want them to be having an email saying, 68 00:02:48,430 --> 00:02:49,660 hello, how are you? 69 00:02:49,660 --> 00:02:52,070 So for this, maybe in DynamoDB 70 00:02:52,070 --> 00:02:54,650 we want to enable streams of changes, 71 00:02:54,650 --> 00:02:57,810 so we'll have DynamoDB stream being created, 72 00:02:57,810 --> 00:03:02,200 and that DynamoDB stream will invoke a Lambda function. 73 00:03:02,200 --> 00:03:04,800 That Lambda function is going to be very special, 74 00:03:04,800 --> 00:03:06,300 it's going to have an IAM role, 75 00:03:06,300 --> 00:03:08,880 which allows us to use Amazon SES. 76 00:03:08,880 --> 00:03:10,746 So we haven't seen what Amazon SES is, 77 00:03:10,746 --> 00:03:11,579 but it's really simple. 78 00:03:11,579 --> 00:03:14,570 It's called Amazon Simple Email Service, so SES, 79 00:03:14,570 --> 00:03:16,960 and it basically allows us to send emails. 80 00:03:16,960 --> 00:03:20,690 So here our Amazon Lambda function can use the AWS SDK 81 00:03:20,690 --> 00:03:23,650 to send emails from Amazon SES, and here we go, 82 00:03:23,650 --> 00:03:27,630 we have a basically serverless user welcome email flow, 83 00:03:27,630 --> 00:03:30,360 and really simple, no infrastructure to manage, 84 00:03:30,360 --> 00:03:33,090 it just works and scales really really well. 85 00:03:33,090 --> 00:03:36,880 Okay, so now we said, okay if users upload images 86 00:03:36,880 --> 00:03:40,190 we want thumbnails to be created, so our client, 87 00:03:40,190 --> 00:03:44,020 is going to maybe upload to our S3 bucket directly, 88 00:03:44,020 --> 00:03:47,280 or maybe we again have an OAI in a CloudFront distribution. 89 00:03:47,280 --> 00:03:50,337 In which case our client will upload photos to CloudFront, 90 00:03:50,337 --> 00:03:53,560 and CloudFront will forward them onto the Amazon S3 bucket, 91 00:03:53,560 --> 00:03:57,790 and this is called S3 transfer acceleration. 92 00:03:57,790 --> 00:04:01,470 So either directly to S3, or using transfer acceleration, 93 00:04:01,470 --> 00:04:04,923 and then we will do is that whenever a file is added to S3 94 00:04:04,923 --> 00:04:07,530 it's going to trigger a Lambda function, 95 00:04:07,530 --> 00:04:10,160 so Lambda can be triggered by S3, 96 00:04:10,160 --> 00:04:12,100 and Lambda will be creating a thumbnail 97 00:04:12,100 --> 00:04:14,170 and putting that thumbnail into an S3 bucket, 98 00:04:14,170 --> 00:04:16,070 could be a different bucket for example. 99 00:04:16,070 --> 00:04:18,480 And just to show you it's possible, 100 00:04:18,480 --> 00:04:22,710 Amazon S3 also has triggers to SQS and SNS. 101 00:04:22,710 --> 00:04:23,850 Now this is optional, 102 00:04:23,850 --> 00:04:26,260 and from SQS SNS you can do whatever you want, 103 00:04:26,260 --> 00:04:28,430 but it's just to show you that your very free 104 00:04:28,430 --> 00:04:30,100 into how you want things to work, 105 00:04:30,100 --> 00:04:33,730 and so Amazon S3 can invoke either Lambda, SQS, or SNS, 106 00:04:33,730 --> 00:04:35,170 and you're really free to think about your 107 00:04:35,170 --> 00:04:37,610 solution architecture and how to make things serverless 108 00:04:37,610 --> 00:04:39,840 and easy for you on your end. 109 00:04:39,840 --> 00:04:42,860 So this is quite a complete architecture we've just done, 110 00:04:42,860 --> 00:04:45,740 but it's all serverless, it's all scaling globally, 111 00:04:45,740 --> 00:04:47,460 and I think that's what matters most. 112 00:04:47,460 --> 00:04:49,910 So we've seen static content being distributed 113 00:04:49,910 --> 00:04:51,570 using CloudFront with S3. 114 00:04:51,570 --> 00:04:53,480 We've seen the REST API that was serverless, 115 00:04:53,480 --> 00:04:54,820 we didn't need Cognito this time 116 00:04:54,820 --> 00:04:56,950 because it was a public REST API, 117 00:04:56,950 --> 00:04:59,430 and we leveraged a global DynamoDB table 118 00:04:59,430 --> 00:05:01,160 to serve the data globally. 119 00:05:01,160 --> 00:05:03,380 We could have used also Aurora Global Database, 120 00:05:03,380 --> 00:05:06,140 but in this case it wouldn't have been such serverless, 121 00:05:06,140 --> 00:05:08,460 it would have been provisioned Aurora. 122 00:05:08,460 --> 00:05:10,740 We could also enable DynamoDB streams, 123 00:05:10,740 --> 00:05:13,380 basically these streams should tell us about changes 124 00:05:13,380 --> 00:05:16,560 to our user tables and then trigger a Lambda function, 125 00:05:16,560 --> 00:05:19,140 and that Lambda function had a IAM role attached to it, 126 00:05:19,140 --> 00:05:22,260 so it could use SES or Simple Email Service, 127 00:05:22,260 --> 00:05:24,910 and this was just to send emails in a serverless way. 128 00:05:24,910 --> 00:05:26,276 And S3 we've seen that it could trigger 129 00:05:26,276 --> 00:05:29,630 SQS, SNS, Lambda to be notify of events. 130 00:05:29,630 --> 00:05:31,840 So quite a lot of learnings, all these things we know, 131 00:05:31,840 --> 00:05:33,260 but it's now, I think, really nice 132 00:05:33,260 --> 00:05:35,230 to see all these things working together, 133 00:05:35,230 --> 00:05:37,370 and how we can create some really cool applications 134 00:05:37,370 --> 00:05:39,040 using all the concepts we know. 135 00:05:39,040 --> 00:05:39,873 So I hope you liked it, 136 00:05:39,873 --> 00:05:41,750 and I will see you in the next lecture.