<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nick Goko</title>
    <description>The latest articles on DEV Community by Nick Goko (@nickgoko).</description>
    <link>https://dev.to/nickgoko</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1161215%2F6ce25031-c260-44fd-be7c-1872c3fee7bb.jpeg</url>
      <title>DEV Community: Nick Goko</title>
      <link>https://dev.to/nickgoko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nickgoko"/>
    <language>en</language>
    <item>
      <title>Provisioning with AWS CloudFormation</title>
      <dc:creator>Nick Goko</dc:creator>
      <pubDate>Tue, 16 Jan 2024 10:22:36 +0000</pubDate>
      <link>https://dev.to/nickgoko/provisioning-with-aws-cloudformation-1ngi</link>
      <guid>https://dev.to/nickgoko/provisioning-with-aws-cloudformation-1ngi</guid>
      <description>&lt;h2&gt;
  
  
  ProvisioningAWS CloudFormation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S2-S2664--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/rwljpqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S2-S2664--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/rwljpqq.png" alt="" width="358" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SswTosXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/9i5Drss.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SswTosXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/9i5Drss.png" alt="" width="800" height="148"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Create a VPC &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a text editor and create an empty YAML File called&amp;nbsp;&lt;code&gt;sfid-cfn-vpc.yaml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy and paste the sample CloudFormation template below that defines a VPC and save the file.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Create a VPC&lt;/span&gt;
  &lt;span class="na"&gt;MainVPC&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::VPC&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;CidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10.0.0.0/16&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Navigate to CloudFormation console. Choose "Template is ready"&lt;/li&gt;
&lt;li&gt;Upload the yaml file you created above. &lt;/li&gt;
&lt;li&gt;Name the stack &lt;code&gt;SFID-CFN-VPC&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Leave Configure stack options on default.Click Next.&lt;/li&gt;
&lt;li&gt;Submit the stack and refresh until the creation is complete on events. &lt;/li&gt;
&lt;li&gt;Open you VPC console to check if the VPC was created using AWS CloudFormation. &lt;/li&gt;
&lt;li&gt;Now that we created a simple VPC, we need to enable the DNS Options and name the VPC “VPC for SFID CFN

&lt;ul&gt;
&lt;li&gt;Add the following to the bottom of the YAML File called&amp;nbsp;&lt;em&gt;sfid-cfn-vpc.yaml&lt;/em&gt;&amp;nbsp;and save the file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="na"&gt;EnableDnsHostnames&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
      &lt;span class="na"&gt;EnableDnsSupport&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;VPC for SFID CFN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Select the "SFID-CFN-VPC" stack name in the stack list.&lt;/li&gt;
&lt;li&gt;Click on Update button &amp;amp; replace current template. Upload the update template file. &lt;/li&gt;
&lt;li&gt;You can leave Parameters since nothing was defined and Click&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can leave Configure stack options default, click&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Check the Changes list under the Change set preview; which shows how the changes can affect the running resources, for this case, it won’t affect our template.&lt;/li&gt;
&lt;li&gt;Click&amp;nbsp;&lt;strong&gt;Submit&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can click the refresh button a few times until you see in the status&amp;nbsp;&lt;em&gt;&lt;strong&gt;UPDATE_COMPLETE&lt;/strong&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Navigate to the&amp;nbsp;&lt;a href="https://us-east-2.console.aws.amazon.com/vpc/"&gt;AWS VPC Console&lt;/a&gt;&amp;nbsp;&amp;nbsp;to check the VPC Tag and DNS options enabled using AWS CloudFormation.
&amp;gt;[!highlight]
&amp;gt;Before the update the VPC didn't have a name just the CIDR block.
&amp;gt;Now it has enabled DNS options
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XtF9TQQD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/LUjMrzq.png" alt="" width="719" height="374"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EfXVLWeV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/zQ1xQZx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EfXVLWeV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/zQ1xQZx.png" alt="" width="684" height="353"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Create Internet Gateway&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the following to the bottom of the YAML File called&amp;nbsp;&lt;em&gt;sfid-cfn-vpc.yaml&lt;/em&gt;&amp;nbsp;and save the file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Create and attach InternetGateway&lt;/span&gt;
  &lt;span class="na"&gt;InternetGateway&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::InternetGateway&lt;/span&gt;
    &lt;span class="na"&gt;DependsOn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;

  &lt;span class="na"&gt;AttachIGW&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::VPCGatewayAttachment&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;InternetGatewayId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;InternetGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run the same steps you did when you last update the yaml file.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zzCOQYtA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Jdwjp4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zzCOQYtA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Jdwjp4j.png" alt="" width="647" height="370"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Z3nbOqA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/HEb0mBm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Z3nbOqA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/HEb0mBm.png" alt="" width="710" height="354"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Create First Subnet&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the following to the bottom of the yaml file. Save the file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Create First Subnet&lt;/span&gt;
  &lt;span class="na"&gt;FirstSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::Subnet&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;CidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10.0.10.0/24&lt;/span&gt;
      &lt;span class="na"&gt;AvailabilityZone&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;us-east-2a"&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Subnet A - SFID&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Update the stack with new saved template.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3qGn7Xj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/0AjcayX.png" alt="" width="677" height="334"&gt;
Create Additional Subnet
Add the following to the the bottom of the YAML file called sfid-cfn-vpc.yaml and save the file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Creating additional subnet&lt;/span&gt;
  &lt;span class="na"&gt;SecondSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::Subnet&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;CidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10.0.20.0/24&lt;/span&gt;
      &lt;span class="na"&gt;AvailabilityZone&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;us-east-2b"&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Subnet B - SFID&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Update the stack list.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fIE69WpH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/ZI8nnKq.png" alt="" width="717" height="384"&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pKQ_U5EE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/bys3F9T.png" alt="" width="688" height="348"&gt;
Setting up routing table
&lt;/li&gt;
&lt;li&gt;Add the following to the bottom the YAML file again
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Create and Set Public Route Table&lt;/span&gt;
  &lt;span class="na"&gt;PublicRouteTable&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::RouteTable&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Route Table&lt;/span&gt;

  &lt;span class="na"&gt;PublicRoute&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::Route'&lt;/span&gt;
    &lt;span class="na"&gt;DependsOn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AttachIGW&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;RouteTableId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicRouteTable&lt;/span&gt;
      &lt;span class="na"&gt;DestinationCidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0.0.0.0/0&lt;/span&gt;
      &lt;span class="na"&gt;GatewayId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;InternetGateway&lt;/span&gt;

  &lt;span class="c1"&gt;# Associate Public Subnets to Public Route Table&lt;/span&gt;
  &lt;span class="na"&gt;PublicSubnet1RouteTableAssociation&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SubnetRouteTableAssociation'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;FirstSubnet&lt;/span&gt;
      &lt;span class="na"&gt;RouteTableId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicRouteTable&lt;/span&gt;

  &lt;span class="na"&gt;PublicSubnet2RouteTableAssociation&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SubnetRouteTableAssociation'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;SecondSubnet&lt;/span&gt;
      &lt;span class="na"&gt;RouteTableId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicRouteTable&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Update the stack just as you have before. &lt;/li&gt;
&lt;li&gt;View the changes.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zwI3jrPu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/an5tt8Y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zwI3jrPu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/an5tt8Y.png" alt="" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the VPC console and check the public routing table and association with 2 subnets. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I3WQiWl6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/TP19GK8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I3WQiWl6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/TP19GK8.png" alt="" width="728" height="356"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Q0o5RZ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/gIenxy2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Q0o5RZ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/gIenxy2.png" alt="" width="684" height="358"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Create Security Group&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the following to the bottom of the YAML file
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Create Security Group for the following:&lt;/span&gt;
  &lt;span class="na"&gt;MainSecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::SecurityGroup&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;GroupDescription&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Security Group for Web Server&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;SecurityGroupIngress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;IpProtocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tcp&lt;/span&gt;
        &lt;span class="na"&gt;FromPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
        &lt;span class="na"&gt;ToPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
        &lt;span class="na"&gt;CidrIp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0.0.0.0/0&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Server Security Group - SFID&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V-Lw_KUp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/dwWkvUe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V-Lw_KUp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/dwWkvUe.png" alt="" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to security groups on the left side of the screen.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nw3AuXXr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/F0lY7xo.png" alt="" width="729" height="426"&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cx8wg6rG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Z4opF1A.png" alt="" width="693" height="346"&gt;
&lt;/li&gt;
&lt;li&gt;On the last step we are going to add a description to the CloudFormation template and Add outputs.&lt;/li&gt;
&lt;li&gt;Add the following to the top of the YAML file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Introduction to CloudFormation SFID - Virtual Private Cloud (VPC)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add the following to the bottom of the YAML file.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Outputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;MainSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;FirstSubnet&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Subnet ID with Direct Internet Route&lt;/span&gt;

  &lt;span class="na"&gt;MainSecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainSecurityGroup&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Security Group ID for the Web Server&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Now update the “SFID-CFN-VPC” Stack Name in the Stack List&lt;/li&gt;
&lt;li&gt;The changes do not appear on change set preview but description does appear on the template section.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JJAOE3KR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/nn4qAk0.png" alt="" width="667" height="379"&gt;
Once you submit, refresh the stack &amp;amp; navigate to the output section. Same section you find the Events section
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tJ_UPUr3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/xAfzNRM.png" alt="" width="800" height="420"&gt;
&amp;gt;[!summary] Summary Lab 1
&amp;gt;We divided our CloudFormation Template into the following and provided a recap to the CloudFormation Template:- Created a VPC, tagged it by providing a name and sat up the DNS Options
&amp;gt;- Created an Internet Gateway and attached it to the VPC
&amp;gt;- Created two Subnets in the VPC
&amp;gt;- Created a public Route Table and Associated the two subnets
&amp;gt;- Created a Security Group which allows Inbound Access on HTTP for Lab 2
&amp;gt;- Added a Description and Outputs to better understands the template.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Now that we laid down for the networking portion for this lab, we will move to our next Lab to set up an EC2 Instance and act as web server using CloudFormation.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--infN-Ts1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/I6dKsNs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--infN-Ts1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/I6dKsNs.png" alt="" width="800" height="352"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Here is the complete yaml file.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Introduction to CloudFormation SFID - Virtual Private Cloud (VPC)&lt;/span&gt;
&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

  &lt;span class="c1"&gt;# Create a VPC&lt;/span&gt;
  &lt;span class="na"&gt;MainVPC&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::VPC&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;CidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10.0.0.0/16&lt;/span&gt;
      &lt;span class="na"&gt;EnableDnsHostnames&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
      &lt;span class="na"&gt;EnableDnsSupport&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;VPC for SFID CFN&lt;/span&gt;

&lt;span class="c1"&gt;# Create and attach InternetGateway&lt;/span&gt;
  &lt;span class="na"&gt;InternetGateway&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::InternetGateway&lt;/span&gt;
    &lt;span class="na"&gt;DependsOn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;

  &lt;span class="na"&gt;AttachIGW&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::VPCGatewayAttachment&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;InternetGatewayId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;InternetGateway&lt;/span&gt;

&lt;span class="c1"&gt;# Create First Subnet&lt;/span&gt;
  &lt;span class="na"&gt;FirstSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::Subnet&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;CidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10.0.10.0/24&lt;/span&gt;
      &lt;span class="na"&gt;AvailabilityZone&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;us-east-2a"&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Subnet A - SFID&lt;/span&gt;

&lt;span class="c1"&gt;# Creating additional subnet&lt;/span&gt;
  &lt;span class="na"&gt;SecondSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::Subnet&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;CidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10.0.20.0/24&lt;/span&gt;
      &lt;span class="na"&gt;AvailabilityZone&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;us-east-2b"&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Subnet B - SFID&lt;/span&gt;

&lt;span class="c1"&gt;# Create and Set Public Route Table&lt;/span&gt;
  &lt;span class="na"&gt;PublicRouteTable&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::RouteTable&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Route Table&lt;/span&gt;

  &lt;span class="na"&gt;PublicRoute&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::Route'&lt;/span&gt;
    &lt;span class="na"&gt;DependsOn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AttachIGW&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;RouteTableId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicRouteTable&lt;/span&gt;
      &lt;span class="na"&gt;DestinationCidrBlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0.0.0.0/0&lt;/span&gt;
      &lt;span class="na"&gt;GatewayId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;InternetGateway&lt;/span&gt;

  &lt;span class="c1"&gt;# Associate Public Subnets to Public Route Table&lt;/span&gt;
  &lt;span class="na"&gt;PublicSubnet1RouteTableAssociation&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SubnetRouteTableAssociation'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;FirstSubnet&lt;/span&gt;
      &lt;span class="na"&gt;RouteTableId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicRouteTable&lt;/span&gt;

  &lt;span class="na"&gt;PublicSubnet2RouteTableAssociation&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SubnetRouteTableAssociation'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;SecondSubnet&lt;/span&gt;
      &lt;span class="na"&gt;RouteTableId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicRouteTable&lt;/span&gt;

  &lt;span class="c1"&gt;# Create Security Group for the following:&lt;/span&gt;
  &lt;span class="na"&gt;MainSecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::SecurityGroup&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;GroupDescription&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Security Group for Web Server&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainVPC&lt;/span&gt;
      &lt;span class="na"&gt;SecurityGroupIngress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;IpProtocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tcp&lt;/span&gt;
        &lt;span class="na"&gt;FromPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
        &lt;span class="na"&gt;ToPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
        &lt;span class="na"&gt;CidrIp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0.0.0.0/0&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
        &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Server Security Group - SFID&lt;/span&gt;

&lt;span class="na"&gt;Outputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;MainSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;FirstSubnet&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Public Subnet ID with Direct Internet Route&lt;/span&gt;

  &lt;span class="na"&gt;MainSecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MainSecurityGroup&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Security Group ID for the Web Server&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Setting up an EC2 instance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a text editor and create an empty YAML file called &lt;code&gt;sfid-cfn-EC2.yaml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy and paste the following yaml code and save the file. Note the ImageId is copied from
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="c1"&gt;# Create EC2 Linux&lt;/span&gt;
  &lt;span class="na"&gt;WebServerInstance&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::Instance&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;ImageId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ami-0331ebbf81138e4de"&lt;/span&gt;
      &lt;span class="na"&gt;InstanceType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;t3a.micro&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Open the AWS CloudFormation Console. Click on &lt;em&gt;Create stack&lt;/em&gt;. Upload a template file. Select the yaml file you just created.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name the stack &lt;code&gt;SFID-CFN-EC2&lt;/code&gt;. You can leave Configure stack options default. Submit. Refresh a few times until you see in the status &lt;em&gt;CREATE_COMPLETE&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f_tw0xWK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/c6bnpqN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f_tw0xWK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/c6bnpqN.png" alt="" width="400" height="173"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the AWS EC2 Console to check the EC2 created using AWS CloudFormation.&lt;br&gt;&lt;br&gt;
Tag and pass User Data to EC2 Instance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the following to the bottom of the YAML file called &lt;code&gt;sfid-cfn-EC2.yaml&lt;/code&gt; and save the file.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
            &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Server for IMD&lt;/span&gt;
      &lt;span class="na"&gt;UserData&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
        &lt;span class="na"&gt;Fn::Base64&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;#!/bin/sh&lt;/span&gt;
          &lt;span class="s"&gt;yum -y install httpd&lt;/span&gt;
          &lt;span class="s"&gt;chkconfig httpd on&lt;/span&gt;
          &lt;span class="s"&gt;systemctl start httpd&lt;/span&gt;
          &lt;span class="s"&gt;echo '&amp;lt;html&amp;gt;&amp;lt;center&amp;gt;&amp;lt;text="#252F3E" style="font-family: Amazon Ember"&amp;gt;&amp;lt;h1&amp;gt;AWS CloudFormation is Fun !!!&amp;lt;/h1&amp;gt;' &amp;gt; /var/www/html/index.html&lt;/span&gt;
          &lt;span class="s"&gt;echo '&amp;lt;h3&amp;gt;&amp;lt;img src="https://d0.awsstatic.com/logos/powered-by-aws.png"&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;/html&amp;gt;' &amp;gt;&amp;gt; /var/www/html/index.html&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Select the "SFID-CFN-EC2" stack name in the stack list and update the stack.&lt;/li&gt;
&lt;li&gt;You can leave Parameters since nothing was defined and Click&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can leave Configure stack options default, click&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Check the Changes list under the Change set preview; which shows how the changes can affect the running resources, for this case, it won’t affect our template. Click&amp;nbsp;&lt;strong&gt;Submit&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Navigate to the&amp;nbsp;&lt;a href="https://us-east-2.console.aws.amazon.com/ec2"&gt;AWS EC2 Console&lt;/a&gt;&amp;nbsp;&amp;nbsp;to check the EC2 Name Tag and access to the Website other characteristics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Paying attention to the EC2 Instance settings, you will notice that the Instance was launched in the default VPC, using a default Security Group which doesn’t allow traffic to the internet and User Data Script running only during Launch of the instance in our case, this is not the end goal for our lab.&lt;br&gt;&lt;br&gt;
Terminate EC2 instance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the AWS CloudFormation Stacks Console&lt;/li&gt;
&lt;li&gt;We shall delete the &lt;code&gt;SFID-CFN-EC2&lt;/code&gt; stack
Launch EC2 instance in the lab VPC 
&lt;/li&gt;
&lt;li&gt;Now that we have a better understanding on how the AWS CloudFormation Template works and setting needed for a web host to launch with the proper settings Let’s create an EC2 Instance in the proper VPC using CloudFormation&lt;/li&gt;
&lt;li&gt;Add the following to the top of the yaml file called &lt;code&gt;sfid-cfn-ec2.ymal&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Parameters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;PublicSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Select a Public Subnet created in the "VPC for SFID CFN" Lab (Hint - Search for "SFID")&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::Subnet::Id'&lt;/span&gt;
  &lt;span class="na"&gt;SecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Select the Security Group created in the "VPC for SFID CFN" Lab (Hint - Search for "SFID")&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SecurityGroup::Id'&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Add the following to the bottom&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="na"&gt;NetworkInterfaces&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;GroupSet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;SecurityGroup&lt;/span&gt;
          &lt;span class="na"&gt;AssociatePublicIpAddress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
          &lt;span class="na"&gt;DeviceIndex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0'&lt;/span&gt;
          &lt;span class="na"&gt;DeleteOnTermination&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
          &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicSubnet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create stack. choose &lt;em&gt;Template is ready&lt;/em&gt;. Upload a &lt;em&gt;template file&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Recommend stack name &lt;code&gt;SFID-CFN-EC2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select any of the&amp;nbsp;&lt;em&gt;&lt;strong&gt;Public Subnet A or B&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;created in the "VPC for SFID CFN" Lab&amp;nbsp;&lt;em&gt;&lt;strong&gt;(Hint - Search for "SFID")&lt;/strong&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Select&amp;nbsp;&lt;em&gt;&lt;strong&gt;webserver-sg&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;created in the "VPC for SFID CFN" Lab&amp;nbsp;_&lt;strong&gt;(Hint - Search for "SFID")&lt;/strong&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B40LECio--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/2Qw8ML6.png" alt="" width="644" height="589"&gt;
&lt;/li&gt;
&lt;li&gt;Leave Configure stack options on default. Click &lt;em&gt;Next&lt;/em&gt;. Submit. Click refresh until you see the status _CREATE_COMPLETE&lt;/li&gt;
&lt;li&gt;When you open the AWS EC2 Console. Check the security and Networking tab on the EC2 console and you will notice that instance was launched based on the information we selected in the "Parameters" prompt.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PYpv-zOk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/mQPO5C4.png" alt="" width="700" height="378"&gt;
On the last step. You can add add-ons . Add a description to the CloudFormation Template and Add Outputs.
Add the following to the top of the YAML file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Introduction to CloudFormation SFID - Elastic Compute Cloud (EC2)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following to the bottom of the YAML file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Outputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;PublicDNS&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Join&lt;/span&gt; 
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://'&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!GetAtt&lt;/span&gt; 
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;WebServerInstance&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PublicDnsName&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Host Public URL&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the stack and upload the update yaml file. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[!summary] Lab 2 Summary&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;This is the complete yaml code for lab2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Introduction to CloudFormation SFID - Elastic Compute Cloud (EC2)&lt;/span&gt;

&lt;span class="na"&gt;Parameters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;PublicSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Select a Public Subnet created in the "VPC for SFID CFN" Lab (Hint - Search for "SFID")&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::Subnet::Id'&lt;/span&gt;
  &lt;span class="na"&gt;SecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Select the Security Group created in the "VPC for SFID CFN" Lab (Hint - Search for "SFID")&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SecurityGroup::Id'&lt;/span&gt;

&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="c1"&gt;# Create EC2 Linux&lt;/span&gt;
  &lt;span class="na"&gt;WebServerInstance&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::EC2::Instance&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;ImageId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ami-0331ebbf81138e4de"&lt;/span&gt;
      &lt;span class="na"&gt;InstanceType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;t3a.micro&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
            &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Server for IMD&lt;/span&gt;
      &lt;span class="na"&gt;UserData&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
        &lt;span class="na"&gt;Fn::Base64&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;#!/bin/sh&lt;/span&gt;
          &lt;span class="s"&gt;yum -y install httpd&lt;/span&gt;
          &lt;span class="s"&gt;chkconfig httpd on&lt;/span&gt;
          &lt;span class="s"&gt;systemctl start httpd&lt;/span&gt;
          &lt;span class="s"&gt;echo '&amp;lt;html&amp;gt;&amp;lt;center&amp;gt;&amp;lt;text="#252F3E" style="font-family: Amazon Ember"&amp;gt;&amp;lt;h1&amp;gt;AWS CloudFormation is Fun !!!&amp;lt;/h1&amp;gt;' &amp;gt; /var/www/html/index.html&lt;/span&gt;
          &lt;span class="s"&gt;echo '&amp;lt;h3&amp;gt;&amp;lt;img src="https://d0.awsstatic.com/logos/powered-by-aws.png"&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;/html&amp;gt;' &amp;gt;&amp;gt; /var/www/html/index.html&lt;/span&gt;
      &lt;span class="na"&gt;NetworkInterfaces&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;GroupSet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;SecurityGroup&lt;/span&gt;
          &lt;span class="na"&gt;AssociatePublicIpAddress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
          &lt;span class="na"&gt;DeviceIndex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0'&lt;/span&gt;
          &lt;span class="na"&gt;DeleteOnTermination&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
          &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicSubnet&lt;/span&gt;

&lt;span class="na"&gt;Outputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;PublicDNS&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Join&lt;/span&gt; 
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://'&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!GetAtt&lt;/span&gt; 
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;WebServerInstance&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PublicDnsName&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Host Public URL&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Om0T84O---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/8RLrWN5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Om0T84O---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/8RLrWN5.png" alt="" width="677" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering Conversations with ChatGPT: A Guide to Prominent Prompting Techniques</title>
      <dc:creator>Nick Goko</dc:creator>
      <pubDate>Tue, 16 Jan 2024 10:21:36 +0000</pubDate>
      <link>https://dev.to/nickgoko/mastering-conversations-with-chatgpt-a-guide-to-prominent-prompting-techniques-9dl</link>
      <guid>https://dev.to/nickgoko/mastering-conversations-with-chatgpt-a-guide-to-prominent-prompting-techniques-9dl</guid>
      <description>&lt;p&gt;Introduction:&lt;/p&gt;

&lt;p&gt;In the realm of AI-driven conversations, unlocking the full potential of ChatGPT requires not only knowledge but also effective prompting techniques. In this article, we will delve into three powerful techniques: the Cognitive Verifier pattern, the Infinite Generation pattern, and the Refusal Breaker pattern. Our journey will be enriched with code examples and a personal touch to make these techniques more accessible and educational.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Cognitive Verifier Pattern: Enhancing Reasoning&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intent and Context:&lt;/strong&gt; The Cognitive Verifier pattern encourages us to break down complex questions into smaller, more manageable parts. This technique is akin to a detective gathering clues to solve a bigger mystery.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; Imagine you're exploring quantum physics, a domain full of complexity. You might start with a broad question: "Explain quantum entanglement." This pattern motivates you to subdivide it: "What is quantum entanglement?" "How does it relate to particle physics?" Each answer forms a piece of the puzzle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Structure and Key Ideas:&lt;/strong&gt; For instance, let's explore the concept of quantum entanglement. We could begin with:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt: "What is quantum entanglement?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then further subdivide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt: "How does quantum entanglement affect particle behavior?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By combining the answers to these questions, you construct a comprehensive understanding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Infinite Generation Pattern: Continuous Output&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intent and Context:&lt;/strong&gt; Imagine you're designing a text-based game or generating creative content. The Infinite Generation pattern allows you to maintain a continuous flow of content without repetitive prompts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; This technique's motivation is simple: to save time and effort while ensuring a consistent output. You can specify how many outputs you want or even request an infinite stream.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Structure and Key Ideas:&lt;/strong&gt; Suppose you're developing a story generator. You might start with:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt: "Create a story about an adventurer's quest."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, with the Infinite Generation pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Generate output forever, 3 output(s) at a time.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, your narrative flows seamlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Refusal Breaker Pattern: Enhancing Answer Quality&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intent and Context:&lt;/strong&gt; Occasionally, ChatGPT may not provide a satisfactory answer. The Refusal Breaker pattern addresses this by explaining why and offering alternative phrasings for the question.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; This pattern aims to enhance the quality of responses. Think of it as a helpful librarian guiding you to the right bookshelf when the desired book isn't on display.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Structure and Key Ideas:&lt;/strong&gt; For instance, if you inquire about the meaning of life:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User: What is the meaning of life?
ChatGPT: As an AI, I can't provide personal beliefs. Try asking, "What are some philosophical perspectives on life's purpose?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pattern empowers you to refine your questions effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Personal Touch and Code Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine you're teaching programming with ChatGPT. You could employ the Cognitive Verifier pattern to explore topics step by step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Explain Python functions.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What are the parameters in Python functions?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each subdivision helps students grasp complex concepts. Similarly, you can use Infinite Generation to create coding exercises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Generate&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="n"&gt;forever&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nf"&gt;output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps students engaged with continuous challenges.&lt;/p&gt;

&lt;p&gt;The Refusal Breaker pattern, meanwhile, aids in clarifying doubts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User: How do I fix a syntax error in my Python code?
ChatGPT: To address syntax errors in Python, try asking, "What are common Python syntax mistakes and how to fix them?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Incorporating these techniques and code examples into your interactions with ChatGPT can make learning and problem-solving more interactive and enjoyable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your journey with ChatGPT, these prompting techniques are like the keys to a treasure trove of knowledge and creativity. Whether you're seeking clarity, continuous content, or refined answers, they empower you to make the most of your conversations. By embracing them, you'll uncover the full potential of ChatGPT as an educational companion and problem-solving partner.&lt;/p&gt;

</description>
      <category>promptengineering</category>
      <category>productivity</category>
      <category>ai</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>EC2 Auto Scaling</title>
      <dc:creator>Nick Goko</dc:creator>
      <pubDate>Tue, 16 Jan 2024 10:18:39 +0000</pubDate>
      <link>https://dev.to/nickgoko/ec2-auto-scaling-5aia</link>
      <guid>https://dev.to/nickgoko/ec2-auto-scaling-5aia</guid>
      <description>&lt;p&gt;We start by creating an Amazon Machine Image (AMI) from a web host created with CloudFormation.&lt;br&gt;&lt;br&gt;
Then continue to creating a launch template and setting up the web host within an auto scaling group behind an Application Load Balancer (ALB).&lt;br&gt;&lt;br&gt;
The end result will be an auto scaling group behind a load balancer that scales based on CPU utilization of the hosts.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fcXAItIY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/xo9y4jN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fcXAItIY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/xo9y4jN.png" alt="" width="282" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites 
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to AWS Console and search for &lt;code&gt;CloudFormation&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--prQ2tJu2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/oO4gyKY.png" alt="" width="800" height="228"&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iANoAMs8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/CJHhihy.png" alt="" width="800" height="144"&gt;
&lt;/li&gt;
&lt;li&gt;Create Stack &lt;/li&gt;
&lt;li&gt;Under template source select &lt;em&gt;Upload a template file&lt;/em&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QdRah_Z2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/UdzAV3p.png" alt="" width="800" height="567"&gt;
&lt;/li&gt;
&lt;li&gt;Upload this EC2-Auto-Scaling-Lab.yaml file then click Next. 
&amp;gt;[!code]- Read through and use this yaml code to create a &lt;em&gt;EC2-Auto-Scaling-Lab.yaml&lt;/em&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;AWSTemplateFormatVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2010-09-09&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;This CloudFormation template will produce the web host to build your AMI&lt;/span&gt;
&lt;span class="na"&gt;Parameters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;AmiID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::SSM::Parameter::Value&amp;lt;AWS::EC2::Image::Id&amp;gt;&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;The AMI ID - Leave as Default&lt;/span&gt;
    &lt;span class="na"&gt;Default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'&lt;/span&gt;
  &lt;span class="na"&gt;InstanceType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Web Host EC2 instance type&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;String&lt;/span&gt;
    &lt;span class="na"&gt;Default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;m5.large&lt;/span&gt;
    &lt;span class="na"&gt;AllowedValues&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;t2.micro&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;m5.large&lt;/span&gt;
  &lt;span class="na"&gt;MyVPC&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Select Your VPC (Most Likely the Default VPC)&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::VPC::Id'&lt;/span&gt;
  &lt;span class="na"&gt;MyIP&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Please enter your local IP address followed by a /32 to restrict HTTP(80) access. To find your IP use an internet search phrase "What is my IP".&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;String&lt;/span&gt;
    &lt;span class="na"&gt;AllowedPattern&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(32))$'&lt;/span&gt;
    &lt;span class="na"&gt;ConstraintDescription&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Must be a valid IP CIDR range of the form x.x.x.x/32&lt;/span&gt;
  &lt;span class="na"&gt;PublicSubnet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Select a Public Subnet from your VPC that has access to the internet&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::Subnet::Id'&lt;/span&gt;

&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;WebhostSecurityGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::SecurityGroup'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VpcId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MyVPC&lt;/span&gt;
      &lt;span class="na"&gt;GroupName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="s"&gt;${AWS::StackName} - Website Security Group&lt;/span&gt;
      &lt;span class="na"&gt;GroupDescription&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Allow Access to the Webhost on Port &lt;/span&gt;&lt;span class="m"&gt;80&lt;/span&gt;
      &lt;span class="na"&gt;SecurityGroupIngress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;IpProtocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tcp&lt;/span&gt;
          &lt;span class="na"&gt;FromPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;80'&lt;/span&gt;
          &lt;span class="na"&gt;ToPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;80'&lt;/span&gt;
          &lt;span class="na"&gt;CidrIp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;MyIP&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
          &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="s"&gt;${AWS::StackName} - Web Host Security Group&lt;/span&gt;
  &lt;span class="na"&gt;WebServerInstance&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;AWS::EC2::Instance'&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;ImageId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;AmiID&lt;/span&gt;
      &lt;span class="na"&gt;InstanceType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;InstanceType&lt;/span&gt;
      &lt;span class="na"&gt;Tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Name&lt;/span&gt;
          &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="s"&gt;${AWS::StackName}&lt;/span&gt;
      &lt;span class="na"&gt;NetworkInterfaces&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;GroupSet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;WebhostSecurityGroup&lt;/span&gt;
          &lt;span class="na"&gt;AssociatePublicIpAddress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
          &lt;span class="na"&gt;DeviceIndex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0'&lt;/span&gt;
          &lt;span class="na"&gt;DeleteOnTermination&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
          &lt;span class="na"&gt;SubnetId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Ref&lt;/span&gt; &lt;span class="s"&gt;PublicSubnet&lt;/span&gt;
      &lt;span class="na"&gt;UserData&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
        &lt;span class="na"&gt;Fn::Base64&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="kt"&gt;!Sub&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;#!/bin/bash -xe&lt;/span&gt;
          &lt;span class="s"&gt;yum -y update&lt;/span&gt;
          &lt;span class="s"&gt;yum -y install httpd&lt;/span&gt;
          &lt;span class="s"&gt;amazon-linux-extras install php7.2&lt;/span&gt;
          &lt;span class="s"&gt;yum -y install php-mbstring&lt;/span&gt;
          &lt;span class="s"&gt;yum -y install telnet&lt;/span&gt;
          &lt;span class="s"&gt;case $(ps -p 1 -o comm | tail -1) in&lt;/span&gt;
          &lt;span class="s"&gt;systemd) systemctl enable --now httpd ;;&lt;/span&gt;
          &lt;span class="s"&gt;init) chkconfig httpd on; service httpd start ;;&lt;/span&gt;
          &lt;span class="s"&gt;*) echo "Error starting httpd (OS not using init or systemd)." 2&amp;gt;&amp;amp;1&lt;/span&gt;
          &lt;span class="s"&gt;esac&lt;/span&gt;
          &lt;span class="s"&gt;if [ ! -f /var/www/html/ec2-web-host.tar.gz ]; then&lt;/span&gt;
          &lt;span class="s"&gt;cd /var/www/html&lt;/span&gt;
          &lt;span class="s"&gt;wget https://workshop-objects.s3.amazonaws.com/general-id/ec2_auto_scaling/ec2-web-host.tar&lt;/span&gt;
          &lt;span class="s"&gt;tar xvf ec2-web-host.tar&lt;/span&gt;
          &lt;span class="s"&gt;fi&lt;/span&gt;
          &lt;span class="s"&gt;yum -y update&lt;/span&gt;
&lt;span class="na"&gt;Outputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;PublicIP&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Join&lt;/span&gt; 
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://'&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!GetAtt&lt;/span&gt; 
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;WebServerInstance&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PublicIp&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Newly created webhost Public IP&lt;/span&gt;
  &lt;span class="na"&gt;PublicDNS&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;!Join&lt;/span&gt; 
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://'&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="kt"&gt;!GetAtt&lt;/span&gt; 
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;WebServerInstance&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PublicDnsName&lt;/span&gt;
    &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Newly created webhost Public DNS URL&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Specify Stack Details&lt;/li&gt;
&lt;li&gt;After that you will need to specify stack details.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JTGpbhMM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/xd423em.png" alt="" width="800" height="631"&gt;
To continue on to the next section you must first:

&lt;ul&gt;
&lt;li&gt;Edit you stack name with your initials &lt;code&gt;[Your initials]-EC2-Web-Host&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Leave AmiID to the default&lt;/li&gt;
&lt;li&gt;Under instance type select m5.large to demonstrate real world performance for production workloads. Should you encounter any problem with the m5 instances load the CloudFormation Template again and select t2.micro. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Under MyIp, enter your local address followed by /32. Here is a link to lookup you &lt;a href="https://whatismyipaddress.com/"&gt;IP address&lt;/a&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--982UngWh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/zkvZ7NA.png" alt="" width="687" height="366"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Under MyVPC select the default VPC or any VPC you may want. &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Under "PublicSubnet"&amp;nbsp;&lt;strong&gt;select&lt;/strong&gt;&amp;nbsp;a subnet within your VPC that has internet access. A public subnet is defined by a subnet having a route to the internet gateway within it's route table. By default, the Default VPC subnets are all public. In the event you want to view all your subnets you can navigate to VPC on your AWS management console and click subnets.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zi-VqabZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/OjCEPGI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zi-VqabZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/OjCEPGI.png" alt="" width="800" height="271"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you are done entering the details above, click on&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure Stack Options. You can leave "Tags", "Permissions", and "Advanced options" as default and select&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DGaEfPid--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/yaiNXaP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DGaEfPid--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/yaiNXaP.png" alt="" width="800" height="592"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Review [Your Initials]-EC2-Web-Host page, review your settings and click on&amp;nbsp;&lt;strong&gt;Create stack&lt;/strong&gt;&amp;nbsp;to start building your web server.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wait till the "Logical ID" "[Your Initials]-EC2-Web-Host" shows a status of "CREATE_COMPLETE".&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the CloudFormation Stack is complete. Navigate to the EC2 service using you management console.&lt;br&gt;&lt;br&gt;
Select&amp;nbsp;&lt;strong&gt;Instances&lt;/strong&gt;&amp;nbsp;from the left hand menu. On the "Instances" page, select your instance "[Your Initials]-EC2-Web-Host" and copy the "Public IPv4 DNS" address. Paste this address into a new tab on your web browser.&lt;br&gt;&lt;br&gt;
You should be greeted by this web page with the title "EC2 Instance Metadata".&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y29vRS6o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/KFPay0I.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y29vRS6o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/KFPay0I.png" alt="" width="800" height="492"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sFxap-AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/fpg30XO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sFxap-AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/fpg30XO.png" alt="" width="800" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Generate a Custom AMI of the web server.
&lt;/h5&gt;

&lt;p&gt;Now that we have our instance setup to host our website, we will generate a custom machine image for our auto scaling group.&lt;br&gt;&lt;br&gt;
This will create an image of our web host that will be used by our Auto Scaling group to spin up multiple instances based on server load.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the EC2 Console under Instances, you can create Amazon Machine Images (AMIs) from either running or stopped instances. &lt;/li&gt;
&lt;li&gt;Or create an Amazon Machine Image by using your instance name [your initials] - Webserver &lt;strong&gt;Right-click&lt;/strong&gt;&amp;nbsp;your webhost instance under "Image and templates" choose&amp;nbsp;&lt;strong&gt;Create image&lt;/strong&gt;&amp;nbsp;from the context menu. &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j3SFvQ_k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/LZgNiW9.png" alt="" width="800" height="267"&gt;
&lt;/li&gt;
&lt;li&gt;On the "Create Image" page, put in the Image name&amp;nbsp;&lt;code&gt;[Your Initials]_Auto_Scaling_Webhost&lt;/code&gt;&amp;nbsp;and a description. You can leave the Instance volumes as default and then choose&amp;nbsp;&lt;strong&gt;Create Image&lt;/strong&gt;.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0abRYiha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/eKoQGIa.png" alt="" width="800" height="619"&gt;
&lt;/li&gt;
&lt;li&gt;It may take a few minutes for the AMI to be created. In the EC2 console under "Images" in the left hand menu select&amp;nbsp;&lt;strong&gt;AMIs&lt;/strong&gt;. You should see the AMI you just created, it may be in a pending state, but after a few moments it will transition to an available state.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We are done with our new Amazon Machine Image for now, we can now move on to setting up our auto scaling security group.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bKt4wWZ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Ly3kShk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bKt4wWZ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Ly3kShk.png" alt="" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Create a new Security Group for the Auto Scaling Group
&lt;/h5&gt;

&lt;p&gt;&amp;nbsp;A &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html"&gt;security group&lt;/a&gt; provides instance (virtual machine) level protection.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[!article]- A&amp;nbsp;security group&amp;nbsp;controls the traffic that is allowed to reach and leave the resources that it is associated with. For example, after you associate a security group with an EC2 instance, it controls the inbound and outbound traffic for the instance.&lt;br&gt;&lt;br&gt;
&amp;nbsp;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hYAgoBHO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/lGWo0RD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hYAgoBHO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/lGWo0RD.png" alt="" width="462" height="229"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JwuUQpga--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/u9R4skm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JwuUQpga--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/u9R4skm.png" alt="" width="462" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Within the console Under "Services" select&amp;nbsp;&lt;strong&gt;EC2&lt;/strong&gt;&amp;nbsp;or search&amp;nbsp;&lt;code&gt;EC2&lt;/code&gt;&amp;nbsp;in the search bar. On the EC2 page under the "Network &amp;amp; Security" heading in the left-hand menu select&amp;nbsp;&lt;strong&gt;Security Groups&lt;/strong&gt;.
You should see other security groups, including the security group for your web server named "[Your Initials]-EC2-Web-Host - Website Security Group".
To start the creation of a new security group, click on the&amp;nbsp;&lt;strong&gt;Create security group&lt;/strong&gt;&amp;nbsp;button.&lt;/li&gt;
&lt;li&gt;Name your security group&amp;nbsp;&lt;code&gt;[Your Initials] - Auto Scaling SG&lt;/code&gt; and you can use the same name for the description as well and make sure you have the correct VPC select. (Most likely the&amp;nbsp;&lt;strong&gt;Default&lt;/strong&gt;&amp;nbsp;VPC unless you setup a new one for this lab)&lt;/li&gt;
&lt;li&gt;Under "Inbound rules" we will leave it empty for now. We will be creating a rule later but we need our load balancer security group to exist first.&lt;/li&gt;
&lt;li&gt;"Outbound rules" currently allow all traffic out so there is no need for any additional rules. Add rule and select the CIDR range &lt;code&gt;0.0.0.0/0&lt;/code&gt; setting the destination to allow all ip address to access your instance.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8qNeSa7N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/PRPJSpb.png" alt="" width="800" height="491"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You are now finished with the prerequisites need. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Below is a representation of the end state&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QNpQdHyK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/RXwZBtA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QNpQdHyK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/RXwZBtA.png" alt="" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Three Main Components to EC2 Auto Scaling on AWS
&lt;/h4&gt;

&lt;p&gt;&amp;nbsp;&lt;strong&gt;1. Launch Template:&lt;/strong&gt;&amp;nbsp;A Launch Template is a feature of EC2 Auto Scaling that allows a way to templatize your launch requests. It enables you to store launch parameters so that you do not have to specify them every time you launch an instance. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Auto Scaling Groups:&lt;/strong&gt;&amp;nbsp;For auto scaling your EC2 instances are organized into groups so that they can be treated as a logical unit for the purposes of scaling and management. When you create a group, you can specify its minimum, maximum, and desired number of EC2 instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Scaling Policies:&lt;/strong&gt;&amp;nbsp;A Scaling Policy tells Auto Scaling when and how to scale. Scaling can occur manually, on a schedule, on demand, or you can use Auto Scaling to maintain a specific number of instances.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Auto Scaling is well suited for applications that have unpredictable demand patterns that can experience hourly, daily, or weekly variability in usage. This helps you to manage your cost and eliminate over-provisioning of capacity during times when it is not needed. Auto Scaling can also find an unhealthy instance, terminate that instance, and launch a new one based on the scaling plan.&lt;/li&gt;
&lt;li&gt;The number of EC2 instances can be scaled in or out as Auto Scaling responds to the metrics you define when creating these groups

&lt;ul&gt;
&lt;li&gt;You can specify the minimum number of instances in each Auto Scaling Group, so that your group never goes below this size. (Even if the instances are determined to be unhealthy)&lt;/li&gt;
&lt;li&gt;You can specify the maximum number of instances in each Auto Scaling Group, so that your group never goes above this size.&lt;/li&gt;
&lt;li&gt;You can specify a desired capacity to specify the number of healthy instances your auto scaling group should have at all times.️&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creating a Launch Template&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select&amp;nbsp;&lt;strong&gt;EC2&lt;/strong&gt; using your management console&lt;/li&gt;
&lt;li&gt;In the left navigation pane, find "Instances" and select&amp;nbsp;&lt;strong&gt;Launch Templates&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Now select&amp;nbsp;&lt;strong&gt;Create launch template&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You should find yourself on Create launch template" page, starting with the "Launch template name and description":
 a.&amp;nbsp;&lt;em&gt;Launch template name&lt;/em&gt;:&amp;nbsp;&lt;code&gt;[Your Initials]-scaling-template&lt;/code&gt;
b.&amp;nbsp;&lt;em&gt;Template version description&lt;/em&gt;: This is optional
c.&amp;nbsp;&lt;em&gt;Auto scaling guidance&lt;/em&gt;:&amp;nbsp;&lt;strong&gt;Check the box&lt;/strong&gt;&amp;nbsp;to provide guidance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pd4pgBb9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/1G7UCja.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pd4pgBb9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/1G7UCja.png" alt="" width="800" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;"Launch Template Contents" defines the parameters for the instances in the Auto Scaling group:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;a.&amp;nbsp;Amazon machine image (AMI): Select "My AMIs" and "Owned by me". In the drop down search by typing your initials and select the custom AMI you just created&amp;nbsp;[Your Initials]Auto_Scaling_Webhost. (The new AMI you just created may already be selected)&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8O0B_Oh5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/cRetsTb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8O0B_Oh5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/cRetsTb.png" alt="" width="781" height="709"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;b.&amp;nbsp;Instance type_:&amp;nbsp;t2.micro&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CNxo9U9S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/rNN9wUn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CNxo9U9S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/rNN9wUn.png" alt="" width="784" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;c.&amp;nbsp;Key pair (Login):&amp;nbsp;&lt;strong&gt;Select&lt;/strong&gt;&amp;nbsp;the Key Pair you created in the past, it is most likely call [Your Initials]-KeyPair. If not here is a guide to create &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html"&gt;one&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gZBSajk6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/pnX5dnF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gZBSajk6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/pnX5dnF.png" alt="" width="782" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;d.&amp;nbsp;Networking Settings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Subnet:&amp;nbsp;&lt;strong&gt;Don't include in launch template&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Firewall (security groups): Select "Select existing security group" and then select the security group you created in the first part of this lab named&amp;nbsp;&lt;strong&gt;[Your Initials] - Auto Scaling SG&lt;/strong&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ivNHUZE5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/a6UFdSN.png" alt="" width="777" height="485"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;e.&amp;nbsp;Configure storage: Leave as default&lt;br&gt;&lt;br&gt;
f.&amp;nbsp;Resource tags: None&lt;br&gt;&lt;br&gt;
g.&amp;nbsp;Advanced Details:&amp;nbsp;&lt;strong&gt;IMPORTANT&lt;/strong&gt;: Select the arrow to expand "Advanced details" and under "Detailed Cloudwatch monitoring" select&amp;nbsp;&lt;strong&gt;Enable&lt;/strong&gt;. Leave everything else as the default.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i1nUO33U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/0N7q9fL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i1nUO33U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/0N7q9fL.png" alt="" width="586" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By enabling CloudWatch Detailed monitoring. CloudWatch will monitor the instances in your auto scaling group in 1-minute intervals. This will allow the auto scaling group to respond quicker to changes in the group.&lt;/p&gt;

&lt;p&gt;By default, your instance has basic monitoring in 5-minute intervals for the instances. &lt;/p&gt;

&lt;p&gt;Create Auto Scaling Group&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select&amp;nbsp;&lt;strong&gt;EC2&lt;/strong&gt; using your management console&lt;/li&gt;
&lt;li&gt;In the left navigation pane find "Auto Scaling" and Select&amp;nbsp;Auto Scaling Groups.&lt;/li&gt;
&lt;li&gt;Click&amp;nbsp;Create an Auto Scaling group.&lt;/li&gt;
&lt;li&gt;Give the Auto Scaling group a name:&amp;nbsp;&lt;code&gt;[Your Initials]-Lab-AutoScaling-Group&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dFilzhBV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/r04sPZt.png" alt="" width="743" height="802"&gt;
&lt;/li&gt;
&lt;li&gt;From the Launch Template drop down choose the launch template named&amp;nbsp;[Your Initials]-scaling-template&amp;nbsp;you created in the previous section and select&amp;nbsp;Next.&lt;/li&gt;
&lt;li&gt;Configure settings page, configure the following and select&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;:
Network:

&lt;ul&gt;
&lt;li&gt;VPC:&amp;nbsp;&lt;strong&gt;Select&lt;/strong&gt;&amp;nbsp;your VPC (most likely Default) &lt;/li&gt;
&lt;li&gt;Subnets:&amp;nbsp;&lt;strong&gt;Select&lt;/strong&gt;&amp;nbsp;the subnets where you would like the auto scaling group to use when spinning up the hosts. (If you are using the default VPC, this will most likely be four subnets)
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NHFEO2lE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/vazKvTf.png" alt="" width="722" height="568"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A best practice for your Auto Scaling Group would be to select only private subnets. The instances will be sitting behind a load balancer and will not need public IP addresses.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Specify load balancing and health checks:&lt;/p&gt;

&lt;p&gt;a.&amp;nbsp;&lt;em&gt;Load balancing&lt;/em&gt;:&amp;nbsp;&lt;strong&gt;Attach to a new load balancer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;b.&amp;nbsp;&lt;em&gt;Load balancer type&lt;/em&gt;:&amp;nbsp;&lt;strong&gt;Application Load Balancer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;c.&amp;nbsp;&lt;em&gt;Load balancer name&lt;/em&gt;:&amp;nbsp;&lt;code&gt;[Your Initials]-Application-Load-Balancer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;d.&amp;nbsp;&lt;em&gt;Load balancer scheme&lt;/em&gt;:&amp;nbsp;&lt;strong&gt;Internet-facing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;e.&amp;nbsp;&lt;em&gt;Networking mapping&lt;/em&gt;: You should see all the Availability Zones and subnets you selected in the previous step. (If you had multiple subnets per AZ, this were it would let you choose between them)&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fktFsAjB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/14l4eKe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fktFsAjB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/14l4eKe.png" alt="" width="637" height="789"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;f.&amp;nbsp;&lt;em&gt;Listeners and routing&lt;/em&gt;: Keep the Port as 80 and select&amp;nbsp;&lt;strong&gt;Create a target group&lt;/strong&gt;&amp;nbsp;from the "Default routing (forward to)" dropdown.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L39ZBY5C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Wdws1Jt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L39ZBY5C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/Wdws1Jt.png" alt="" width="639" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;g.&amp;nbsp;&lt;em&gt;New target group name&lt;/em&gt;:&amp;nbsp;&lt;code&gt;[Your Initials]-Target-Group&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- The target group is where your load balancer is going to look for instances to distribute traffic. We are setting our auto scaling group to automatically register instances into this group and it will also be associated to our load balancer.

h.&amp;nbsp;*Health checks &amp;amp; Additional settings*: Leave as default and select&amp;nbsp;**Next**.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Configure the group size and scaling policies below and then select&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;
a.&amp;nbsp;&lt;em&gt;Group Size&lt;/em&gt;: The settings below will keep our group size to one EC2 instance unless a scaling policy is triggered.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Desired capacity:&amp;nbsp;`1`

- Minimum capacity:&amp;nbsp;`1`

- Maximum Capacity:&amp;nbsp;`5`

b.&amp;nbsp;*Scaling policies*: Select&amp;nbsp;**Target tracking scaling policy**

- Metric type:&amp;nbsp;Average CPU utilization

- Target Value:&amp;nbsp;`25`

![](https://i.imgur.com/lyOp5tZ.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We are going to set our target CPU utilization low to speed up the results.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add Notifications:&lt;br&gt;&lt;br&gt;
You can configure your Auto Scaling Group to send notifications to an endpoint that you choose, such as an &lt;em&gt;email address&lt;/em&gt;. You can receive notifications whenever a specified event takes place, including the successful launch of an instance, failed instance launch, instance termination, and failed instance termination.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add Tags: Add a single tag and then select&amp;nbsp;&lt;strong&gt;Next&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
a. Select the&amp;nbsp;&lt;strong&gt;Add tag&lt;/strong&gt;&amp;nbsp;button and configure the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Key:&amp;nbsp;&lt;code&gt;Name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Value:&amp;nbsp;&lt;code&gt;[Your Initials] - Auto Scaling Group&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then select&amp;nbsp;&lt;strong&gt;Create Auto Scaling group&lt;/strong&gt;. You have now created your Auto Scaling Group, target group and load balancer.&lt;br&gt;&lt;br&gt;
a. You will soon see a new instance created by the Auto Scaling group in the EC2 console with the name tag "[Your Initials] - Auto Scaling Group". (You may need to refresh the screen to see the instance)&lt;/p&gt;

&lt;p&gt;b. If you select&amp;nbsp;&lt;strong&gt;Load Balancers&lt;/strong&gt;&amp;nbsp;under "Load Balancing" in the left hand menu, you will see your load balancer provisioning.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the next step we will create an additional security group and update the security settings to allow traffic to flow between the ALB and our web hosts.&lt;/p&gt;

&lt;h4&gt;
  
  
  Penultimate Things We Must Do before We come to the End Is:
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Configuring Security Groups
&lt;/h4&gt;

&lt;p&gt;Creating a Load Balancer Security Group&lt;/p&gt;

&lt;p&gt;When our load balancer was provisioned it was setup with the default security group in our VPC. To allow access to the load balancer via the public DNS, we will need to create and attach a security group to allow inbound traffic on port 80 from the internet.&lt;/p&gt;

&lt;p&gt;We will also create an outbound rule that allows outgoing traffic from the load balancer to only be sent to hosts within the Auto Scaling Security Group.&lt;br&gt;&lt;br&gt;
On the EC2 page under the "Network &amp;amp; Security" heading in the left-hand menu select&amp;nbsp;&lt;strong&gt;Security Groups&lt;/strong&gt;. You should see other security groups, including the security group for your web server named [Your Initials]-EC2-Web-Host - Website Security Group.&lt;br&gt;&lt;br&gt;
Click on the&amp;nbsp;&lt;strong&gt;Create security group&lt;/strong&gt;&amp;nbsp;button.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic details:
a.&amp;nbsp;&lt;em&gt;Security group name&lt;/em&gt;:&amp;nbsp;&lt;code&gt;[Your Initials]-SG-Load-Balancer&lt;/code&gt;
b.&amp;nbsp;&lt;em&gt;Description&lt;/em&gt;:&amp;nbsp;&lt;code&gt;[Your Initials]-SG-Load-Balancer&lt;/code&gt;
c.&amp;nbsp;&lt;em&gt;VPC&lt;/em&gt;: Select your VPC (Most likely the Default VPC)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inbound rules:&lt;br&gt;&lt;br&gt;
a. Click on the&amp;nbsp;&lt;strong&gt;Add rule&lt;/strong&gt;&amp;nbsp;button&lt;br&gt;&lt;br&gt;
b.&amp;nbsp;&lt;em&gt;Type&lt;/em&gt;:&amp;nbsp;&lt;code&gt;HTTP&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kwUihLxP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/ka3Cvy6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kwUihLxP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/ka3Cvy6.png" alt="" width="800" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;c.&amp;nbsp;&lt;em&gt;Source&lt;/em&gt;: Custom:&amp;nbsp;&lt;code&gt;[Input your public IP address followed by a /32]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;(You can find your local IP by searching&amp;nbsp;&lt;a href="https://www.google.com/search?q=What+is+my+ip%3F&amp;amp;rlz"&gt;What is my IP.&lt;/a&gt;&amp;nbsp;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Outbound rules:&lt;br&gt;&lt;br&gt;
a. Find the "All traffic" rule and click on&amp;nbsp;&lt;strong&gt;Delete&lt;/strong&gt;&amp;nbsp;to remove the rule. (All Outbound rules should now be removed)&lt;br&gt;&lt;br&gt;
b. Click on the&amp;nbsp;&lt;strong&gt;Add rule&lt;/strong&gt;&amp;nbsp;button&lt;br&gt;&lt;br&gt;
c.&amp;nbsp;&lt;em&gt;Type&lt;/em&gt;: HTTP&lt;br&gt;&lt;br&gt;
d. Under "Destination" select&amp;nbsp;&lt;strong&gt;Custom&lt;/strong&gt;&amp;nbsp;and in the field select your&amp;nbsp;&lt;strong&gt;[Your Initials]-Auto Scaling SG&lt;/strong&gt;&amp;nbsp;as the "Destination". Hint: start by typing&amp;nbsp;&lt;code&gt;sg&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&amp;nbsp;to get the Security Group list.&lt;br&gt;&lt;br&gt;
f. You security group configuration should look similar to the image below. Select&amp;nbsp;&lt;strong&gt;Create security group&lt;/strong&gt;&amp;nbsp;when finished.&lt;br&gt;&lt;br&gt;
  &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dg4iwUMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/FNK72qy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dg4iwUMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/FNK72qy.png" alt="" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attach your new Load Balancer Security group to your Load Balancer:&lt;br&gt;&lt;br&gt;
a. On the EC2 service page left side menu find "Load Balancing" and select&amp;nbsp;&lt;strong&gt;Load Balancers&lt;/strong&gt;. Select the load balancer you created. Make sure the State is "Active".&lt;br&gt;&lt;br&gt;
b. Under the "Description" tab scroll down to the "Security" section and click on&amp;nbsp;&lt;strong&gt;Edit security groups&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
c. Select the box to the left of your new load balancer sg named&amp;nbsp;&lt;code&gt;[Your Initials]-SG-Load-Balancer&lt;/code&gt;&lt;br&gt;&lt;br&gt;
d. Make sure you also&amp;nbsp;&lt;strong&gt;un-select&lt;/strong&gt;&amp;nbsp;any other security group and then click on the&amp;nbsp;&lt;strong&gt;Save&lt;/strong&gt;&amp;nbsp;button.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a4-q5vXO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/eXmD19m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a4-q5vXO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/eXmD19m.png" alt="" width="713" height="553"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Add Inbound Rule to the Auto Scaling Security Group
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We will need to setup a rule to only allow traffic from the new Load Balancer Security Group to the Auto Scaling Security Group. This will be one of the layers of protection that will prevent our webhosts from being directly accessed from the internet.&lt;br&gt;&lt;br&gt;
a. On the EC2 service page left side menu under "Network &amp;amp; Security" select&amp;nbsp;&lt;strong&gt;Security Groups&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
b. Select your Auto Scaling Security Group:&amp;nbsp;&lt;strong&gt;[Your Initials] - Auto Scaling SG&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
c. Select the&amp;nbsp;&lt;strong&gt;Inbound Rules&lt;/strong&gt;&amp;nbsp;tab and click on the&amp;nbsp;&lt;strong&gt;Edit inbound rules&lt;/strong&gt;&amp;nbsp;button and then the&amp;nbsp;&lt;strong&gt;Add rule&lt;/strong&gt;&amp;nbsp;button.&lt;br&gt;&lt;br&gt;
d. From the "Type" drop down select&amp;nbsp;&lt;strong&gt;HTTP&lt;/strong&gt;. Under "Source" select&amp;nbsp;&lt;strong&gt;Custom&lt;/strong&gt;&amp;nbsp;and in the field specify your&amp;nbsp;&lt;strong&gt;[Your Initials]-SG-Load-Balancer&lt;/strong&gt;&amp;nbsp;as the "Source". Hint: start by typing&amp;nbsp;&lt;code&gt;sg&lt;/code&gt; to get the Security Group list. Now click on&amp;nbsp;&lt;strong&gt;Save rules&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v6f1OU_T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/QM2NCIW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v6f1OU_T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/QM2NCIW.png" alt="" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We will now test to make sure your load balancer is working. There is currently only one instance (or target) running in the auto scaling group, but you should be able to access the website.&lt;/p&gt;

&lt;p&gt;Return to your the load balancers page by selecting&amp;nbsp;&lt;strong&gt;Load Balancers&lt;/strong&gt;&amp;nbsp;from the left hand menu. Under the "Description" tab&amp;nbsp;&lt;strong&gt;copy&lt;/strong&gt;&amp;nbsp;the DNS name and&amp;nbsp;&lt;strong&gt;paste&lt;/strong&gt;&amp;nbsp;it into a web browser. You should now see the website being loaded from your auto scaling group. Leave this page open, you will need it in the next step.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Testing the AutoScaling Group
&lt;/h4&gt;

&lt;p&gt;Now that you have created your Auto Scaling Group and load balancer, let's test it to ensure that everything is working correctly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you are on the website accessed through the Load Balancer DNS address in the previous step.&lt;/li&gt;
&lt;li&gt;At the bottom of the front page click on the&amp;nbsp;&lt;strong&gt;Start CPU Load Generation&lt;/strong&gt;&amp;nbsp;link: Once the CPU load goes above 25% for a sustained period the Auto Scaling policy will begin spinning up the instances specified in the launch template to meet demand.&amp;nbsp;&lt;em&gt;(You may have to do this twice if the first time doesn't generate enough load)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;In the "Instances" section of the EC2 Console you can watch for the new instances created by Auto Scaling, this might take a couple of minutes. Refresh the EC2 instances page and you should soon see a new instance spinning up automatically. You can select the instance named [Your Initials] - Auto Scaling Group and click on the&amp;nbsp;&lt;strong&gt;Monitoring&lt;/strong&gt;&amp;nbsp;tab below to keep an eye on the "CPU Utilization".&lt;/li&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;You can also see this by going to the Auto Scaling Groups page.&amp;nbsp;&lt;a href="https://console.aws.amazon.com/ec2autoscaling"&gt;https://console.aws.amazon.com/ec2autoscaling&lt;/a&gt;&amp;nbsp;&amp;nbsp;Then select your auto scaling group&amp;nbsp;&lt;strong&gt;[Your Initials]-Lab-AutoScaling-Group&lt;/strong&gt;. If you look at the details under the Instance management tab, you can see if new instances are spinning up. You can look at the Instance management tab to see how many instances there are in your group currently. The monitoring tab shows you different metrics like group size, pending instances, total instances, and much more.
&amp;gt; Your architecture now looks like this
&amp;gt; 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-3nvFyY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/BBVYhff.png" alt="" width="800" height="443"&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once a number of new instances have successfully started (probably 3 or 4), repeatedly&amp;nbsp;&lt;strong&gt;refresh&lt;/strong&gt;&amp;nbsp;your web-browser on you web host. You should now see the Instance ID, Availability Zone and Private IP change as the load balancer distributes the requests across the Auto Scaling group.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your have successfully created an EC2 Auto Scaling Group behind an Application Load Balancer.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Breaking a Monolithic Node.js Application into Microservices</title>
      <dc:creator>Nick Goko</dc:creator>
      <pubDate>Tue, 16 Jan 2024 10:16:34 +0000</pubDate>
      <link>https://dev.to/nickgoko/breaking-a-monolithic-nodejs-application-into-microservices-479e</link>
      <guid>https://dev.to/nickgoko/breaking-a-monolithic-nodejs-application-into-microservices-479e</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QMtWcUy7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/aacyBbv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QMtWcUy7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/aacyBbv.png" alt="" width="800" height="456"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;After completing this lab, you should be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Migrate a monolithic Node.js application to run in a Docker container&lt;/li&gt;
&lt;li&gt;Refactor a Node.js application from a monolithic design to a microservices architecture&lt;/li&gt;
&lt;li&gt;Deploy a containerized Node.js microservices application to Amazon ECS. 
### Task 1: Preparing the Development Environment&lt;/li&gt;
&lt;li&gt;Create cloud9 environment. AWS Cloud9 is a cloud-based integrated development environment (IDE) that you can use to write, run, and debug code on a browser. It comes pre-packaged with essential tools for popular programming languages, and provides access to the AWS Command Line Interface (AWS CLI) in a terminal session tab.
![[Pasted image 20240111082546.png]]&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;AWS Management Console&lt;/strong&gt; browser tab, expand &lt;strong&gt;All services&lt;/strong&gt;, and then select &lt;strong&gt;Developer Tools &amp;gt; Cloud9&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Cloud9-IDE&lt;/strong&gt; card, choose &lt;strong&gt;Open IDE&lt;/strong&gt;
The IDE opens in a new browser tab and displays several tabs, including a &lt;strong&gt;Welcome&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;In the bottom pane of the IDE, enter the following command in the terminal tab
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://aws-tc-largeobjects.s3.us-west-2.amazonaws.com/CUR-TF-200-ACACAD-2-91555/16-lab-mod13-guided-1-ECS/s3/lab-files-ms-node-js.tar.gz | &lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-zxv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command retrieves a compressed archive file that contains the lab files. It also extracts the file contents in the AWS Cloud9 &lt;strong&gt;~/environment&lt;/strong&gt; folder. The command output should like the following example:&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111083015.png]]&lt;br&gt;&lt;br&gt;
The downloaded and extracted files are visible in the &lt;strong&gt;Environment&lt;/strong&gt; window (in the left pane).&lt;br&gt;&lt;br&gt;
You can see the following folders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1-no-container&lt;/strong&gt; – Contains the files that are related to the &lt;em&gt;monolithic&lt;/em&gt; implementation of the application. This implementation is intended to run directly on a Node.js server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2-containerized-monolith&lt;/strong&gt; – Contains the files that are related to the &lt;em&gt;monolithic&lt;/em&gt; implementation of the application. This implementation is intended to run in a containerized Docker environment orchestrated by Amazon ECS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3-containerized-microservices&lt;/strong&gt; – Contains the files that are related to the &lt;em&gt;microservices&lt;/em&gt; implementation of the application. This implementation is intended to run in a containerized Docker environment orchestrated by Amazon ECS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep the AWS Cloud9 IDE tab opened throughout this lab, because you will use it frequently.&lt;/p&gt;
&lt;h3&gt;
  
  
  Task 2: Running the Application on a Basic Node.js Server
&lt;/h3&gt;

&lt;p&gt;The base Node.js application is a monolithic service that was designed to run directly on a server, without a container.&lt;br&gt;&lt;br&gt;
In this task, you deploy the application to the Node.js server that is installed on the instance running your AWS Cloud9 environment.&lt;br&gt;&lt;br&gt;
You then test the application by using the AWS CLI terminal to invoke its RESTful API methods.&lt;br&gt;&lt;br&gt;
The deployment architecture and request flow are illustrated in the following diagram.&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111083313.png]]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The monolithic implementation of the application uses the Node.js &lt;em&gt;cluster&lt;/em&gt; functionality to spawn one worker process per CPU core.&lt;br&gt;&lt;br&gt;
The processes share a single port, and are invoked in a round-robin way by the load balancer that is built into Node.js. This feature increases scalability on servers that have multiple CPU cores.&lt;/p&gt;

&lt;p&gt;In this task, you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the Node.js modules required by the application&lt;/li&gt;
&lt;li&gt;Review the application design and code&lt;/li&gt;
&lt;li&gt;Run the application&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Task 2.1: Installing the Required Node.js Modules
&lt;/h4&gt;

&lt;p&gt;The message board application uses two modules from the Node.js &lt;em&gt;koa&lt;/em&gt; framework in its implementation: &lt;em&gt;koa&lt;/em&gt; and &lt;em&gt;koa-router&lt;/em&gt;. &lt;em&gt;Koa.js&lt;/em&gt; is a widely used Node.js web application framework that facilitates building asynchronous server-side JavaScript applications.&lt;/p&gt;

&lt;p&gt;In the terminal tab, enter the following commands to install the &lt;em&gt;koa&lt;/em&gt; and &lt;em&gt;koa-router&lt;/em&gt; modules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/environment/1-no-container

npm &lt;span class="nb"&gt;install &lt;/span&gt;koa

npm &lt;span class="nb"&gt;install &lt;/span&gt;koa-router
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The modules are downloaded and installed in the &lt;strong&gt;1-no-container/node_modules&lt;/strong&gt; folder of the AWS Cloud9 &lt;strong&gt;~/environment&lt;/strong&gt; folder. You can ignore the notice, warnings, and update messages in the output.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 2.2: Reviewing the Application Design and Code
&lt;/h4&gt;

&lt;p&gt;The components that implement the monolithic message board application are in the &lt;strong&gt;1-no-container&lt;/strong&gt; folder. Review them to gain an understanding of the application design and code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Environment&lt;/strong&gt; window on the left, expand the &lt;strong&gt;1-no-container&lt;/strong&gt; folder. The components of the application include:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;node_modules&lt;/strong&gt; folder – This folder was created when you installed the required JavaScript modules in the previous subtask. It contains their source code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;db.json&lt;/strong&gt; – A JavaScript Object Notation (JSON) object that simulates the message board database. It contains attributes that represent &lt;em&gt;users&lt;/em&gt;, &lt;em&gt;threads&lt;/em&gt;, and &lt;em&gt;posts&lt;/em&gt;, with corresponding sample values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;index.js&lt;/strong&gt; – JavaScript program that is the application's entry point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;package.json&lt;/strong&gt; – A JSON object that describes the application, its entry point, and its dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;package-lock.json&lt;/strong&gt; – A JSON object that was automatically generated when you installed the required JavaScript modules in the &lt;strong&gt;node_modules&lt;/strong&gt; folder. It is used by the installation utility, &lt;em&gt;npm&lt;/em&gt;, to track the modifications that are made to the folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;server.js&lt;/strong&gt; – JavaScript program that defines the application's RESTful API methods, and implements their respective handlers.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Examine the &lt;em&gt;package.json&lt;/em&gt; object. In the &lt;strong&gt;Environment&lt;/strong&gt; window, open &lt;strong&gt;package.json&lt;/strong&gt; an editor tab by double-clicking it. Notice the following attributes of the JSON object:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lines 2 through 5&lt;/strong&gt; – The &lt;em&gt;dependencies&lt;/em&gt; attribute defines the JavaScript module dependencies for the application.
Note that the &lt;em&gt;koa&lt;/em&gt; and &lt;em&gt;koa-router&lt;/em&gt; modules that you installed in the previous subtask are listed here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 6 through 8&lt;/strong&gt; – The &lt;em&gt;scripts&lt;/em&gt; attribute declares the &lt;em&gt;index.js&lt;/em&gt; program as the entry point to the application.
![[Pasted image 20240111085740.png]]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Examine the &lt;strong&gt;db.json&lt;/strong&gt; object. In the &lt;strong&gt;Environment&lt;/strong&gt; window, open &lt;strong&gt;db.json&lt;/strong&gt; in an editor tab by double-clicking it. Notice the following attributes of the JSON object:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lines 2 through 27&lt;/strong&gt; – These lines define a &lt;em&gt;users&lt;/em&gt; attribute that represents the registered users of the message board. The attribute value is a list of &lt;em&gt;four&lt;/em&gt; sample users with the following names: &lt;em&gt;Marcerline Singer&lt;/em&gt;, &lt;em&gt;Finn Alberts&lt;/em&gt;, &lt;em&gt;Paul Barium&lt;/em&gt;, and &lt;em&gt;Jake Storm&lt;/em&gt;.
![[Pasted image 20240111085822.png]]&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 29 through 45&lt;/strong&gt; – These lines define a &lt;em&gt;threads&lt;/em&gt; attribute that represents the current active threads on the message board. The attribute value is a list of &lt;em&gt;three&lt;/em&gt; sample threads with the following titles:
![[Pasted image 20240111085959.png]]

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Did you see the Brazil game?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;New French bakery opening in the neighborhood tomorrow&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;In search of a new guitar&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 47 through 78&lt;/strong&gt; – These lines define a &lt;em&gt;posts&lt;/em&gt; attribute that represents the posted messages on the active threads. The attribute value is a list of &lt;em&gt;six&lt;/em&gt; sample message posts.
![[Pasted image 20240111090023.png]]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Review the code for &lt;em&gt;index.js&lt;/em&gt;. In the &lt;strong&gt;Environment&lt;/strong&gt; window, open &lt;strong&gt;index.js&lt;/strong&gt; in an editor tab by double-clicking it. Notice the following information:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lines 1 through 3&lt;/strong&gt; – These lines import the JavaScript modules that the program requires, specifically: &lt;em&gt;cluster&lt;/em&gt;, &lt;em&gt;http&lt;/em&gt;, and &lt;em&gt;os&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 3&lt;/strong&gt; – This line uses the &lt;em&gt;os&lt;/em&gt; module to ask about the number of CPU cores that are available on the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 5 through 15&lt;/strong&gt; – These lines are run the first time the program is invoked (when the application is started). They create a &lt;em&gt;Leader&lt;/em&gt; thread for the cluster and one &lt;em&gt;worker&lt;/em&gt; thread for each CPU core that is available on the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 16 through 19&lt;/strong&gt; – These lines handle each request to the application by invoking the &lt;em&gt;server.js&lt;/em&gt; program in the current &lt;em&gt;worker&lt;/em&gt; thread.
![[Pasted image 20240111090107.png]]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Lastly, review the code for &lt;em&gt;server.js&lt;/em&gt;. In the &lt;strong&gt;Environment&lt;/strong&gt; window, open &lt;strong&gt;server.js&lt;/strong&gt; in an editor tab by double-clicking it. Use the comments that are provided in the code to facilitate your understanding of the logic. In particular, notice the following information:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Line 3&lt;/strong&gt; – This line imports &lt;em&gt;db.json&lt;/em&gt;, the JSON object that simulates the database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 6 through 11&lt;/strong&gt; – These lines define a generator function that runs for every request. Its purpose is to print a line that contains the &lt;em&gt;HTTP method&lt;/em&gt;, &lt;em&gt;resource path URL&lt;/em&gt;, and &lt;em&gt;elapsed time&lt;/em&gt; for each request that is processed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lines 13 through 47&lt;/strong&gt; – These lines define the application's RESTful API methods and their implementation. Specifically, the application can respond to the following RESTful calls.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;GET /api/users&lt;/code&gt;: Returns the collection of &lt;em&gt;users&lt;/em&gt; in the database&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/users/:userId&lt;/code&gt;: Returns the information for the &lt;em&gt;user&lt;/em&gt; that is identified by &lt;em&gt;:userId&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/threads&lt;/code&gt;: Returns the collection of &lt;em&gt;threads&lt;/em&gt; in the database&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/threads/:threadId&lt;/code&gt;: Returns the information for the &lt;em&gt;thread&lt;/em&gt; that is identified by &lt;em&gt;:threadId&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/posts/in-thread/:threadId&lt;/code&gt;: Returns the collection of &lt;em&gt;post messages&lt;/em&gt; for the &lt;em&gt;thread&lt;/em&gt; that is identified by &lt;em&gt;:threadId&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/posts/by-user/:userId&lt;/code&gt;: Returns the collection of &lt;em&gt;post messages&lt;/em&gt; for the &lt;em&gt;user&lt;/em&gt; that is identified by &lt;em&gt;:userId&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /api/&lt;/code&gt;: Returns the message &lt;em&gt;API ready to receive requests&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /&lt;/code&gt;: Returns the message &lt;em&gt;Ready to receive requests&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 52&lt;/strong&gt; – This line defines the &lt;em&gt;port number&lt;/em&gt; where the application listens for requests
&lt;h4&gt;
  
  
  Task 2.3: Running the Application
&lt;/h4&gt;

&lt;p&gt;In this subtask, you will start the Node.js server and run the message board application. Then, you will test some of its RESTful API methods.&lt;br&gt;&lt;br&gt;
In the terminal tab, start Node.js and the application by entering the following command:&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the server is started and the application's entry point, index.js, is run. The first time that index.js is invoked, it creates two cluster threads—Leader and Worker—to process requests.&lt;/p&gt;

&lt;p&gt;Next, you will leave the current terminal session active and open a second terminal tab to test the application's RESTful API.&lt;br&gt;&lt;br&gt;
    In the bottom pane, open a new terminal tab by choosing &lt;strong&gt;(+)&lt;/strong&gt; and selecting &lt;strong&gt;New Terminal&lt;/strong&gt;. You now have two terminals where you can enter commands.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;right terminal tab&lt;/strong&gt;, retrieve the &lt;code&gt;/api/users&lt;/code&gt; resource by entering the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl localhost:3000/api/users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The RESTful invocation returns a JSON object that contains the list of &lt;em&gt;users&lt;/em&gt; in the message board database.&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111094123.png]]&lt;/p&gt;

&lt;p&gt;Select the &lt;strong&gt;left terminal tab&lt;/strong&gt;. You see an output message from server.js that it processed a GET method request on the resource, which is identified by the path &lt;code&gt;/api/users&lt;/code&gt;. The request took &lt;em&gt;2&lt;/em&gt; milliseconds to process.&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111094352.png]]&lt;/p&gt;

&lt;p&gt;Retrieve the information for only the &lt;em&gt;fourth&lt;/em&gt; user in database. In the &lt;strong&gt;right terminal tab&lt;/strong&gt;, enter the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;curl localhost:3000/api/users/4&lt;/code&gt;&lt;br&gt;&lt;br&gt;
A JSON object that contains all the threads in the database is returned&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111094737.png]]&lt;/p&gt;

&lt;p&gt;Next, retrieve all the &lt;em&gt;threads&lt;/em&gt; that are currently in the database. In the &lt;strong&gt;right terminal tab&lt;/strong&gt;, enter the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;curl localhost:3000/api/threads&lt;/code&gt;&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111095230.png]]&lt;/p&gt;

&lt;p&gt;Lastly, retrieve all the &lt;em&gt;posts&lt;/em&gt; for the &lt;em&gt;first&lt;/em&gt; thread in the database. In the &lt;strong&gt;right terminal tab&lt;/strong&gt;, enter the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;curl localhost:3000/api/posts/in-thread/1&lt;/code&gt;&lt;br&gt;&lt;br&gt;
A JSON object that contains all the threads in the database is returned&lt;/p&gt;

&lt;p&gt;Lastly, retrieve all the &lt;em&gt;posts&lt;/em&gt; for the &lt;em&gt;first&lt;/em&gt; thread in the database. In the &lt;strong&gt;right terminal tab&lt;/strong&gt;, enter the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;curl localhost:3000/api/posts/in-thread/1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Stop the Node.js server. In the &lt;strong&gt;left terminal tab&lt;/strong&gt;, press &lt;strong&gt;CTRL+C&lt;/strong&gt; to terminate the server process.&lt;br&gt;&lt;br&gt;
You have validated that the application responds properly to GET requests. In the next task, you will containerize the application.&lt;/p&gt;
&lt;h3&gt;
  
  
  Task 3: Containerizing the Monolith for Amazon ECS
&lt;/h3&gt;

&lt;p&gt;Containers wrap application code in a unit of deployment, which captures a snapshot of the code and its dependencies. They can help ensure that applications deploy quickly, reliably, and consistently, regardless of the deployment environment.&lt;/p&gt;

&lt;p&gt;In this task, you will build a container image for the monolithic message board application and push it to Amazon Elastic Container Registry (Amazon ECR). This step prepares the application for deployment to Amazon ECS.&lt;/p&gt;

&lt;p&gt;Specifically, you will perform the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prepare the application for Docker containerization&lt;/li&gt;
&lt;li&gt;Provision a repository&lt;/li&gt;
&lt;li&gt;Build and push the Docker image to the repository&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Task 3.1: Preparing the Application for Docker Containerization
&lt;/h4&gt;

&lt;p&gt;To put the message board application into a Docker container, the following changes must be made to the application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove the use of the Node.js &lt;em&gt;cluster&lt;/em&gt; feature and convert the application to a single-process design.
With Docker containers, the goal is to run a single process per container, instead of a cluster of processes.&lt;/li&gt;
&lt;li&gt;Create a &lt;em&gt;Dockerfile&lt;/em&gt; for the application. This file is basically a build script that contains instructions about how to build a &lt;em&gt;container image&lt;/em&gt; for the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A container-ready version of the application is provided to you in the &lt;strong&gt;2-containerized-monolith&lt;/strong&gt; folder of your AWS Cloud9 environment.&lt;br&gt;&lt;br&gt;
Take a few minutes to review the files and understand the changes that were made to prepare the application for containerization.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Environment&lt;/strong&gt; window on the left, expand the &lt;strong&gt;2-containerized-monolith&lt;/strong&gt; folder, and open the &lt;strong&gt;package.json&lt;/strong&gt; in an editor tab by double-clicking it.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Line 7&lt;/strong&gt;, notice that the entry point into the application was changed from &lt;em&gt;index.js&lt;/em&gt; to &lt;em&gt;server.js&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
The &lt;em&gt;index.js&lt;/em&gt; file is no longer in the application folder.&lt;br&gt;&lt;br&gt;
The &lt;em&gt;index.js&lt;/em&gt; file contained the initialization logic for the Node.js &lt;em&gt;cluster&lt;/em&gt; feature, and you will no longer use that feature.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Environment&lt;/strong&gt; window, expand the &lt;strong&gt;2-containerized-monolith&lt;/strong&gt; folder, and open the &lt;strong&gt;server.js&lt;/strong&gt; file in an editor tab by double-clicking it.&lt;br&gt;&lt;br&gt;
The only difference from the non-containerized version is the addition of &lt;strong&gt;Line 54&lt;/strong&gt;, which prints the message &lt;em&gt;Worker started&lt;/em&gt; when the application is first started.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Environment&lt;/strong&gt; window, expand the &lt;strong&gt;2-containerized-monolith&lt;/strong&gt; folder, and open the &lt;strong&gt;Dockerfile&lt;/strong&gt; in an editor tab by double-clicking it.&lt;/p&gt;

&lt;p&gt;This file contains the instructions about how to build the container image for the application.&lt;/p&gt;

&lt;p&gt;![[Pasted image 20240113110142.png]]&lt;br&gt;&lt;br&gt;
Notice the following information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Line 1&lt;/strong&gt; – The base image where the container image will be built. Here, it is &lt;em&gt;alpine-node&lt;/em&gt;, which is a Node.js image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 3&lt;/strong&gt; – This line sets the working directory of the file system on the image to &lt;em&gt;/srv&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 4&lt;/strong&gt; – This line adds the contents of the &lt;strong&gt;2-containerized-monolith&lt;/strong&gt; folder (the application folder) to the current working directory of the image's file system (which is set in the previous line).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 5&lt;/strong&gt; – This line invokes the &lt;em&gt;npm install&lt;/em&gt; command to install all the application's library dependencies that were declared in the &lt;em&gt;package.json&lt;/em&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 7&lt;/strong&gt; – This line informs Docker that the container listens on port 3000 when it runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 8&lt;/strong&gt; – This line asks Docker to run the command &lt;em&gt;node server.js&lt;/em&gt;, which starts the application when the image is started.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you understand how the container image for the application will be built, you will next examine where to put the image after it is built.&lt;/p&gt;
&lt;h4&gt;
  
  
  Task 3.2: Provisioning a Repository
&lt;/h4&gt;

&lt;p&gt;Docker container images are intended to be stored in a repository for sharing, version control, and easier management purposes. &lt;em&gt;Amazon ECR&lt;/em&gt; makes it easy for developers to store, manage, and deploy Docker container images.&lt;br&gt;&lt;br&gt;
In addition, Amazon ECR is integrated with Amazon ECS, which enables Amazon ECS to pull container images directly for production deployments.&lt;/p&gt;

&lt;p&gt;In this subtask, you will create a repository in Amazon ECR to house the Docker container image for the message board application.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Your environments&lt;/strong&gt; browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and then select &lt;strong&gt;Container &amp;gt; Elastic Container Registry&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The Amazon ECR console opens.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Create a repository&lt;/strong&gt;, choose &lt;strong&gt;Get Started&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Repository name&lt;/strong&gt; box, enter &lt;code&gt;mb-repo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create repository&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A message at the top of the page indicates that the repository was successfully created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Do not close the window that shows the message.&lt;/em&gt; You will use it in the next subtask.&lt;/p&gt;
&lt;h4&gt;
  
  
  Task 3.3: Building and Pushing the Docker Image
&lt;/h4&gt;

&lt;p&gt;You are now ready to build the container image for the application and push it to the Amazon ECR repository that you created.&lt;/p&gt;

&lt;p&gt;One useful feature of the Amazon ECR console is that it provides ready-to-use command templates for building and pushing an image to the new repository. You use these provided AWS CLI commands in the next steps.&lt;/p&gt;

&lt;p&gt;Before you can successfully run the next steps, you must upgrade the AWS CLI. To do this, go to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab, and in the &lt;strong&gt;left terminal tab&lt;/strong&gt;, enter the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip3 &lt;span class="nb"&gt;install &lt;/span&gt;awscli &lt;span class="nt"&gt;--upgrade&lt;/span&gt; &lt;span class="nt"&gt;--user&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;/.local/bin:&lt;span class="nv"&gt;$PATH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go back to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab, and in the message window at the top of the page, choose &lt;strong&gt;View push commands&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Push commands for mb-repo&lt;/strong&gt; pop-up window opens. This window lists four AWS CLI commands that are customized for the &lt;em&gt;mb-repo&lt;/em&gt;, and they are purposely built to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authenticate your Docker client to your Amazon ECR registry

&lt;ul&gt;
&lt;li&gt;Build your Docker image&lt;/li&gt;
&lt;li&gt;Tag your Docker image&lt;/li&gt;
&lt;li&gt;Push your Docker image to the repository&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pop-up window offers two versions of the commands: one for &lt;em&gt;macOS/linux&lt;/em&gt;, and one for &lt;em&gt;Microsoft Windows&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Make sure that the &lt;strong&gt;macOS/Linux&lt;/strong&gt; tab is selected, because you will run these commands in your AWS Cloud9 environment.&lt;br&gt;&lt;br&gt;
First, you will copy and run the command to log in your Docker client to your registry.&lt;/p&gt;

&lt;p&gt;In the pop-up window, locate the &lt;em&gt;first&lt;/em&gt; command and then copy the command to the clipboard by choosing the &lt;strong&gt;Copy&lt;/strong&gt; icon.&lt;/p&gt;

&lt;p&gt;The command looks like the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 01234567890.dkr.ecr.us-east-1.amazonaws.com/mb-repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;![[Pasted image 20240113111016.png]]&lt;br&gt;&lt;br&gt;
If the command runs successfully, it returns the message &lt;em&gt;Login Succeeded&lt;/em&gt;. You can ignore the displayed warnings.&lt;br&gt;&lt;br&gt;
Next, you will build the Docker image for your application.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;: When a specific terminal tab is not mentioned in an instruction step, use the &lt;em&gt;left&lt;/em&gt; terminal tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, change the directory to the &lt;strong&gt;2-containerized-monolith&lt;/strong&gt; folder by entering the following command:&lt;br&gt;&lt;br&gt;
    &lt;code&gt;cd ~/environment/2-containerized-monolith&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Push commands for mb-repo&lt;/strong&gt; window, locate the &lt;em&gt;second&lt;/em&gt; command and copy the command by choosing the &lt;strong&gt;Copy&lt;/strong&gt; icon.&lt;/p&gt;

&lt;p&gt;The command looks like the following example:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker build -t mb-repo .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;br&gt;&lt;br&gt;
In the terminal tab, paste the copied command and run it by pressing ENTER:&lt;br&gt;&lt;br&gt;
![[Pasted image 20240113111259.png]]&lt;br&gt;&lt;br&gt;
The &lt;em&gt;build&lt;/em&gt; command produces multiples lines of output as it runs the instructions that are in the application's &lt;em&gt;Dockerfile&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
When it is finished, you see the messages &lt;em&gt;Successfully built nnnnnnnnnn&lt;/em&gt; and &lt;em&gt;Successfully tagged mb-repo:latest&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Next, you will tag the image with the repository URI so that it can be pushed the repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Push commands for mb-repo&lt;/strong&gt; window, locate the &lt;em&gt;third&lt;/em&gt; command and choose the &lt;strong&gt;Copy&lt;/strong&gt; icon.&lt;/p&gt;

&lt;p&gt;The command looks like the following example:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker tag mb-repo:latest 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-repo:latest&lt;/code&gt;&lt;br&gt;&lt;br&gt;
![[Pasted image 20240113111610.png]]&lt;br&gt;&lt;br&gt;
The command does not return anything if it completed successfully.&lt;/p&gt;

&lt;p&gt;Finally, you will push the container image to the application's repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Push commands for mb-repo&lt;/strong&gt; window, locate the &lt;em&gt;fourth&lt;/em&gt; command and copy it.&lt;/p&gt;

&lt;p&gt;The command looks like the following example:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker push 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;br&gt;&lt;br&gt;
In the terminal tab, paste and run the copied command:&lt;br&gt;&lt;br&gt;
    ![[Pasted image 20240113111751.png]]&lt;br&gt;&lt;br&gt;
The command outputs several messages as each layer of the image is pushed to the repository.&lt;br&gt;&lt;br&gt;
Next, you will verify that the image was successfully uploaded.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;br&gt;&lt;br&gt;
Close the &lt;strong&gt;Push commands for mb-repo&lt;/strong&gt; window.&lt;br&gt;&lt;br&gt;
 In the &lt;strong&gt;Repositories&lt;/strong&gt; list, choose &lt;strong&gt;mb-repo&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Images&lt;/strong&gt; list, you should see the container image that you pushed, which you can identify by the &lt;em&gt;latest&lt;/em&gt; tag.&lt;br&gt;&lt;br&gt;
![[Pasted image 20240113111958.png]]&lt;br&gt;&lt;br&gt;
Record the &lt;em&gt;Image URI&lt;/em&gt;. In the &lt;strong&gt;Images&lt;/strong&gt; list, locate the &lt;strong&gt;Image URI&lt;/strong&gt; of the &lt;em&gt;latest&lt;/em&gt; version of the image, and choose the &lt;strong&gt;Copy&lt;/strong&gt; icon. Paste the value in a text editor. You will use it in a subsequent step.&lt;/p&gt;

&lt;p&gt;You have successfully created a container image for the message board application, and you have also pushed it to an Amazon ECR repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Task 4: Deploying the Monolith to Amazon ECS
&lt;/h3&gt;

&lt;p&gt;In this task, you deploy the containerized monolithic application to an Amazon ECS runtime environment. Specifically, you use Amazon ECS to create a managed cluster of Amazon Elastic Compute Cloud (Amazon EC2) instances. You will deploy your application container image to this cluster. The cluster is configured as the target group of an Application Load Balancer, which will provide failover and scalability.&lt;/p&gt;

&lt;p&gt;The following diagram shows the deployment architecture of the containerized monolithic application. It also displays the resources that you will create in this task.&lt;br&gt;&lt;br&gt;
![[Pasted image 20240111122506.png]]&lt;br&gt;&lt;br&gt;
The steps that you perform in this task are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an Amazon ECS cluster.&lt;/li&gt;
&lt;li&gt;Create a task definition for the application container image.&lt;/li&gt;
&lt;li&gt;Create the Application Load Balancer.&lt;/li&gt;
&lt;li&gt;Deploy the monolithic application as an ECS Service.&lt;/li&gt;
&lt;li&gt;Test the containerized monolithic application.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;[!caution]&lt;br&gt;&lt;br&gt;
Before you create an Amazon ECS cluster CREATE a separate VPC and Subnet (with the IP block supplied) under the VPC service.Then return to the ECS window and follow the instructions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Task 4.1: Creating an Amazon ECS Cluster
&lt;/h4&gt;

&lt;p&gt;An Amazon ECS cluster is a logical grouping of EC2 instances where you can run tasks or services that represent your containerized application.&lt;/p&gt;

&lt;p&gt;In this subtask, you will create an ECS cluster by using the Amazon ECS console. The console's cluster creation wizard enables you to create all the infrastructure components that are needed to create the ECS cluster environment. These components include the virtual private cloud (VPC), subnets, security groups, internet gateway, and AWS Identity and Access Management (IAM) roles.&lt;/p&gt;

&lt;p&gt;Go back to the &lt;strong&gt;AWS Management Console&lt;/strong&gt; browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and then select &lt;strong&gt;Containers &amp;gt; Elastic Container Service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the navigation pane, choose &lt;strong&gt;Amazon ECS &amp;gt; Clusters&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: Verify that the new ECS experience toggle button is set to off. The instructions below assume you are using the older ECS experience.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Clusters&lt;/strong&gt; page, choose &lt;strong&gt;Create Cluster&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Select cluster template&lt;/strong&gt; page, select the &lt;strong&gt;EC2 Linux + Networking&lt;/strong&gt; card.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Configure cluster&lt;/strong&gt; wizard, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Cluster name&lt;/strong&gt;: &lt;code&gt;mb-ecs-cluster&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Provisioning Model&lt;/strong&gt;: &lt;em&gt;On-Demand Instance&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;EC2 instance type&lt;/strong&gt;: &lt;em&gt;t2.micro&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Number of instances&lt;/strong&gt;: &lt;code&gt;2&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;VPC&lt;/strong&gt;: &lt;em&gt;Create a new VPC&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;CIDR block&lt;/strong&gt;: &lt;code&gt;10.32.0.0/16&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Subnet 1&lt;/strong&gt;: &lt;code&gt;10.32.0.0/24&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Subnet 2&lt;/strong&gt;: &lt;code&gt;10.32.1.0/24&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Security group&lt;/strong&gt;: &lt;em&gt;Create a new security group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Security group inbound rules&lt;/strong&gt;: Leave it at the default setting, which allows inbound traffic from all IP addresses on port 80.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The message in the &lt;strong&gt;Container instance IAM role&lt;/strong&gt; section states that you are granting permissions to Amazon ECS to create and use the &lt;strong&gt;ecsInstanceRole&lt;/strong&gt;. This role authorizes the EC2 instances in the cluster to invoke Amazon ECS actions.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Launch Status&lt;/strong&gt; page opens, and shows the tasks that the wizard performs.&lt;br&gt;&lt;br&gt;
Wait until all tasks have a check mark, which indicates that they are complete.  &lt;/p&gt;

&lt;p&gt;The resources that the wizard creates are listed in the &lt;strong&gt;Cluster Resources&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View Cluster&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The details page for the &lt;em&gt;mb-ecs-cluster&lt;/em&gt; opens. The &lt;strong&gt;Status&lt;/strong&gt; field shows a value of &lt;em&gt;ACTIVE&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Choose the &lt;strong&gt;ECS Instances&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;The two EC2 instances for the cluster (which the wizard created) are listed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: It might take a few minutes for the two EC2 instances to show in the list. If you do not see both instances, choose &lt;strong&gt;Refresh&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
[image]&lt;/p&gt;

&lt;p&gt;Choose the &lt;strong&gt;Tasks&lt;/strong&gt; tab.&lt;br&gt;&lt;br&gt;
No tasks are deployed to the cluster yet. You will create one next.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 4.2: Creating a Task Definition for the Application Container Image
&lt;/h4&gt;

&lt;p&gt;A task definition is a list of configuration settings for how to run a Docker container on Amazon ECS.&lt;br&gt;&lt;br&gt;
It tells Amazon ECS various kinds of information, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What container image to run&lt;/li&gt;
&lt;li&gt;How much CPU and memory the container needs&lt;/li&gt;
&lt;li&gt;What ports the container listens to traffic on
In this subtask, you will create a task definition for the container image of the message board application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the navigation pane of the &lt;strong&gt;Amazon ECS&lt;/strong&gt; console browser tab, choose &lt;strong&gt;Task Definitions&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Create new Task Definition&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Select launch type compatibility&lt;/strong&gt; page, choose the &lt;strong&gt;EC2&lt;/strong&gt; card.&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Configure task and container definitions&lt;/strong&gt; page opens.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Task Definition Name&lt;/strong&gt; box, enter &lt;code&gt;mb-task&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
Scroll down to &lt;strong&gt;Container Definitions&lt;/strong&gt; and choose &lt;strong&gt;Add container&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Add container&lt;/strong&gt; window opens.&lt;/p&gt;

&lt;p&gt;Configure the following settings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Container name&lt;/strong&gt;: &lt;code&gt;mb-container&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image&lt;/strong&gt;: Paste the &lt;strong&gt;Image URI&lt;/strong&gt; of the application container image, which you copied to a text editor in a previous step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Limits&lt;/strong&gt;: Select &lt;em&gt;Hard limit&lt;/em&gt; and enter &lt;code&gt;256&lt;/code&gt;. (This setting defines the maximum amount of memory that the container is allowed to use.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port mappings &amp;gt; Container port&lt;/strong&gt;: &lt;code&gt;3000&lt;/code&gt; (This setting specifies the port where the container receives requests. You do not need to enter a value in &lt;strong&gt;Host port&lt;/strong&gt;.)
The &lt;strong&gt;Add container&lt;/strong&gt; window should look similar to the following example:
[image]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose &lt;strong&gt;Add&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Scroll down and choose &lt;strong&gt;Create&lt;/strong&gt;. You can ignore any warnings.&lt;br&gt;&lt;br&gt;
A message displays, indicating that the task definition was successfully created. Notice that the definition is automatically assigned the version number of &lt;em&gt;1&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
You now have a task definition that tells Amazon ECS how to deploy your application container across the cluster.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 4.3: Creating the Application Load Balancer
&lt;/h4&gt;

&lt;p&gt;Next, you will create the Application Load Balancer that distributes incoming requests to the EC2 instances that run in the ECS cluster. This load balancer resides in the same VPC and uses the same security group as the ECS cluster.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Amazon ECS&lt;/strong&gt; console browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and then select &lt;strong&gt;Compute &amp;gt; EC2&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the navigation pane, scroll down and select &lt;strong&gt;Load Balancers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create load balancer&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Select load balancer type&lt;/strong&gt; page opens.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Application Load Balancer&lt;/strong&gt; card, choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The Application Load Balancer creation wizard opens.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Configure the following settings:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load balancer name&lt;/strong&gt;: &lt;code&gt;mb-load-balancer&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC&lt;/strong&gt;: Select the &lt;em&gt;Amazon ECS cluster VPC ID&lt;/em&gt;. This ID be similar to &lt;em&gt;vpc-nnnnnnnnnn (10.32.0.0/16)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mappings&lt;/strong&gt;: Select the first two Availability Zones in the list

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security groups&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Clear &lt;em&gt;default&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;em&gt;EC2ContainerService-mb-ecs-cluster-EcsSecurityGroup&lt;/em&gt;. (This is the security group of your ECS cluster.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Listener HTTP:80&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;strong&gt;Create target group&lt;/strong&gt;: &lt;em&gt;New target group&lt;/em&gt; (You want the wizard to create a new target group for the load balancer.)
The target group configuration screen opens in a new browser tab.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Target group type&lt;/strong&gt;: Instances&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target group name&lt;/strong&gt;: &lt;code&gt;mb-load-balancer-target-group&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Leave the protocol settings at their default values of &lt;em&gt;HTTP&lt;/em&gt; and &lt;em&gt;80&lt;/em&gt;. The application expects to be accessed through RESTful HTTP requests.&lt;/li&gt;
&lt;li&gt;VPC: Amazon ECS cluster VPC&lt;/li&gt;
&lt;li&gt;Expand &lt;strong&gt;Advanced health check settings&lt;/strong&gt; and enter the following settings.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Healthy threshold&lt;/strong&gt;: &lt;code&gt;2&lt;/code&gt; (This setting tells the load balancer that the target is considered healthy if it receives two consecutive successful health checks from it.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeout&lt;/strong&gt;: &lt;code&gt;5&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interval&lt;/strong&gt;: &lt;code&gt;6&lt;/code&gt; (This setting increases the frequency of health checks to once every 6 seconds.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Create target group&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Return to the &lt;em&gt;Load balancers&lt;/em&gt; browser tab&lt;/li&gt;
&lt;li&gt;Under Listener HTTP:80, refresh the target groups list. Select the &lt;strong&gt;mb-load-balancer-target-group&lt;/strong&gt; you just created.&lt;/li&gt;
&lt;li&gt;Scroll to the bottom of the page and choose &lt;strong&gt;Create load balancer&lt;/strong&gt;.
A message should indicate that the load balancer was successfully created.
Choose &lt;strong&gt;Close&lt;/strong&gt;.
The &lt;em&gt;mb-load-balancer&lt;/em&gt; is now in the load balancer list.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Wait a few moments, then choose the &lt;strong&gt;Refresh&lt;/strong&gt; icon. The &lt;strong&gt;State&lt;/strong&gt; of the load balancer should change to &lt;em&gt;active&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
[image]&lt;/p&gt;

&lt;p&gt;To complete the load balancer configuration, you will modify its security group to open the ports that allow internal communication between the load balancer and the instances in the ECS cluster.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Description&lt;/strong&gt; tab at the bottom, scroll down to the &lt;strong&gt;Security&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;Next to &lt;strong&gt;Security Groups&lt;/strong&gt;, choose the security group ID link, which should be similar to &lt;em&gt;sg-nnnnnnnnnn&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The details page of the load balancer's security group opens.&lt;/p&gt;

&lt;p&gt;To copy the security group ID to the clipboard, go to the &lt;strong&gt;Details&lt;/strong&gt; tab (in the bottom pane), hover your pointer over the &lt;strong&gt;security group ID&lt;/strong&gt;, and choose the &lt;strong&gt;Copy&lt;/strong&gt; icon.&lt;/p&gt;

&lt;p&gt;You will use this ID in a subsequent step.&lt;/p&gt;

&lt;p&gt;In the bottom pane, select the &lt;strong&gt;Inbound rules&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;The inbound rules for the security group are displayed.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Edit inbound rules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Edit inbound rules&lt;/strong&gt; dialog window opens.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Add rule&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
A new line appears in the rules list so that you can add a new rule. It is already preconfigured for a &lt;em&gt;Custom TCP Rule&lt;/em&gt;, which is the type that you want to add.&lt;/p&gt;

&lt;p&gt;In the new line, add the following configuration.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Port Range&lt;/strong&gt;: &lt;code&gt;31000-61000&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Source &amp;gt; Custom&lt;/strong&gt;: Paste the security group ID from the clipboard.
Choose &lt;strong&gt;Save rules&lt;/strong&gt;.
The security group's inbound rules list shows the new rule that you added.
[image]&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Task 4.4: Deploying the Monolith as an ECS Service
&lt;/h4&gt;

&lt;p&gt;You have created all the required Amazon ECS infrastructure components. In this subtask, you will deploy the containerized monolithic application to the cluster as an Amazon ECS service.&lt;/p&gt;

&lt;p&gt;An ECS service enables you to simultaneously run and maintain a specified number of task definition instances in an ECS cluster. If one of the tasks fails or stops for any reason, the ECS service scheduler launches another task definition instance to replace it. Thus, it will maintain the desired count of tasks that were specified in the service.&lt;/p&gt;

&lt;p&gt;You will now create an ECS service for the message board application's task definition by using the Amazon ECS console.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;AWS Management Console&lt;/strong&gt; browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and select &lt;strong&gt;Containers &amp;gt; Elastic Container Service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the navigation pane, choose &lt;strong&gt;Task Definitions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Task Definition&lt;/strong&gt; list, choose the &lt;strong&gt;mb-task&lt;/strong&gt; link.&lt;/p&gt;

&lt;p&gt;A page opens with the available revisions of the task definition.&lt;/p&gt;

&lt;p&gt;Select &lt;strong&gt;mb-task:1&lt;/strong&gt; and choose &lt;strong&gt;Actions &amp;gt; Create Service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Configure service&lt;/strong&gt;, configure these settings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Launch type&lt;/strong&gt;: &lt;em&gt;EC2&lt;/em&gt; (You are running the containerized application directly on a cluster of EC2 instances.)

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Service name&lt;/strong&gt;: &lt;code&gt;mb-ecs-service&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service type&lt;/strong&gt;: &lt;em&gt;REPLICA&lt;/em&gt; (This setting establishes a scheduling strategy that places and maintains the desired number of tasks across the ECS cluster.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number of tasks&lt;/strong&gt;: &lt;code&gt;1&lt;/code&gt; (Normally, to take full advantage of the cluster, you would enter a higher number, depending on the request load that you expect. However, to keep things simple in this exercise, you specify that you want to launch and maintain one task on the cluster at all times.)
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Configure network&lt;/strong&gt;, configure the following settings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load balancer type&lt;/strong&gt;: &lt;em&gt;Application Load Balancer&lt;/em&gt; (You want the tasks in your service to be load balanced by the &lt;em&gt;mb-load-balancer&lt;/em&gt; that you set up earlier)

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Service IAM role&lt;/strong&gt;: &lt;em&gt;Create new role&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load balancer name&lt;/strong&gt;: &lt;em&gt;mb-load-balancer&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Container name:port&lt;/strong&gt;: This field is already populated with the correct container information that is associated with the task definition. Choose &lt;strong&gt;Add to load balancer&lt;/strong&gt;. (This setting will associate the container with one of the load balancer's listeners.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production listener port&lt;/strong&gt;: &lt;em&gt;80:HTTP&lt;/em&gt; (This setting associates the container with the load balancer listener for HTTP traffic on port 80)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target group name&lt;/strong&gt;: &lt;em&gt;mb-load-balancer-target-group&lt;/em&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;strong&gt;Step 3: Set Auto Scaling (optional)&lt;/strong&gt;, choose &lt;strong&gt;Next step&lt;/strong&gt;. You do not want to configure any additional automatic scaling.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Review&lt;/strong&gt; page, make sure that the settings are correct and choose &lt;strong&gt;Create Service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Launch Status&lt;/strong&gt; page opens, and shows the tasks that the wizard performs.&lt;/p&gt;

&lt;p&gt;Wait until all tasks display check marks, which indicate that they are complete.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
To open the details page for &lt;em&gt;mb-ecs-service&lt;/em&gt;, choose &lt;strong&gt;View Service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Tasks&lt;/strong&gt; tab shows that there is now one task that is running the container, with a status of &lt;em&gt;ACTIVATING&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After a few moments, choose &lt;strong&gt;Refresh&lt;/strong&gt;. The task's &lt;strong&gt;Last status&lt;/strong&gt; should show: &lt;em&gt;RUNNING&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
You have successfully deployed the containerized monolith as an ECS service into the cluster.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 4.5: Testing the Containerized Monolith
&lt;/h4&gt;

&lt;p&gt;You will now validate your deployment by testing the RESTful API methods of the message board application from a web browser.&lt;br&gt;&lt;br&gt;
First, you will find and record the URL of the load balancer.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Amazon ECS&lt;/strong&gt; console browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and select &lt;strong&gt;Compute &amp;gt; EC2&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In the navigation pane, scroll down and choose &lt;strong&gt;Load Balancers&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The load balancer list shows the &lt;strong&gt;mb-load-balancer&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Description&lt;/strong&gt; tab at the bottom, go to &lt;strong&gt;DNS name&lt;/strong&gt; and choose the &lt;strong&gt;Copy&lt;/strong&gt; icon.&lt;br&gt;&lt;br&gt;
Paste the DNS name value into a text editor, and label it &lt;code&gt;Load Balancer DNS Name&lt;/code&gt;. You will use this value multiple times in later steps.&lt;br&gt;&lt;br&gt;
Open a new browser tab, paste the DNS name into the address bar, and press ENTER.&lt;/p&gt;

&lt;p&gt;The page opens with the message &lt;em&gt;Ready to receive requests&lt;/em&gt;. This message is returned by the message board application when no resource path is included in the GET request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Troubleshooting tip&lt;/strong&gt;: If you get a server-related HTTP error code, wait a few moments and then try again. It might take a few minutes for the container to register as healthy and begin receiving traffic.&lt;/p&gt;

&lt;p&gt;In the browser address bar, add &lt;code&gt;/api&lt;/code&gt; to the end of the URL and press ENTER.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
The application should return the message &lt;em&gt;API ready to receive requests&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Test the retrieval of all &lt;em&gt;users&lt;/em&gt; in the database. In the browser address bar, add &lt;code&gt;/users&lt;/code&gt; to the end of the URL and press ENTER.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
The application returns a JSON object that lists the four users in the database.&lt;/p&gt;

&lt;p&gt;Retrieve the information for the &lt;em&gt;first user&lt;/em&gt; in the database. In the browser address bar, add &lt;code&gt;/1&lt;/code&gt; to the end of the URL and press &lt;strong&gt;Enter&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
The application returns a JSON object that contains the information for &lt;em&gt;Marcerline Singer&lt;/em&gt;, who is the first user in the database.&lt;/p&gt;

&lt;p&gt;Next, you will retrieve all the &lt;em&gt;threads&lt;/em&gt; in the database. In the browser address bar, change the URI after the load balancer DNS name to &lt;code&gt;/api/threads&lt;/code&gt; and press ENTER.&lt;br&gt;&lt;br&gt;
The application returns a JSON object that contains the three threads in the database.&lt;/p&gt;

&lt;p&gt;Finally, retrieve the &lt;em&gt;posts&lt;/em&gt; for the &lt;em&gt;second thread&lt;/em&gt; in the database. In the browser address bar, change the URI after the load balancer DNS name to &lt;code&gt;/api/posts/in-thread/2&lt;/code&gt; and press ENTER.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
The application returns a JSON object that contains the posted messages for the second thread in the database. The messages are bakery-related.&lt;/p&gt;

&lt;p&gt;Optionally, invoke other resource paths that the application can serve. When you are finished testing, close the application browser tab.&lt;br&gt;&lt;br&gt;
You have now successfully containerized the monolithic message board application and deployed it to an Amazon ECS environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Task 5: Refactoring the Monolith
&lt;/h3&gt;

&lt;p&gt;In this task, you will break the containerized monolithic message board application into several interconnected microservices. You will then push each microservice image to an Amazon ECR repository. Each microservice performs a single business capability of the application, and can be scaled independently of the other microservices. The application is divided into the following microservices, which represent the top-level classes of objects that the application's API serves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Users&lt;/em&gt; microservice – A service for all &lt;em&gt;user&lt;/em&gt;-related REST paths (&lt;code&gt;/api/users/*&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Threads&lt;/em&gt; microservice – A service for all &lt;em&gt;thread&lt;/em&gt;-related REST paths (&lt;code&gt;/api/threads/*&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Posts&lt;/em&gt; microservice – A service for all &lt;em&gt;post&lt;/em&gt;-related REST paths (&lt;code&gt;/api/posts/*&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To expedite the refactoring, a microservices version of the application is provided to you in the &lt;strong&gt;3-containerized-microservices&lt;/strong&gt; folder of your AWS Cloud9 environment.&lt;/p&gt;

&lt;p&gt;The steps that you perform in this task are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Review the refactored microservices application&lt;/li&gt;
&lt;li&gt;Provision an Amazon ECR repository for each microservice&lt;/li&gt;
&lt;li&gt;Build and push the images for each microservice
#### Task 5.1: Reviewing the Refactored Microservices Application
In this subtask, you will Take a few minutes to review the files to help you understand the changes that were made to refactor the application into microservices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.  &lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Environment&lt;/strong&gt; pane on the left, expand the &lt;strong&gt;3-containerized-microservices&lt;/strong&gt; folder.&lt;br&gt;&lt;br&gt;
This folder now has three separate subfolders named &lt;strong&gt;posts&lt;/strong&gt;, &lt;strong&gt;threads&lt;/strong&gt;, and &lt;strong&gt;users&lt;/strong&gt;, which represent the three application microservices. Each subfolder contains the implementation files for the corresponding microservice. &lt;/p&gt;

&lt;p&gt;Expand the &lt;strong&gt;posts&lt;/strong&gt;, &lt;strong&gt;threads&lt;/strong&gt;, and &lt;strong&gt;users&lt;/strong&gt; subfolders.&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
Notice that each subfolder contains a copy of the same application files as those of the containerized monolith application. The &lt;em&gt;db.json&lt;/em&gt;, &lt;em&gt;Dockerfile&lt;/em&gt;, and &lt;em&gt;package.json&lt;/em&gt; files in each subfolder are identical to their containerized monolith counterparts. The &lt;em&gt;server.js&lt;/em&gt; file is the only file that changed from the refactoring.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;users&lt;/strong&gt; subfolder, open &lt;strong&gt;server.js&lt;/strong&gt; in an editor tab by double-clicking it.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Lines 13 through 20&lt;/strong&gt; differ from the containerized monolith version in that the program defines only the API methods and implementations that are related to the &lt;em&gt;users&lt;/em&gt; resource paths.&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;Threads&lt;/em&gt; subfolder, open &lt;strong&gt;server.js&lt;/strong&gt; in an editor tab by double-clicking it.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Lines 13 through 20&lt;/strong&gt; differ from the containerized monolith version in that the program defines only the API methods and implementations that are related to the &lt;em&gt;threads&lt;/em&gt; resource paths.&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;posts&lt;/em&gt; subfolder, open &lt;strong&gt;server.js&lt;/strong&gt; in an editor tab by double-clicking it.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Lines 13 through 21&lt;/strong&gt; differ from the containerized monolith version in that the program defines only the API methods and implementations that are related to the &lt;em&gt;posts&lt;/em&gt; resource paths.&lt;br&gt;&lt;br&gt;
In summary, the only change that is required to refactor the application is to split the RESTful API method handlers in the monolithic version of &lt;em&gt;server.js&lt;/em&gt; into three separate &lt;em&gt;server.js&lt;/em&gt; files. Each individual &lt;em&gt;server.js&lt;/em&gt; file contains a relevant subset of the API method handlers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 5.2: Provisioning an Amazon ECR Repository for Each Microservice
&lt;/h4&gt;

&lt;p&gt;Similar to what you did for the containerized monolith version, you will now create an Amazon ECR repository for each application microservice.&lt;/p&gt;

&lt;p&gt;You will now create a repository for the &lt;em&gt;Users&lt;/em&gt;, &lt;em&gt;Threads&lt;/em&gt;, and &lt;em&gt;Posts&lt;/em&gt; microservice container images.&lt;/p&gt;

&lt;p&gt;To open the Amazon ECR console, go to the &lt;strong&gt;AWS Management Console&lt;/strong&gt; browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and then select &lt;strong&gt;Containers &amp;gt; Elastic Container Registry&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create repository&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Repository name&lt;/strong&gt;, enter &lt;code&gt;mb-users-repo&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create repository&lt;/strong&gt;. A message is displayed at the top of the page indicating that the repository was successfully created.  &lt;/p&gt;

&lt;p&gt;Repeat the previous steps to create two repositories for the other two microservices, with the following repository information.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Threads&lt;/em&gt; repository name: &lt;code&gt;mb-threads-repo&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Posts&lt;/em&gt; repository name: &lt;code&gt;mb-posts-repo&lt;/code&gt;
When you have created the repositories for all three microservices, the &lt;em&gt;Repositories&lt;/em&gt; list should look like the following example:
[image]&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Task 5.3: Building and Pushing the Images for Each Microservice
&lt;/h4&gt;

&lt;p&gt;Next, you will build each microservice container image and push it to its corresponding repository. In the following steps, you will use the ready-to-use commands that are provided by the Amazon ECR console to complete the task.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Building And Pushing the &lt;em&gt;Users&lt;/em&gt; microservice&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;You will start with the container image for the &lt;em&gt;Users&lt;/em&gt; microservice.&lt;br&gt;&lt;br&gt;
Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.  &lt;/p&gt;

&lt;p&gt;In the terminal tab, change the directory to the &lt;strong&gt;3-containerized-microservices/users&lt;/strong&gt; folder by entering the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;cd ~/environment/3-containerized-microservices/users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Repositories&lt;/strong&gt; list, select &lt;strong&gt;mb-users-repo&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At the top of the page, choose &lt;strong&gt;View push commands&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Push commands for mb-users-repo&lt;/strong&gt; pop-up window opens.&lt;br&gt;&lt;br&gt;
First, you will build the Docker image for the microservice.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Push commands for mb-users-repo&lt;/strong&gt; window, copy the &lt;em&gt;second&lt;/em&gt; command to the clipboard by selecting the &lt;strong&gt;Copy&lt;/strong&gt; icon next to it. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker build -t mb-users-repo .&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;: Make sure to include the period (.) at the end of the command.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, paste the copied command and run it by pressing ENTER.&lt;br&gt;&lt;br&gt;
    When the command is finished, you should see the messages &lt;em&gt;Successfully built nnnnnnnnnn&lt;/em&gt; and &lt;em&gt;Successfully tagged mb-users-repo:latest&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    Next, you will tag the image with the repository URI so that it can be pushed the repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Push commands for mb-users-repo&lt;/strong&gt; window, copy the &lt;em&gt;third&lt;/em&gt; command to the clipboard by selecting the &lt;strong&gt;Copy&lt;/strong&gt; icon next to it. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker tag mb-users-repo:latest 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-users-  repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, paste the copied command and run it by pressing ENTER.&lt;br&gt;&lt;br&gt;
    The command does not return anything if it completed successfully.&lt;br&gt;&lt;br&gt;
    Finally, push the container image to the microservice repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Push commands for mb-users-repo&lt;/strong&gt; window, copy the &lt;em&gt;fourth&lt;/em&gt; command to the clipboard by selecting the &lt;strong&gt;Copy&lt;/strong&gt; icon next to it. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker push 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-users-repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, paste the copied command and run it by pressing ENTER.&lt;br&gt;&lt;br&gt;
The command outputs several messages as each layer of the image is pushed to the repository.&lt;br&gt;&lt;br&gt;
You will now verify that the image was successfully uploaded.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab and close the &lt;strong&gt;Push commands for mb-users-repo&lt;/strong&gt; pop-up window.&lt;/p&gt;

&lt;p&gt;Choose the &lt;strong&gt;Refresh&lt;/strong&gt; icon.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Images&lt;/strong&gt; list, you see the container image that you pushed identified by the &lt;em&gt;latest&lt;/em&gt; tag.&lt;/p&gt;

&lt;p&gt;Record the &lt;em&gt;Image URI&lt;/em&gt;. In the &lt;strong&gt;Images&lt;/strong&gt; list, locate the &lt;em&gt;Image URI&lt;/em&gt; of the &lt;em&gt;latest&lt;/em&gt; version of the image and choose the &lt;strong&gt;Copy&lt;/strong&gt; icon next to it.&lt;/p&gt;

&lt;p&gt;Paste the value in a text editor and label it as &lt;code&gt;Users Image URI&lt;/code&gt;. You will use it in a later step.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Building And Pushing the &lt;em&gt;Threads&lt;/em&gt; microservice&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Next, you will build and push the container image for the &lt;em&gt;Threads&lt;/em&gt; microservice.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab. &lt;/p&gt;

&lt;p&gt;In the terminal tab, change the directory to the &lt;strong&gt;3-containerized-microservices/threads&lt;/strong&gt; folder by entering the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;cd ~/environment/3-containerized-microservices/threads&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the navigation pane, choose &lt;strong&gt;Repositories&lt;/strong&gt; and in the &lt;strong&gt;Repositories&lt;/strong&gt; list, select &lt;strong&gt;mb-threads-repo&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View push commands&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The &lt;strong&gt;Push commands for mb-threads-repo&lt;/strong&gt; pop-up window opens.&lt;br&gt;&lt;br&gt;
    First, you will build the Docker image for the microservice.&lt;/p&gt;

&lt;p&gt;In the pop-up window, copy the &lt;em&gt;second&lt;/em&gt; command by selecting the &lt;strong&gt;Copy&lt;/strong&gt; icon. The command should look like:&lt;br&gt;&lt;br&gt;
    &lt;code&gt;docker build -t mb-threads-repo .&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: Make sure to include the period (.) at the end of the command.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, paste the copied command and run it.&lt;br&gt;&lt;br&gt;
When the command is finished, you see the messages &lt;em&gt;Successfully built nnnnnnnnnn&lt;/em&gt; and &lt;em&gt;Successfully tagged mb-threads-repo:latest&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
Next, you will tag the image with the repository URI so that it can be pushed the repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the pop-up window, copy the &lt;em&gt;third&lt;/em&gt; command by selecting the &lt;strong&gt;Copy&lt;/strong&gt; icon. The command should look like:&lt;br&gt;&lt;br&gt;
    &lt;code&gt;docker tag mb-threads-repo:latest 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-threads-repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, paste the copied command and run it.&lt;br&gt;&lt;br&gt;
The command does not return anything if it completed successfully.&lt;br&gt;&lt;br&gt;
Finally, you will push the container image to the microservice repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;br&gt;&lt;br&gt;
 In the pop-up window, copy the &lt;em&gt;fourth&lt;/em&gt; command by selecting the &lt;strong&gt;Copy&lt;/strong&gt; icon. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker push 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-threads-repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Terminal&lt;/strong&gt; tab, paste the copied command and run it.&lt;br&gt;&lt;br&gt;
The command outputs several messages as each layer of the image is pushed to the repository.&lt;br&gt;&lt;br&gt;
You will now verify that the image was successfully uploaded.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab and close the &lt;strong&gt;Push commands for mb-threads-repo&lt;/strong&gt; pop-up window.&lt;/p&gt;

&lt;p&gt;Choose the &lt;strong&gt;Refresh&lt;/strong&gt; icon.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Images&lt;/strong&gt; list, you should see the container image that you pushed, which can be identified by the &lt;em&gt;latest&lt;/em&gt; tag.&lt;/p&gt;

&lt;p&gt;Record the &lt;em&gt;Image URI&lt;/em&gt;. In the &lt;strong&gt;Images&lt;/strong&gt; list, go to the &lt;em&gt;Image URI&lt;/em&gt; for &lt;em&gt;latest&lt;/em&gt; version and choose the &lt;strong&gt;Copy&lt;/strong&gt; icon.&lt;/p&gt;

&lt;p&gt;Paste the value in a text editor and label it as &lt;code&gt;Threads Image URI&lt;/code&gt;. You will use it in a later step.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Building And Pushing the &lt;em&gt;Posts&lt;/em&gt; microservice&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Lastly, you will build and push the container image for the &lt;em&gt;Posts&lt;/em&gt; microservice.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, change the directory to the &lt;strong&gt;3-containerized-microservices/posts&lt;/strong&gt; folder by entering the following command:&lt;br&gt;&lt;br&gt;
&lt;code&gt;cd ~/environment/3-containerized-microservices/posts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the navigation pane, choose &lt;strong&gt;Repositories&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Repositories&lt;/strong&gt; list, select &lt;strong&gt;mb-posts-repo&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View push commands&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Push commands for mb-posts-repo&lt;/strong&gt; pop-up window opens.&lt;br&gt;&lt;br&gt;
First, you will build the Docker image for the microservice.&lt;/p&gt;

&lt;p&gt;In the pop-up window, copy the &lt;em&gt;second&lt;/em&gt; command. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker build -t mb-posts-repo .&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: Make sure that you include the period (.) at the end of the command.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the terminal tab, paste and run the copied command.&lt;br&gt;&lt;br&gt;
When the command is finished, you see the messages &lt;em&gt;Successfully built nnnnnnnnnn&lt;/em&gt; and &lt;em&gt;Successfully tagged mb-posts-repo:latest&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
Next, you will tag the image with the repository URI so that it can be pushed the repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the pop-up window, copy the &lt;em&gt;third&lt;/em&gt; command. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker tag mb-posts-repo:latest 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-posts-repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Terminal&lt;/strong&gt; tab, paste and run the copied command.&lt;/p&gt;

&lt;p&gt;The command does not return anything if it completed successfully.&lt;/p&gt;

&lt;p&gt;Finally, you will push the container image to the microservice repository.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;In the pop-up window, copy the &lt;em&gt;fourth&lt;/em&gt; command. The command should look like:&lt;br&gt;&lt;br&gt;
&lt;code&gt;docker push 1234567890.dkr.ecr.us-east-2.amazonaws.com/mb-posts-repo:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;AWS Cloud9 IDE&lt;/strong&gt; browser tab.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Terminal&lt;/strong&gt; tab, paste and run the copied command.&lt;br&gt;&lt;br&gt;
The command outputs several messages as each layer of the image is pushed to the repository.&lt;br&gt;&lt;br&gt;
You will now verify that the image was successfully uploaded.&lt;/p&gt;

&lt;p&gt;Switch to the &lt;strong&gt;Amazon ECR&lt;/strong&gt; console browser tab.&lt;/p&gt;

&lt;p&gt;Close the &lt;strong&gt;Push commands for mb-posts-repo&lt;/strong&gt; pop-up window.&lt;/p&gt;

&lt;p&gt;Choose the &lt;strong&gt;Refresh&lt;/strong&gt; icon.&lt;br&gt;&lt;br&gt;
In the &lt;strong&gt;Images&lt;/strong&gt; list, you should see the container image that you pushed, which should have the &lt;em&gt;latest&lt;/em&gt; tag.&lt;/p&gt;

&lt;p&gt;Record the Image URI. In the &lt;strong&gt;Images&lt;/strong&gt; list, copy the &lt;em&gt;Image URI&lt;/em&gt; of the &lt;em&gt;latest&lt;/em&gt; version of the image.&lt;/p&gt;

&lt;p&gt;Paste the value in a text editor and label it as &lt;code&gt;Posts Image URI&lt;/code&gt;. You will use it in a later step.&lt;br&gt;&lt;br&gt;
You have successfully built container images for the microservices in your application and pushed them to Amazon ECR.&lt;/p&gt;

&lt;h3&gt;
  
  
  Task 6: Deploying the Containerized Microservices
&lt;/h3&gt;

&lt;p&gt;In this task, you will deploy the containerized microservices message board application to the same ECS cluster that you used for the containerized monolith. You will also use the same Application Load Balancer from before. However, in this task, you will configure it to route requests to different target groups (one for each microservice container) based on the request URI path.&lt;/p&gt;

&lt;p&gt;The following diagram shows the deployment architecture of the containerized microservices application. It also displays the resources that you will create.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3HjA_vDd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/MtxsCTe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3HjA_vDd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/MtxsCTe.png" alt="" width="800" height="461"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
The steps that you perform in this task are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a task definition for each microservice.&lt;/li&gt;
&lt;li&gt;Configure the Application Load Balancer&lt;/li&gt;
&lt;li&gt;Deploy the microservices as ECS services.&lt;/li&gt;
&lt;li&gt;Validate the deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Task 6.1: Creating a Task Definition for Each Microservice
&lt;/h4&gt;

&lt;p&gt;Because the microservices in the application are intended to run independently of each other, they each require their own task definition. In this subtask, you will create three task definitions that run the container image of each individual microservice.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating A Task Definition for the &lt;em&gt;Users&lt;/em&gt; container&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;You will start by creating the task definition for the &lt;em&gt;Users&lt;/em&gt; microservice container.&lt;/p&gt;

&lt;p&gt;In the navigation pane of the &lt;strong&gt;Amazon ECS&lt;/strong&gt; console, choose &lt;strong&gt;Task definitions&lt;/strong&gt;, and then choose &lt;strong&gt;Create new Task Definition&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may need to expand the menu in the navigation pane to find &lt;strong&gt;Task Definitions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Select launch type compatibility&lt;/strong&gt; page, select the &lt;strong&gt;EC2&lt;/strong&gt; card.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In &lt;strong&gt;Step 2: Configure task and container definitions&lt;/strong&gt;, configure the following settings:&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Task Definition Name&lt;/strong&gt;: &lt;code&gt;mb-users-task&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - Scroll to the &lt;strong&gt;Container Definitions&lt;/strong&gt; section and choose &lt;strong&gt;Add container&lt;/strong&gt;. In the &lt;strong&gt;Add container&lt;/strong&gt; page, enter these settings.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Container name&lt;/strong&gt;: &lt;code&gt;mb-users-container&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Image&lt;/strong&gt;: Paste the &lt;em&gt;Users Image URI&lt;/em&gt; that you copied to a text editor in a previous step.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Memory Limits&lt;/strong&gt;: Make sure that &lt;em&gt;Hard limit&lt;/em&gt; is selected, and enter &lt;code&gt;256&lt;/code&gt;. (This defines the maximum amount of memory that the container is allowed to use.)&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Port mappings &amp;gt; Container port&lt;/strong&gt;: &lt;code&gt;3000&lt;/code&gt; (This specifies the port on which the container receives requests.)&lt;br&gt;&lt;br&gt;
    - Choose &lt;strong&gt;Add&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Scroll-down and choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A message indicates that the task definition was successfully created. Notice that the definition is automatically assigned the version number of &lt;em&gt;1&lt;/em&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating A Task Definition for the &lt;em&gt;Threads&lt;/em&gt; container&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Next, you will create the task definition for the &lt;em&gt;Threads&lt;/em&gt; microservice container.&lt;br&gt;&lt;br&gt;
In the navigation pane, select &lt;strong&gt;Task Definitions&lt;/strong&gt; and choose &lt;strong&gt;Create new Task Definition&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Select launch type compatibility&lt;/strong&gt;, select the &lt;strong&gt;EC2&lt;/strong&gt; card.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Configure task and container definitions&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Task Definition Name&lt;/strong&gt;: &lt;code&gt;mb-threads-task&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
    - Scroll to the &lt;strong&gt;Container Definitions&lt;/strong&gt; section and choose &lt;strong&gt;Add container&lt;/strong&gt;. In the &lt;strong&gt;Add container&lt;/strong&gt; page that opens, enter these settings.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Container name&lt;/strong&gt;: &lt;code&gt;mb-threads-container&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Image&lt;/strong&gt;: Paste the &lt;strong&gt;Threads Image URI&lt;/strong&gt; that you copied to a text editor.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Memory Limits&lt;/strong&gt;: Make sure that &lt;em&gt;Hard limit&lt;/em&gt; is selected, and enter &lt;code&gt;256&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Port mappings &amp;gt; Container port&lt;/strong&gt;: &lt;code&gt;3000&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - Choose &lt;strong&gt;Add&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Scroll-down and choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A message indicates that the task definition was successfully created. The definition is automatically assigned the version number of &lt;em&gt;1&lt;/em&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating A Task Definition for the &lt;em&gt;Posts&lt;/em&gt; container&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Lastly, you will now create the task definition for the &lt;em&gt;Posts&lt;/em&gt; microservice container.&lt;/p&gt;

&lt;p&gt;In the navigation pane, select &lt;strong&gt;Task Definitions&lt;/strong&gt; and then choose &lt;strong&gt;Create new Task Definition&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Select launch type compatibility&lt;/strong&gt;, select the &lt;strong&gt;EC2&lt;/strong&gt; card.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Configure task and container definitions&lt;/strong&gt;, configure these settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Task Definition Name&lt;/strong&gt;: &lt;code&gt;mb-posts-task&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - Scroll down to the &lt;strong&gt;Container Definitions&lt;/strong&gt; section and choose &lt;strong&gt;Add container&lt;/strong&gt;. In the &lt;strong&gt;Add container&lt;/strong&gt; page, enter these settings.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Container name&lt;/strong&gt;: &lt;code&gt;mb-posts-container&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Image&lt;/strong&gt;: Paste the &lt;em&gt;Posts Image URI&lt;/em&gt; that you copied.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Memory Limits&lt;/strong&gt;: Make sure that &lt;em&gt;Hard limit&lt;/em&gt; is selected, and enter &lt;code&gt;256&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Port mappings &amp;gt; Container port&lt;/strong&gt;: &lt;code&gt;3000&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - Choose &lt;strong&gt;Add&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Scroll down and choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A message indicates that the task definition was successfully created. The definition is automatically assigned the version number of &lt;em&gt;1&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 6.2: Configuring the Application Load Balancer
&lt;/h4&gt;

&lt;p&gt;In this subtask, you will create a new load balancer target group for each microservice so that requests can be routed to their container. You also configure the load balancer listener rule to forward requests to the correct target group, based on the request URI path.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating A Target Group for the &lt;em&gt;Users&lt;/em&gt; microservice&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;In the &lt;strong&gt;Amazon ECS&lt;/strong&gt; console browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and then select &lt;strong&gt;Compute &amp;gt; EC2&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the navigation pane, scroll down and choose &lt;strong&gt;Target Groups&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create target group&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Specify group details&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Target group name&lt;/strong&gt;: &lt;code&gt;mb-lb-users-target-group&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;VPC&lt;/strong&gt;: Select the &lt;em&gt;load balancer VPC ID&lt;/em&gt;. It should be similar to &lt;em&gt;vpc-nnnnnnnnnn (10.32.0.0/16)&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    - Scroll down, expand &lt;strong&gt;Advanced health check settings&lt;/strong&gt;, and enter these settings.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Healthy threshold&lt;/strong&gt;: &lt;code&gt;2&lt;/code&gt; (This setting tells the load balancer that if it receives two consecutive successful health checks from a target, the target is considered healthy)&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Interval&lt;/strong&gt;: &lt;code&gt;6&lt;/code&gt; (This increases the frequency of health checks to once every 6 seconds)&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Register targets,&lt;/strong&gt; choose &lt;strong&gt;Create target group&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A window opens with a message that the target group was successfully created.&lt;/p&gt;

&lt;p&gt;Close the message window.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;mb-lb-users-target-group&lt;/em&gt; appears in the target group list.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating A Target Group for the &lt;em&gt;Threads&lt;/em&gt; microservice&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Next, you will create a target group for the &lt;em&gt;Threads&lt;/em&gt; microservice.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Create target group&lt;/strong&gt; and in &lt;strong&gt;Step 1: Specify group details&lt;/strong&gt;, configure these settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Target group name&lt;/strong&gt;: &lt;code&gt;mb-lb-threads-target-group&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;VPC&lt;/strong&gt;: Select the &lt;em&gt;load balancer VPC ID&lt;/em&gt;. It should be similar to &lt;em&gt;vpc-nnnnnnnnnn (10.32.0.0/16)&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - In the &lt;strong&gt;Advanced health check settings&lt;/strong&gt; section, enter these settings.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Healthy threshold&lt;/strong&gt;: &lt;code&gt;2&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Interval&lt;/strong&gt;: &lt;code&gt;6&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Register targets&lt;/strong&gt;, choose &lt;strong&gt;Create target group&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A window opens with a message that the target group was successfully created.&lt;/p&gt;

&lt;p&gt;Close the message window.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;mb-lb-threads-target-group&lt;/em&gt; appears in the target group list.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating A Target Group for the &lt;em&gt;Posts&lt;/em&gt; microservice&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Lastly, you will create a target group for the &lt;em&gt;Posts&lt;/em&gt; microservice.&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Create target group&lt;/strong&gt; and configure these settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Target group name&lt;/strong&gt;: &lt;code&gt;mb-lb-posts-target-group&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;VPC&lt;/strong&gt;: Select the &lt;em&gt;load balancer VPC&lt;/em&gt; ID. It should be similar to &lt;em&gt;vpc-nnnnnnnnnn (10.32.0.0/16)&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    - In the &lt;strong&gt;Advanced health check settings&lt;/strong&gt; section, enter these settings.&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Healthy threshold&lt;/strong&gt;: &lt;code&gt;2&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;strong&gt;Interval&lt;/strong&gt;: &lt;code&gt;6&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next&lt;/strong&gt;, and then choose &lt;strong&gt;Create target group&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A window opens with a message that the target group was successfully created.&lt;/p&gt;

&lt;p&gt;Close the message window.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;mb-lb-posts-target-group&lt;/em&gt; appears in the target group list.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating Listener Rules for the Load balancers&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;You have created the target groups for each microservice. You will modify the listener rules for the load balancer. These rules will route traffic to each load balancer, based on the request URI path.&lt;/p&gt;

&lt;p&gt;Open the details page for &lt;em&gt;mb-load-balancer&lt;/em&gt; by going to the navigation pane and selecting &lt;strong&gt;Load Balancers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the bottom pane, choose the &lt;strong&gt;Listeners&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;Select the &lt;strong&gt;HTTP:80&lt;/strong&gt; listener and then from the &lt;strong&gt;Actions&lt;/strong&gt; menu choose &lt;strong&gt;Manage rules&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The rules editor opens.&lt;br&gt;&lt;br&gt;
    You will now create a new rule to forward a request to the &lt;em&gt;Users&lt;/em&gt; target group if the request URI matches the pattern &lt;code&gt;/api/users*&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the tool bar at the top of the editor, add a new rule by choosing the &lt;strong&gt;Add rules&lt;/strong&gt; (&lt;strong&gt;+&lt;/strong&gt;) icon.&lt;br&gt;&lt;br&gt;
    An &lt;em&gt;Insert Rule&lt;/em&gt; line appears in the rules list.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Insert Rule&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    A rules box appears allowing you to add an &lt;em&gt;IF&lt;/em&gt; condition and a &lt;em&gt;THEN&lt;/em&gt; action.&lt;/p&gt;

&lt;p&gt;Configure the following settings for this rule.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add condition&lt;/strong&gt;: &lt;em&gt;Path&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;is &amp;gt; Value&lt;/strong&gt;: &lt;code&gt;/api/users*&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add action&lt;/strong&gt;: &lt;em&gt;Forward to&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Forward to &amp;gt; Target group&lt;/strong&gt;: &lt;em&gt;mb-lb-users-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
        The rules box should look like the following example:&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Save&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The rule is added to the list as rule &lt;em&gt;1&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    You will now create a rule to forward a request to the &lt;strong&gt;Threads&lt;/strong&gt; target group if the request URI matches the pattern &lt;code&gt;/api/threads*&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the line below &lt;em&gt;rule 1&lt;/em&gt;, choose &lt;strong&gt;Insert Rule&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The rules editor opens.&lt;/p&gt;

&lt;p&gt;Configure the following settings for this rule.&lt;br&gt;&lt;br&gt;
    - Add condition*&lt;em&gt;: &lt;em&gt;Path&lt;/em&gt;&lt;/em&gt;*&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;is &amp;gt; Value&lt;/strong&gt;: &lt;code&gt;/api/threads*&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add action&lt;/strong&gt;: &lt;em&gt;Forward to**&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Forward to &amp;gt; Target group&lt;/strong&gt;: &lt;em&gt;mb-lb-threads-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Save&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The rule is added to the list as rule &lt;em&gt;2&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    You will now create a new rule to forward a request to the &lt;strong&gt;Posts&lt;/strong&gt; target group if the request URI matches the pattern &lt;code&gt;/api/posts*&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the line below &lt;em&gt;rule 2&lt;/em&gt;, choose &lt;strong&gt;Insert Rule&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the rules editor, configure these settings:&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add condition&lt;/strong&gt;: &lt;em&gt;Path&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;is &amp;gt; Value&lt;/strong&gt;: &lt;code&gt;/api/posts*&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add action&lt;/strong&gt;: &lt;em&gt;Forward to&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Forward to &amp;gt; Target group&lt;/strong&gt;: &lt;em&gt;mb-lb-posts-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Save&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The rule is added to the list as rule &lt;em&gt;3&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    Now, you will create a new rule to forward a request to the &lt;strong&gt;Users&lt;/strong&gt; target group if the request URI matches the patterns of &lt;code&gt;/&lt;/code&gt; or &lt;code&gt;/api&lt;/code&gt;. You could select any of the application's target groups because their corresponding microservice can handle both types of requests.&lt;/p&gt;

&lt;p&gt;In the line below &lt;em&gt;rule 3&lt;/em&gt;, choose &lt;strong&gt;Insert Rule&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the rules editor, configure these settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add condition&lt;/strong&gt;: &lt;em&gt;Path&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;is &amp;gt; Value&lt;/strong&gt;: &lt;code&gt;/&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;or &amp;gt; Value&lt;/strong&gt;: &lt;code&gt;/api&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Add action&lt;/strong&gt;: &lt;em&gt;Forward to&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Forward to &amp;gt; Target group&lt;/strong&gt;: &lt;em&gt;mb-lb-users-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Save&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The rule is added to the list as rule &lt;em&gt;4&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    Lastly, you will change the action for the &lt;em&gt;last&lt;/em&gt; (default) rule so that any other request URI returns an error page with the message &lt;em&gt;Invalid request&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In the tool bar at the top, choose the &lt;strong&gt;Edit rules&lt;/strong&gt; (pencil) icon.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The rules editor switches to edit mode.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Scroll to the &lt;em&gt;last&lt;/em&gt; rule and choose the &lt;strong&gt;Edit Rule&lt;/strong&gt; (pencil) icon.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the rules editor, configure these settings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Then&lt;/strong&gt;: Delete the existing &lt;em&gt;Forward to&lt;/em&gt; action by choosing the &lt;strong&gt;Delete&lt;/strong&gt; (trashcan) icon.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add action&lt;/strong&gt;: &lt;em&gt;Return fixed response&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response code&lt;/strong&gt;: &lt;code&gt;200&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response body&lt;/strong&gt;: &lt;code&gt;Invalid request&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The rules editor should look like this example:&lt;br&gt;&lt;br&gt;
[image]&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Update&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
A message indicates that the rule was successfully updated.&lt;br&gt;&lt;br&gt;
The final listener rules for the load balancer should look like this example:&lt;br&gt;&lt;br&gt;
[image]&lt;/p&gt;

&lt;p&gt;To return to the load balancer details page, choose the &lt;strong&gt;Back arrow&lt;/strong&gt; icon (in the top-left area of the window).&lt;br&gt;&lt;br&gt;
    You have completed the required changes to the load balancer configuration.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 6.3: Deploying the Microservices as ECS Services
&lt;/h4&gt;

&lt;p&gt;In this subtask, you will deploy the three microservices to the cluster as ECS services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating an ECS service for &lt;em&gt;Users&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You will now create an ECS service for the &lt;em&gt;Users&lt;/em&gt; microservice task definition.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Amazon EC2 console&lt;/strong&gt; browser tab, choose &lt;strong&gt;Services&lt;/strong&gt;, and then select &lt;strong&gt;Containers &amp;gt; Elastic Container Service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the clusters list, choose &lt;strong&gt;mb-ecs-cluster&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Services&lt;/strong&gt; tab, open the Create Service wizard by choosing &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Configure service&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Launch type&lt;/strong&gt;: &lt;em&gt;EC2&lt;/em&gt; (You are running the containerized microservice directly on a cluster of EC2 instances.)&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Task Definition &amp;gt; Family&lt;/strong&gt;: &lt;em&gt;mb-users-task&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service name&lt;/strong&gt;: &lt;code&gt;mb-users-ecs-service&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service type&lt;/strong&gt;: &lt;em&gt;REPLICA&lt;/em&gt; (This setting establishes a scheduling strategy that places and maintains the desired number of tasks across the ECS cluster)&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Number of tasks&lt;/strong&gt;: &lt;code&gt;1&lt;/code&gt; (For this exercise, you want to launch and maintain one task on the cluster at all times)&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Configure network&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Load balancer type&lt;/strong&gt;: &lt;em&gt;Application Load Balancer&lt;/em&gt; (You want the tasks in your service to be load balanced by the &lt;em&gt;mb-load-balancer&lt;/em&gt; that you set up)&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service IAM role&lt;/strong&gt;: &lt;em&gt;ecsServiceRole&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Load balancer name&lt;/strong&gt;: &lt;em&gt;mb-load-balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Container to load balance&lt;/strong&gt;: &lt;em&gt;Add to load balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Production listener port&lt;/strong&gt;: &lt;em&gt;80:HTTP&lt;/em&gt; (You are associating the container with the load balancer listener that listens for HTTP traffic on port 80)&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Target group name&lt;/strong&gt;: &lt;em&gt;mb-lb-users-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 3: Set Auto Scaling (optional)&lt;/strong&gt;, choose &lt;strong&gt;Next step&lt;/strong&gt;. You do not want to configure any additional automatic scaling.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Review&lt;/strong&gt; page, make sure that the settings are correct and choose &lt;strong&gt;Create Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The &lt;strong&gt;Launch Status&lt;/strong&gt; page opens, and shows the tasks that the wizard performs.&lt;/p&gt;

&lt;p&gt;Wait until all tasks display a check mark to indicate that they are complete.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The details page for &lt;em&gt;mb-users-ecs-service&lt;/em&gt; opens. The &lt;strong&gt;Tasks&lt;/strong&gt; tab shows that there is now one task running the container.&lt;/p&gt;

&lt;p&gt;After a few moments, choose the &lt;strong&gt;Refresh&lt;/strong&gt; button.&lt;br&gt;&lt;br&gt;
    The task's &lt;strong&gt;Last status&lt;/strong&gt; should show a value of &lt;em&gt;RUNNING&lt;/em&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating An ECS Service for &lt;em&gt;Threads&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Next, you will create an ECS service for the &lt;em&gt;Threads&lt;/em&gt; microservice task definition.&lt;/p&gt;

&lt;p&gt;To return to the cluster details page, in the breadcrumb trail at the top of the page, choose &lt;strong&gt;mb-ecs-cluster&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Services&lt;/strong&gt; tab, choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Configure service&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Launch type&lt;/strong&gt;: &lt;em&gt;EC2&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Task Definition &amp;gt; Family&lt;/strong&gt;: &lt;em&gt;mb-threads-task&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service name&lt;/strong&gt;: &lt;code&gt;mb-threads-ecs-service&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service type&lt;/strong&gt;: &lt;em&gt;REPLICA&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Number of tasks&lt;/strong&gt;: &lt;code&gt;1&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Configure network&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Load balancing &amp;gt; Load balancer type&lt;/strong&gt;: &lt;em&gt;Application Load Balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Load balancer name&lt;/strong&gt;: &lt;em&gt;mb-load-balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Container to load balance&lt;/strong&gt;: &lt;em&gt;Add to load balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Production listener port&lt;/strong&gt;: &lt;em&gt;80:HTTP&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Target group name&lt;/strong&gt;: &lt;em&gt;mb-lb-threads-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 3: Set Auto Scaling (optional)&lt;/strong&gt; page, click &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Review&lt;/strong&gt; page, make sure that the settings are correct and choose &lt;strong&gt;Create Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The &lt;strong&gt;Launch Status&lt;/strong&gt; page opens and shows the tasks that the wizard performs.&lt;/p&gt;

&lt;p&gt;Wait until all tasks display a check mark to indicate that they are complete.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The details page for &lt;em&gt;mb-threads-ecs-service&lt;/em&gt; opens. The &lt;strong&gt;Tasks&lt;/strong&gt; tab shows that one task is running the container.&lt;/p&gt;

&lt;p&gt;After a few moments, choose &lt;strong&gt;Refresh&lt;/strong&gt;. The task's &lt;strong&gt;Last status&lt;/strong&gt; shows a value of &lt;em&gt;RUNNING&lt;/em&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Creating An ECS Service for &lt;em&gt;Posts&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Lastly, create an ECS service for the &lt;em&gt;Posts&lt;/em&gt; microservice task definition.&lt;/p&gt;

&lt;p&gt;Return to the cluster details page for &lt;em&gt;mb-ecs-cluster&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Services&lt;/strong&gt; tab, choose &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 1: Configure service&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Launch type&lt;/strong&gt;: &lt;em&gt;EC2&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Task Definition &amp;gt; Family&lt;/strong&gt;: &lt;em&gt;mb-posts-task&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service name&lt;/strong&gt;: &lt;code&gt;mb-posts-ecs-service&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Service type&lt;/strong&gt;: &lt;em&gt;REPLICA&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Number of tasks&lt;/strong&gt;: &lt;code&gt;1&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 2: Configure network&lt;/strong&gt;, configure the following settings.&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Load balancing &amp;gt; Load balancer type&lt;/strong&gt;: &lt;em&gt;Application Load Balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Load balancer name&lt;/strong&gt;: &lt;em&gt;mb-load-balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Container to load balance&lt;/strong&gt;: &lt;em&gt;Add to load balancer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Production listener port&lt;/strong&gt;: &lt;em&gt;80:HTTP&lt;/em&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Target group name&lt;/strong&gt;: &lt;em&gt;mb-lb-posts-target-group&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Step 3L Set Auto Scaling (optional)&lt;/strong&gt;, choose &lt;strong&gt;Next step&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Review&lt;/strong&gt; page, make sure that settings are correct and choose &lt;strong&gt;Create Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The &lt;strong&gt;Launch Status&lt;/strong&gt; page opens and shows the tasks that the wizard performs.&lt;/p&gt;

&lt;p&gt;Wait until all tasks display a check mark to indicate that they are complete.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The details page for &lt;em&gt;mb-posts-ecs-service&lt;/em&gt; opens. The &lt;strong&gt;Tasks&lt;/strong&gt; tab shows that one task is running the container.&lt;/p&gt;

&lt;p&gt;After a few moments, choose &lt;strong&gt;Refresh&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The task's &lt;strong&gt;Last status&lt;/strong&gt; should show a value of &lt;em&gt;RUNNING&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Return to the cluster details page for &lt;em&gt;mb-ecs-cluster&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    The three new services that you created are now in the &lt;strong&gt;Services&lt;/strong&gt; list.&lt;/p&gt;

&lt;p&gt;[image]&lt;/p&gt;

&lt;p&gt;It should only take a few seconds for all your services to start. Double-check that all services and tasks are running and healthy before you proceed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Task 6.4: Validating the Deployment
&lt;/h4&gt;

&lt;p&gt;You will now test the RESTful API methods of the message board application from a web browser. You will also validate that the microservices-based implementation works correctly.&lt;/p&gt;

&lt;p&gt;First, you will shut down the ECS service for the containerized monolith version of the application. You do not want it to serve any requests.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Services&lt;/strong&gt; list, select &lt;strong&gt;mb-ecs-service&lt;/strong&gt;, and choose &lt;strong&gt;Update&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The &lt;strong&gt;Update Service&lt;/strong&gt; wizard opens.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;Number of tasks&lt;/strong&gt;, change the value to &lt;code&gt;0&lt;/code&gt;. (This setting instructs Amazon ECS to not run any tasks for the service.)&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;Skip to review&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Review&lt;/strong&gt; page, choose &lt;strong&gt;Update Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;Launch Status&lt;/em&gt; page opens with a message that the service has been updated.&lt;/p&gt;

&lt;p&gt;Choose &lt;strong&gt;View Service&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
    The details page for &lt;em&gt;mb-ecs-service&lt;/em&gt; opens. The &lt;strong&gt;Deployments&lt;/strong&gt; tab shows that the &lt;strong&gt;Running count&lt;/strong&gt; for the service is &lt;em&gt;0&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    &lt;strong&gt;Note&lt;/strong&gt;: If you do not see the change immediately, wait a few seconds and choose &lt;strong&gt;Refresh&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;[image]&lt;/p&gt;

&lt;p&gt;Open a new browser tab, paste the &lt;em&gt;Load Balancer DNS Name&lt;/em&gt; that you recorded earlier, and press ENTER.&lt;br&gt;&lt;br&gt;
    This action returns the message &lt;em&gt;Ready to receive requests&lt;/em&gt;. The application returns this message when no resource path is included in the GET request. Recall from the listener rules configuration that this type of request is sent to the &lt;em&gt;Users&lt;/em&gt; microservice.&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;/api&lt;/code&gt; to the end of the URL and press ENTER.&lt;br&gt;&lt;br&gt;
    The application—specifically, the &lt;em&gt;Users&lt;/em&gt; microservice—returns the message &lt;em&gt;API ready to receive requests&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Test the retrieval of all &lt;em&gt;users&lt;/em&gt; in the database. Add &lt;code&gt;/users&lt;/code&gt; to the end of the URL and press ENTER.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;Users&lt;/em&gt; microservice returns a JSON object that lists the four users in the database.&lt;/p&gt;

&lt;p&gt;Retrieve the information for the &lt;em&gt;first user&lt;/em&gt; in the database. Add &lt;code&gt;/1&lt;/code&gt; to the end of the URL and press ENTER.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;Users&lt;/em&gt; microservice returns a JSON object that contains the information for &lt;em&gt;Marcerline Singer&lt;/em&gt;, who is the first user in the database.&lt;/p&gt;

&lt;p&gt;Next, retrieve all the &lt;em&gt;threads&lt;/em&gt; in the database. Change the URI after the load balancer DNS name to &lt;code&gt;/api/threads&lt;/code&gt; and press ENTER.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;Threads&lt;/em&gt; microservice returns a JSON object that contains all three threads in the database.&lt;/p&gt;

&lt;p&gt;Retrieve the &lt;em&gt;posts&lt;/em&gt; for the &lt;em&gt;second thread&lt;/em&gt; in the database. Change the URI after the load balancer DNS name to &lt;code&gt;/api/posts/in-thread/2&lt;/code&gt; and press ENTER.&lt;br&gt;&lt;br&gt;
    The &lt;em&gt;Posts&lt;/em&gt; microservice returns a JSON object that contains the posted messages for the second thread (which are bakery-related) in the database.&lt;/p&gt;

&lt;p&gt;Finally, test the submission of a request with an invalid URI. Change the URI after the load balancer DNS name to &lt;code&gt;/xyz&lt;/code&gt; and press ENTER.&lt;br&gt;&lt;br&gt;
    The request is forwarded to default handler in the load balancer's listener rules, which returns the message &lt;em&gt;Invalid request&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
    You have successfully converted a monolithic Node.js application to a microservices architecture. The original application ran, without containerization, directly on an instance. In contrast, microservices-based application is deployed in a containerized environment that is orchestrated by Amazon ECS.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
