1 00:00:00,410 --> 00:00:02,690 So let's practice using SQS. 2 00:00:02,690 --> 00:00:04,390 So let's go into the SQS console, 3 00:00:04,390 --> 00:00:07,560 close this message and create a queue. 4 00:00:07,560 --> 00:00:09,570 So, when we create a queue in SQS, 5 00:00:09,570 --> 00:00:12,640 we'll see we have two choices, Standard and FIFO, 6 00:00:12,640 --> 00:00:14,330 and FIFO we'll see in it's own time. 7 00:00:14,330 --> 00:00:17,060 So, for now we'll just focus on Standard. 8 00:00:17,060 --> 00:00:18,640 Okay, now we have to name the queue. 9 00:00:18,640 --> 00:00:21,290 So I'll call this one DemoQueue, 10 00:00:21,290 --> 00:00:23,500 and we need to configure that queue. 11 00:00:23,500 --> 00:00:25,430 So the queue has a lot of parameters, 12 00:00:25,430 --> 00:00:28,650 we'll see the visibility timeout impact in the next lecture 13 00:00:28,650 --> 00:00:30,910 we'll see delay as well in the next lectures, 14 00:00:30,910 --> 00:00:33,080 we'll see this as well in the next lectures. 15 00:00:33,080 --> 00:00:34,710 A lot of things we'll see very soon. 16 00:00:34,710 --> 00:00:37,320 The message retention period is four days 17 00:00:37,320 --> 00:00:42,260 but we can set it anywhere between one minute and 14 days. 18 00:00:42,260 --> 00:00:43,770 So this is how long the message will stay 19 00:00:43,770 --> 00:00:45,720 in the queue waiting to be processed 20 00:00:45,720 --> 00:00:48,460 before being dropped automatically out of the queue. 21 00:00:48,460 --> 00:00:50,070 And the maximum message size as you can see, 22 00:00:50,070 --> 00:00:52,690 the very maximum is 256 kilobytes, 23 00:00:52,690 --> 00:00:57,570 but it could be anywhere between one kilobytes and 256. 24 00:00:57,570 --> 00:01:01,570 Okay, so next we have to define an access policy. 25 00:01:01,570 --> 00:01:04,540 And the access policy is who can access the queue. 26 00:01:04,540 --> 00:01:06,410 By default, we can... 27 00:01:06,410 --> 00:01:08,210 Only the queue owner can send a message 28 00:01:08,210 --> 00:01:10,420 to the queue and receive message from the queue. 29 00:01:10,420 --> 00:01:13,000 But you can, if you use these drop-down, 30 00:01:13,000 --> 00:01:15,470 you can set other accounts, roles, 31 00:01:15,470 --> 00:01:19,270 or IAM users that could send messages into the queue, 32 00:01:19,270 --> 00:01:22,040 which is very helpful if we do some integrations 33 00:01:22,040 --> 00:01:24,970 with Amazon S3 or Amazon SNS. 34 00:01:24,970 --> 00:01:27,790 But for now, we'll just keep it to only the queue owner. 35 00:01:27,790 --> 00:01:29,340 And if you knew what you're doing, 36 00:01:29,340 --> 00:01:30,230 you could just directly go 37 00:01:30,230 --> 00:01:33,560 and edit this JSON policy in-line, 38 00:01:33,560 --> 00:01:36,180 to say who can write to your SQ SQ. 39 00:01:36,180 --> 00:01:37,840 We'll use the basic one, 40 00:01:37,840 --> 00:01:38,740 but as you can see, 41 00:01:38,740 --> 00:01:40,580 this JSON policy right here, 42 00:01:40,580 --> 00:01:43,060 looks a lot like an S3 bucket policy 43 00:01:43,060 --> 00:01:44,610 because they have the same purpose. 44 00:01:44,610 --> 00:01:46,660 This is to define who can access, 45 00:01:46,660 --> 00:01:49,620 an Amazon SQ SQ if you do cross-account 46 00:01:49,620 --> 00:01:51,310 or different roles or stuff like that. 47 00:01:51,310 --> 00:01:53,030 Okay, so for now we'll keep it as basic. 48 00:01:53,030 --> 00:01:54,280 This is a basic hands on. 49 00:01:55,120 --> 00:01:57,890 Queue encryption is possible. 50 00:01:57,890 --> 00:02:01,620 So we have in-transit encryption enabled by default, 51 00:02:01,620 --> 00:02:03,430 but you can add at-rest encryption 52 00:02:03,430 --> 00:02:05,680 by enabling server-side encryption, 53 00:02:05,680 --> 00:02:07,910 in which case we have to choose a CMK. 54 00:02:07,910 --> 00:02:10,690 And so we can ensure the default CMK, 55 00:02:10,690 --> 00:02:13,580 or we can choose an alias if we create our own key. 56 00:02:13,580 --> 00:02:14,460 But for now, I'm just going 57 00:02:14,460 --> 00:02:16,160 to use the default CMK, 58 00:02:16,160 --> 00:02:19,240 to get encryption on this queue. 59 00:02:19,240 --> 00:02:21,280 And the data key reuse period is, 60 00:02:21,280 --> 00:02:22,900 how long the same data key should be used 61 00:02:22,900 --> 00:02:24,010 to encrypt the data. 62 00:02:24,010 --> 00:02:25,420 For now, you can just leave it as five minutes, 63 00:02:25,420 --> 00:02:26,610 this is fine. 64 00:02:26,610 --> 00:02:29,490 Okay, dead-letter queue we'll see as well later on. 65 00:02:29,490 --> 00:02:31,360 So let's create this queue. 66 00:02:31,360 --> 00:02:33,350 And now the queue is successfully created. 67 00:02:33,350 --> 00:02:37,200 So, we can go ahead and send and receive messages from it. 68 00:02:37,200 --> 00:02:40,410 So we get a lot of different panels in this UI. 69 00:02:40,410 --> 00:02:43,210 But what we want to be doing is to go 70 00:02:43,210 --> 00:02:44,960 to the top right-hand side 71 00:02:44,960 --> 00:02:48,260 and click on send and receive messages. 72 00:02:48,260 --> 00:02:51,310 So here is a facility for us to send messages 73 00:02:51,310 --> 00:02:53,420 and then at the bottom to receive them. 74 00:02:53,420 --> 00:02:54,870 So as we can see right now in the queue, 75 00:02:54,870 --> 00:02:56,970 we have zero messages available. 76 00:02:56,970 --> 00:03:01,970 But if I enter hello world in the message body, 77 00:03:02,040 --> 00:03:04,490 and then send the message. 78 00:03:04,490 --> 00:03:05,880 As you can see the message is sent, 79 00:03:05,880 --> 00:03:07,300 is ready to be received. 80 00:03:07,300 --> 00:03:09,930 Now we have a messages available one. 81 00:03:09,930 --> 00:03:13,530 And so in here, as soon as I click on poll for messages, 82 00:03:13,530 --> 00:03:15,410 the messages will appear. 83 00:03:15,410 --> 00:03:16,243 So let's have a look. 84 00:03:16,243 --> 00:03:17,690 I click on poll for messages, 85 00:03:17,690 --> 00:03:20,220 and yes, we did receive that message right here. 86 00:03:20,220 --> 00:03:21,780 As we can see, we have a message ID, 87 00:03:21,780 --> 00:03:24,800 and if you want to look at the content of the message, 88 00:03:24,800 --> 00:03:26,220 I click on the message details, 89 00:03:26,220 --> 00:03:28,180 and I can have some information. 90 00:03:28,180 --> 00:03:30,550 So there's a lot of metadata around that message. 91 00:03:30,550 --> 00:03:32,500 For example, the hash of the message, 92 00:03:32,500 --> 00:03:34,630 who sent it, how many times it were received. 93 00:03:34,630 --> 00:03:35,680 So just one time right now, 94 00:03:35,680 --> 00:03:36,513 because we have... 95 00:03:36,513 --> 00:03:38,190 This is the first time we posted this message, 96 00:03:38,190 --> 00:03:41,590 the size in bytes, and if we go and want 97 00:03:41,590 --> 00:03:43,420 to receive the body itself, 98 00:03:43,420 --> 00:03:45,970 we can see that whatever I sent before hello world, 99 00:03:45,970 --> 00:03:48,830 has ended up right here in the message I just read. 100 00:03:48,830 --> 00:03:51,330 If we created attributes for the message, 101 00:03:51,330 --> 00:03:54,900 there was a message attributes panel that we didn't look at, 102 00:03:54,900 --> 00:03:57,900 we could create key values and read them from here as well. 103 00:03:57,900 --> 00:03:59,560 So, very simple what you would expect, 104 00:03:59,560 --> 00:04:02,870 when you send a message and then read it, 105 00:04:02,870 --> 00:04:05,120 you get the exact same message. 106 00:04:05,120 --> 00:04:06,240 But we have decoupled 107 00:04:06,240 --> 00:04:08,960 because a producer has sent some information, 108 00:04:08,960 --> 00:04:11,889 and a consumer has received that information. 109 00:04:11,889 --> 00:04:14,680 Now we can see that the message has been received twice 110 00:04:14,680 --> 00:04:19,269 because we didn't process it in enough time. 111 00:04:19,269 --> 00:04:20,839 So after 30 seconds, the lowest, 112 00:04:20,839 --> 00:04:22,700 the message went back into the queue, 113 00:04:22,700 --> 00:04:24,470 and we received it again. 114 00:04:24,470 --> 00:04:26,220 So if I poll for messages, 115 00:04:26,220 --> 00:04:28,170 now the message received count is three. 116 00:04:28,170 --> 00:04:31,170 So it has been read, yet again another time. 117 00:04:31,170 --> 00:04:33,070 So to be done with this message, 118 00:04:33,070 --> 00:04:35,610 because say we've processed this hello world message, 119 00:04:35,610 --> 00:04:37,290 I'm going to click on it, 120 00:04:37,290 --> 00:04:39,620 and then I'm going to click on delete. 121 00:04:39,620 --> 00:04:41,840 And by deleting the message from the queue, 122 00:04:41,840 --> 00:04:44,720 we have signaled to the SQ SQ, 123 00:04:44,720 --> 00:04:46,970 that the message has been successfully processed. 124 00:04:46,970 --> 00:04:47,890 And therefore, 125 00:04:47,890 --> 00:04:50,570 we have zero messages available in the queue, 126 00:04:50,570 --> 00:04:52,640 and if we poll again, 127 00:04:52,640 --> 00:04:54,270 we will not receive the same message again 128 00:04:54,270 --> 00:04:56,200 because we have deleted it. 129 00:04:56,200 --> 00:04:58,070 So you start seeing the power of queues. 130 00:04:58,070 --> 00:04:59,740 We could go ahead and send, 131 00:04:59,740 --> 00:05:01,080 many times different messages, 132 00:05:01,080 --> 00:05:01,913 hello world, and so on, 133 00:05:01,913 --> 00:05:03,440 and you can just play with it, 134 00:05:03,440 --> 00:05:06,030 and this is how you would set message attributes, 135 00:05:06,030 --> 00:05:08,140 but this is out of scope for the exam. 136 00:05:08,140 --> 00:05:10,930 And here, you would receive these messages, 137 00:05:10,930 --> 00:05:13,030 and you can receive many messages at a time. 138 00:05:13,030 --> 00:05:14,535 So if we send hello world, 139 00:05:14,535 --> 00:05:16,380 we'll send that message again, 140 00:05:16,380 --> 00:05:18,680 and hello world 2, for example, 141 00:05:18,680 --> 00:05:21,730 and send that message, and hello world 3, 142 00:05:21,730 --> 00:05:23,390 whatever you want really in that message. 143 00:05:23,390 --> 00:05:26,973 As we can see, as soon as I refresh this window, 144 00:05:28,030 --> 00:05:30,510 we can see that the number of messages available is three. 145 00:05:30,510 --> 00:05:32,380 And so if I poll for messages, 146 00:05:32,380 --> 00:05:35,670 I will get three messages available in here, 147 00:05:35,670 --> 00:05:37,100 to be processed. 148 00:05:37,100 --> 00:05:38,860 And again, you can take them all 149 00:05:38,860 --> 00:05:41,140 and delete them to signal to SQS 150 00:05:41,140 --> 00:05:42,500 that they have been processed. 151 00:05:42,500 --> 00:05:44,320 So fairly easy, but you've seen the power 152 00:05:44,320 --> 00:05:47,070 of producers and consumers. 153 00:05:47,070 --> 00:05:48,490 Now back in the queue, 154 00:05:48,490 --> 00:05:49,530 with just a few options as well, 155 00:05:49,530 --> 00:05:50,440 we can see out. 156 00:05:50,440 --> 00:05:52,180 So we can edit this queue 157 00:05:52,180 --> 00:05:54,340 to edit all the configurations 158 00:05:54,340 --> 00:05:56,070 that we've seen from before. 159 00:05:56,070 --> 00:05:57,520 Or you can purge the queue, 160 00:05:57,520 --> 00:06:00,240 this will delete all the messages in the queue. 161 00:06:00,240 --> 00:06:01,780 And so to delete all the messages, 162 00:06:01,780 --> 00:06:03,400 you just need to type purge, 163 00:06:03,400 --> 00:06:04,900 and it will go ahead and remove everything, 164 00:06:04,900 --> 00:06:07,250 which is very helpful when you do developments. 165 00:06:07,250 --> 00:06:09,327 But I don't think you should do this in production. 166 00:06:09,327 --> 00:06:12,350 And then you get some information around monitoring, 167 00:06:12,350 --> 00:06:14,630 for example here, which gives you some information 168 00:06:14,630 --> 00:06:17,367 around how many messages are in the queue, 169 00:06:17,367 --> 00:06:19,790 what's the approximate age of the oldest message; 170 00:06:19,790 --> 00:06:22,170 which could be another way to scale your SQ SQ 171 00:06:22,170 --> 00:06:24,430 if you have an Auto Scaling group reading from it, 172 00:06:24,430 --> 00:06:25,263 and so on. 173 00:06:25,263 --> 00:06:27,100 And finally, access policy, 174 00:06:27,100 --> 00:06:30,110 which is who can access the queue and how 175 00:06:30,110 --> 00:06:32,160 and encryption we have enabled, 176 00:06:32,160 --> 00:06:34,240 which is saying we use this encryption key 177 00:06:34,240 --> 00:06:36,340 to encrypt the messages at-rest. 178 00:06:36,340 --> 00:06:38,290 So that's it for the overview of SQS. 179 00:06:38,290 --> 00:06:40,560 We'll have a look at a few more options in a second 180 00:06:40,560 --> 00:06:43,860 but I hope that by now you understand better how this works 181 00:06:43,860 --> 00:06:45,810 and I will see you in the next lecture.