1 00:00:00,330 --> 00:00:03,660 ‫So let's practice using Amazon EventBridge. 2 00:00:03,660 --> 00:00:06,140 ‫And for this we're going to go into the EventBridge console, 3 00:00:06,140 --> 00:00:07,740 ‫and then you have lots of options. 4 00:00:07,740 --> 00:00:11,220 ‫But for now, we're just going to create an EventBridge rule. 5 00:00:11,220 --> 00:00:13,290 ‫So let's create this rule, and the rule name is 6 00:00:13,290 --> 00:00:15,817 ‫going to be called InvokeLambdaEveryHour. 7 00:00:16,773 --> 00:00:18,960 ‫Now, if you click on schedule 8 00:00:18,960 --> 00:00:21,330 ‫you will see that there is a new capability 9 00:00:21,330 --> 00:00:23,670 ‫of EventBridge called EventBridge Scheduler. 10 00:00:23,670 --> 00:00:25,740 ‫And this is what we're going to use to 11 00:00:25,740 --> 00:00:29,610 ‫create this Lambda function scheduler. 12 00:00:29,610 --> 00:00:31,650 ‫So we're going to go into another console 13 00:00:31,650 --> 00:00:32,580 ‫and this is a new thing. 14 00:00:32,580 --> 00:00:34,856 ‫So it's called InvokeLambdaEveryHour. 15 00:00:34,856 --> 00:00:36,859 ‫And then it's a one time schedule 16 00:00:36,859 --> 00:00:38,910 ‫it's a recurring schedule, excuse me, 17 00:00:38,910 --> 00:00:40,530 ‫and then it's going to be a rate based 18 00:00:40,530 --> 00:00:43,620 ‫and we can say that we want every one hour to 19 00:00:43,620 --> 00:00:46,440 ‫have our Lambda function being invoked. 20 00:00:46,440 --> 00:00:47,273 ‫Okay? 21 00:00:47,273 --> 00:00:48,600 ‫Then we can specify more options about 22 00:00:48,600 --> 00:00:50,220 ‫the timing that we want to. 23 00:00:50,220 --> 00:00:51,990 ‫Flexible time we say of, 24 00:00:51,990 --> 00:00:54,660 ‫so that's we, happen to execute it exactly 25 00:00:54,660 --> 00:00:56,220 ‫every one hour. 26 00:00:56,220 --> 00:00:58,200 ‫Target API could be different targets. 27 00:00:58,200 --> 00:01:00,903 ‫In this case we're going to use AWS Lambda, 28 00:01:01,740 --> 00:01:03,810 ‫and then we need to select Lambda function. 29 00:01:03,810 --> 00:01:06,840 ‫So I'll just choose my demo Lambda, that's it 30 00:01:06,840 --> 00:01:08,610 ‫and then click on next. 31 00:01:08,610 --> 00:01:10,560 ‫And then whether or not we want to enable the schedule 32 00:01:10,560 --> 00:01:11,910 ‫and retry in case of errors, 33 00:01:11,910 --> 00:01:14,160 ‫we'll just leave everything as the default. 34 00:01:14,160 --> 00:01:16,770 ‫Then a role is created for me automatically. 35 00:01:16,770 --> 00:01:20,010 ‫I click on next, and then I create this schedule. 36 00:01:20,010 --> 00:01:22,620 ‫So by creating this schedule, we're having actually 37 00:01:22,620 --> 00:01:27,420 ‫something called EventBridge scheduler to run a schedule 38 00:01:27,420 --> 00:01:29,100 ‫and invoke our Lamda function. 39 00:01:29,100 --> 00:01:30,960 ‫This used to be something that was part 40 00:01:30,960 --> 00:01:34,200 ‫of EventBridge rules, but now has been separated. 41 00:01:34,200 --> 00:01:35,662 ‫Even though if you wanted to, 42 00:01:35,662 --> 00:01:37,380 ‫you could create a rule, 43 00:01:37,380 --> 00:01:39,420 ‫choose a schedule, and then instead 44 00:01:39,420 --> 00:01:41,490 ‫of clicking here continue in EventBridge schedule 45 00:01:41,490 --> 00:01:43,740 ‫you could just click on continue to create rule, 46 00:01:43,740 --> 00:01:44,970 ‫And there you go. 47 00:01:44,970 --> 00:01:46,320 ‫But it's not the recommended way. 48 00:01:46,320 --> 00:01:48,420 ‫So I'll just show you the better way, 49 00:01:48,420 --> 00:01:50,280 ‫with EventBridge scheduler. 50 00:01:50,280 --> 00:01:51,600 ‫So here with EventBridge scheduler 51 00:01:51,600 --> 00:01:53,520 ‫my schedule is now created, 52 00:01:53,520 --> 00:01:56,070 ‫and this is going to invoke my Lamda function 53 00:01:56,070 --> 00:01:57,210 ‫every one hour. 54 00:01:57,210 --> 00:01:58,410 ‫So it's quite nice. 55 00:01:58,410 --> 00:01:59,670 ‫But what if you wanted it to react 56 00:01:59,670 --> 00:02:03,120 ‫to events happening within your accounts in EventBridge? 57 00:02:03,120 --> 00:02:06,183 ‫So again, back into rules, we're going to create a rule. 58 00:02:07,527 --> 00:02:10,797 ‫So let's call this rule, send notification for login, 59 00:02:11,820 --> 00:02:13,650 ‫and we'll make sure this rule is triggered whenever 60 00:02:13,650 --> 00:02:16,200 ‫someone does a login into AWS. 61 00:02:16,200 --> 00:02:19,264 ‫So we'll use a rule with an event pattern and click on next 62 00:02:19,264 --> 00:02:23,100 ‫and then we'll use AWS events in it. 63 00:02:23,100 --> 00:02:24,620 ‫And then amongst the events of AWS, 64 00:02:24,620 --> 00:02:26,400 ‫we need to filter them. 65 00:02:26,400 --> 00:02:29,010 ‫So let's have a look at the event source. 66 00:02:29,010 --> 00:02:29,940 ‫So we scroll down, sorry, 67 00:02:29,940 --> 00:02:32,460 ‫and then we'll need to find a service. 68 00:02:32,460 --> 00:02:34,590 ‫And then we'll just type in console 69 00:02:34,590 --> 00:02:37,500 ‫to find the AWS Console Sign-in. 70 00:02:37,500 --> 00:02:40,950 ‫And then the event type will be Sign-in events. 71 00:02:40,950 --> 00:02:43,710 ‫So any user that signs in 72 00:02:43,710 --> 00:02:46,980 ‫through the console will trigger this events 73 00:02:46,980 --> 00:02:49,080 ‫pattern, which is amazing. 74 00:02:49,080 --> 00:02:51,180 ‫And then for the targets, 75 00:02:51,180 --> 00:02:54,420 ‫we can, for example send this into an SNS topic. 76 00:02:54,420 --> 00:02:56,886 ‫For example, my demo-ccp topic 77 00:02:56,886 --> 00:03:00,840 ‫And this will ensure that events are sent, 78 00:03:00,840 --> 00:03:03,840 ‫as SNS notifications whenever someone logs in. 79 00:03:03,840 --> 00:03:08,670 ‫So next, next, and then create rule and we're good to go. 80 00:03:08,670 --> 00:03:10,860 ‫So now anyone, someone logs into your account 81 00:03:10,860 --> 00:03:13,770 ‫you'll receive an SNS notification and email. 82 00:03:13,770 --> 00:03:14,610 ‫One last I can do, 83 00:03:14,610 --> 00:03:17,060 ‫for example is EC2InstanceTerminateNotifications. 84 00:03:20,130 --> 00:03:21,900 ‫So say you wanted to be notified anytime, 85 00:03:21,900 --> 00:03:24,580 ‫and this two instance was terminated for whatever reason. 86 00:03:24,580 --> 00:03:25,980 ‫So again, we'll use a rule 87 00:03:25,980 --> 00:03:27,750 ‫with an event pattern, 88 00:03:27,750 --> 00:03:31,500 ‫and then we'll use every services 89 00:03:31,500 --> 00:03:35,409 ‫and then we'll use the EC2 service, 90 00:03:35,409 --> 00:03:38,370 ‫And then we'll have a look 91 00:03:38,370 --> 00:03:43,080 ‫at the EC2 instance State-change notification. 92 00:03:43,080 --> 00:03:45,330 ‫And then what state do we want to change to? 93 00:03:45,330 --> 00:03:47,370 ‫So here we're can apply a filter and say, 94 00:03:47,370 --> 00:03:49,260 ‫Hey, I want to apply to specific states, 95 00:03:49,260 --> 00:03:51,570 ‫the state being terminated. 96 00:03:51,570 --> 00:03:54,750 ‫So whenever an instance goes to a terminated states 97 00:03:54,750 --> 00:03:56,790 ‫then this rule will apply 98 00:03:56,790 --> 00:03:58,740 ‫and here will apply to any instance. 99 00:03:58,740 --> 00:04:01,030 ‫So you can see EventBridge is very powerful, 100 00:04:01,030 --> 00:04:03,543 ‫and the event patterns can be quite complicated. 101 00:04:04,380 --> 00:04:06,120 ‫So next, what do we want to invoke? 102 00:04:06,120 --> 00:04:08,580 ‫For example, we can invoke, again, SNS topic 103 00:04:08,580 --> 00:04:13,080 ‫and send a message into the demo CCP topic. 104 00:04:13,080 --> 00:04:16,770 ‫So we have one more rule, and now you start to get an idea 105 00:04:16,770 --> 00:04:19,110 ‫around the power of EventBridge. 106 00:04:19,110 --> 00:04:20,790 ‫So we created three rules. 107 00:04:20,790 --> 00:04:23,100 ‫Now before we heads up MDs, hands on 108 00:04:23,100 --> 00:04:25,590 ‫you need to disable them, for example 109 00:04:25,590 --> 00:04:29,580 ‫or you need to just delete them, whatever you prefer. 110 00:04:29,580 --> 00:04:31,530 ‫And lastly, as you can see 111 00:04:31,530 --> 00:04:32,940 ‫there can be different event bus, 112 00:04:32,940 --> 00:04:33,990 ‫as I told you, I'm not going to go 113 00:04:33,990 --> 00:04:36,270 ‫into it because it's two events for this CCP level. 114 00:04:36,270 --> 00:04:38,718 ‫But you can send your own events into EventBridge 115 00:04:38,718 --> 00:04:40,530 ‫or you can have partners 116 00:04:40,530 --> 00:04:43,350 ‫of AWS send events into EventBridge as well 117 00:04:43,350 --> 00:04:45,630 ‫for you to react to them in real time. 118 00:04:45,630 --> 00:04:46,500 ‫So that's it for this lecture, 119 00:04:46,500 --> 00:04:49,450 ‫I hope you liked it and I will see you in the next lecture.