1 00:00:00,960 --> 00:00:02,720 - [Alana] As Raf and I mentioned earlier, 2 00:00:02,720 --> 00:00:05,840 a pipeline is also programmable infrastructure. 3 00:00:05,840 --> 00:00:08,552 For example, take CodeDeploy. 4 00:00:08,552 --> 00:00:11,070 In Exercise 2 of the course, you created an application 5 00:00:11,070 --> 00:00:13,610 and a deployment group in the console manually. 6 00:00:13,610 --> 00:00:16,170 While you were doing that, I created an application 7 00:00:16,170 --> 00:00:19,350 and deployment group in a CloudFormation template. 8 00:00:19,350 --> 00:00:20,700 Here's what it looks like. 9 00:00:20,700 --> 00:00:22,840 We have our application declared at the top 10 00:00:22,840 --> 00:00:24,270 of the screen, here. 11 00:00:24,270 --> 00:00:27,470 We gave it a name and we also determined 12 00:00:27,470 --> 00:00:31,440 that we're deploying to Amazon EC2 as our compute platform. 13 00:00:31,440 --> 00:00:35,060 So overall, six lines of code to declare 14 00:00:35,060 --> 00:00:38,010 this resource. Not bad. 15 00:00:38,010 --> 00:00:40,670 If I scroll down, you can also see my deployment group 16 00:00:40,670 --> 00:00:42,550 and all of its properties. 17 00:00:42,550 --> 00:00:45,930 So, not only do we have the name of the deployment group, 18 00:00:45,930 --> 00:00:50,930 which application it belongs to, our configuration settings, 19 00:00:50,930 --> 00:00:53,710 and the deployment style, we also declare 20 00:00:53,710 --> 00:00:57,080 which EC2 instance we'll be deploying to, in this case, 21 00:00:57,080 --> 00:01:00,840 the instance that's tagged as CodePipelineBlog. 22 00:01:00,840 --> 00:01:04,970 And you can also see that it references the application, 23 00:01:04,970 --> 00:01:07,370 so that means when I run this template through 24 00:01:07,370 --> 00:01:10,400 the CloudFormation console, CloudFormation won't build 25 00:01:10,400 --> 00:01:13,940 the deployment group until after it builds the application. 26 00:01:13,940 --> 00:01:16,400 This makes sense because we need an application before 27 00:01:16,400 --> 00:01:18,050 we can create a deployment group. 28 00:01:18,890 --> 00:01:22,130 I also, in the same template, created a service role 29 00:01:22,130 --> 00:01:25,780 for CodeDeploy and an EC2 instance that has 30 00:01:25,780 --> 00:01:28,260 the CodeDeploy agents installed. 31 00:01:28,260 --> 00:01:32,330 So basically, everything you did in Exercise 1 and 2 32 00:01:32,330 --> 00:01:34,083 is now in this one template. 33 00:01:35,200 --> 00:01:37,430 To build off of all that, I also created all 34 00:01:37,430 --> 00:01:39,320 the other components of a pipeline, 35 00:01:39,320 --> 00:01:42,241 including CodeCommit and CodeBuild. 36 00:01:42,241 --> 00:01:44,716 And then, I created a code pipeline 37 00:01:46,992 --> 00:01:48,791 with a source stage, 38 00:01:50,910 --> 00:01:54,823 a deploy stage, and an acceptance test stage. 39 00:01:56,060 --> 00:01:57,720 So, let's see this run. 40 00:01:57,720 --> 00:01:59,800 I'll go to the AWS Management Console, 41 00:01:59,800 --> 00:02:01,512 search for CloudFormation, 42 00:02:07,859 --> 00:02:09,584 click Create stack, 43 00:02:15,610 --> 00:02:18,593 upload this template file called final_pipeline, 44 00:02:20,300 --> 00:02:21,433 and click Next. 45 00:02:23,020 --> 00:02:24,913 Here, I'll have to name the stack. 46 00:02:26,550 --> 00:02:28,513 I'll call it final-pipeline-stack, 47 00:02:31,980 --> 00:02:35,515 and then, I'll call the pipeline, final-pipeline. 48 00:02:39,280 --> 00:02:41,750 So, I'll go ahead and keep all the other defaults, 49 00:02:41,750 --> 00:02:46,323 click Next, keep the defaults again, and Next again, 50 00:02:48,870 --> 00:02:51,540 acknowledge that it might create IAM resources, 51 00:02:51,540 --> 00:02:53,073 and click Create stack. 52 00:02:55,020 --> 00:02:57,380 However, I've already created this CloudFormation stack 53 00:02:57,380 --> 00:02:59,240 earlier to save us some waiting time, 54 00:02:59,240 --> 00:03:01,220 which is why we got this error here, 55 00:03:01,220 --> 00:03:04,690 so I'll go ahead and cancel out of this, 56 00:03:04,690 --> 00:03:07,370 and click on the stack that I created earlier 57 00:03:07,370 --> 00:03:09,123 to find all of its resources. 58 00:03:10,080 --> 00:03:11,670 All right, so this CloudFormation template 59 00:03:11,670 --> 00:03:14,820 has already been provisioned and everything looks good, 60 00:03:14,820 --> 00:03:17,110 and if I click on this Resources tab here, 61 00:03:17,110 --> 00:03:19,640 we can see all the resources that were created 62 00:03:19,640 --> 00:03:21,660 when I ran this template. 63 00:03:21,660 --> 00:03:24,530 So, let's jump over to our pipeline that was created 64 00:03:24,530 --> 00:03:27,293 by this template by going to the CodePipeline console. 65 00:03:28,500 --> 00:03:31,780 As you can see, the pipeline has already started running, 66 00:03:31,780 --> 00:03:35,040 but here's what happened behind the scenes. 67 00:03:35,040 --> 00:03:37,710 If I go back to the template, when I wrote the code 68 00:03:37,710 --> 00:03:39,368 to create CodeCommit, 69 00:03:43,410 --> 00:03:44,951 as you can see here, 70 00:03:44,951 --> 00:03:48,900 I chose to propagate the repo with code from an S3 bucket. 71 00:03:48,900 --> 00:03:52,200 So, the commit was made, which kicked off the deployment, 72 00:03:52,200 --> 00:03:55,993 which if I go back to the console, I can see has succeeded. 73 00:03:57,140 --> 00:03:59,563 If I click on the Details and scroll down, 74 00:04:02,060 --> 00:04:04,300 I can find that the instance that it deployed 75 00:04:04,300 --> 00:04:07,690 to is right here, so I'll go ahead and click it, 76 00:04:07,690 --> 00:04:09,633 which brings me to the EC2 console. 77 00:04:12,260 --> 00:04:16,484 Select the instance, copy the public IP address, 78 00:04:16,484 --> 00:04:19,143 and paste it into my browser. 79 00:04:19,143 --> 00:04:21,435 And it looks like the deploy worked! 80 00:04:21,435 --> 00:04:22,983 My app is up and running. 81 00:04:24,500 --> 00:04:29,500 Okay. let's go back to the pipeline and see the final stage, 82 00:04:29,610 --> 00:04:31,590 the acceptance test. 83 00:04:31,590 --> 00:04:33,920 All this test does is access the instance 84 00:04:33,920 --> 00:04:36,620 and check if it can access the landing page. 85 00:04:36,620 --> 00:04:39,060 If we click Details of this stage, 86 00:04:39,060 --> 00:04:41,660 we can look at the commands we ran in the buildspec 87 00:04:42,760 --> 00:04:45,280 and the output of those commands. 88 00:04:45,280 --> 00:04:49,120 As you can see here, it pulls the HTML from our landing page 89 00:04:49,120 --> 00:04:51,630 and that's exactly what we wanted to accomplish, 90 00:04:51,630 --> 00:04:53,233 so everything looks good. 91 00:04:54,740 --> 00:04:57,760 So that's how I automated a pipeline with CloudFormation. 92 00:04:57,760 --> 00:04:59,450 If you're looking for this template to download 93 00:04:59,450 --> 00:05:02,210 so you can try it yourself, I'll be providing it to you 94 00:05:02,210 --> 00:05:04,530 in Exercise 3 of the course, along with 95 00:05:04,530 --> 00:05:08,810 the buildspec file, the AppSpec file, and the app itself. 96 00:05:08,810 --> 00:05:10,890 Now, if I wanted to take it a step further, 97 00:05:10,890 --> 00:05:13,860 I could change the HTML file and commit it to my repo, 98 00:05:13,860 --> 00:05:15,710 kicking off the pipeline once again, 99 00:05:15,710 --> 00:05:18,030 and see my changes in real time, 100 00:05:18,030 --> 00:05:20,630 but you'll be doing that in the next exercise, 101 00:05:20,630 --> 00:05:21,863 so see you soon.