<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rebecca Costanzo on Medium]]></title>
        <description><![CDATA[Stories by Rebecca Costanzo on Medium]]></description>
        <link>https://medium.com/@costanzo.rebecca?source=rss-f062ccdae198------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l_nh0hVAccmOBZJdebOePg.png</url>
            <title>Stories by Rebecca Costanzo on Medium</title>
            <link>https://medium.com/@costanzo.rebecca?source=rss-f062ccdae198------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:52:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@costanzo.rebecca/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploy A Jenkins Server With Terraform]]></title>
            <link>https://medium.com/@costanzo.rebecca/deploy-a-jenkins-server-with-terraform-bd35268fec1b?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd35268fec1b</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 03:46:03 GMT</pubDate>
            <atom:updated>2024-03-28T18:10:56.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*kbEfZZd72TN-LctxpckenQ.png" /></figure><h3>Scenario</h3><p><em>Your team would like to use Jenkins as their CI/CD tool to create pipelines for DevOps projects. They need you to create the Jenkins server using Terraform so that it can be used in other environments and so that changes to the environment are better tracked.</em></p><ol><li><em>Deploy 1 EC2 Instance in your Default VPC.</em></li><li><em>Bootstrap the EC2 instance with a script that will install and start Jenkins.</em></li><li><em>Create and assign a Security Group to the Jenkins Security Group that allows traffic on port 22 from your IP and allows traffic from port 8080.</em></li><li><em>Create a S3 bucket for your Jenkins Artifacts that is not open to the public.</em></li><li><em>Verify that you can reach your Jenkins install via port 8080 in your browser. Be sure to include a screenshot of the Jenkins login screen in your documentation.</em></li><li><em>Push your code to GitHub and include the link in your write-up.</em></li></ol><h3>Solution</h3><h4><strong>Step 1: Set up our environment</strong></h4><p>I’ve started up my AWS Cloud9 environment for this project.</p><p>Here’s the code to install and update Terraform on an AWS Linux EC2 instance:</p><pre>sudo yum install -y yum-utils shadow-utils<br>sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo<br>sudo yum -y install terraform</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*qW9KR5hakSNXfDx6spYZfA.png" /></figure><p>Confirm Terraform is installed by checking your version:</p><pre>terraform -v</pre><h4><strong>Step 2: Create a directory and .tf files</strong></h4><p>Create a Jenkins directory. We will call this jenkins_server</p><pre>mkdir jenkins_server</pre><p>Move to that directory using the cd command and create our files:</p><pre>cd jenkins_server<br>touch providers.tf <br>touch main.tf<br>touch variables.tf </pre><p>This is the order we will work with each of the files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*kumLa_--7vQ1k9ux7AFI-A.png" /></figure><p>I’m going to open the providers.tf file first. This file tells Terraform we are using AWS as our provider.</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*-xG6-nB1-zGZ24Mc2dem0Q.png" /></figure><p>Now let’s move to our main.tf file and add the following code:</p><pre>#Create Security Group for Jenkins<br>resource &quot;aws_security_group&quot; &quot;jenkins_sg&quot; {<br>  name        = &quot;jenkins-sg&quot;<br>  description = &quot;Allow port 22 and 8080&quot;<br><br>  ingress {<br>    description = &quot;Allow SSH traffic&quot;<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow 8080 traffic&quot;<br>    from_port   = 8080<br>    to_port     = 8080<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow HTTPS traffic&quot;<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br> tags   = {<br>    Name = &quot;jenkins server security group&quot;<br>  }<br>}<br><br># use data source to get the latest version of the amazon linux 2 ami<br>data &quot;aws_ami&quot; &quot;amazon_linux_2&quot; {<br>  most_recent = true<br>  owners      = [&quot;amazon&quot;]<br>   <br>  filter {<br>    name   = &quot;owner-alias&quot;<br>    values = [&quot;amazon&quot;]<br>  }<br><br>  filter {<br>    name   = &quot;name&quot;<br>    values = [&quot;amzn2-ami-hvm*&quot;]<br>  }<br>}<br><br># launch the ec2 instance and install website<br>resource &quot;aws_instance&quot; &quot;ec2_instance&quot; {<br>  ami                    = data.aws_ami.amazon_linux_2.id<br>  instance_type          = var.instance_type<br>  subnet_id              = var.subnet_id<br>  vpc_security_group_ids = [aws_security_group.jenkins_sg.id]<br>  key_name               = var.key_name<br>  user_data              = file(&quot;install_jenkins.sh&quot;)<br><br>  tags = {<br>    Name = &quot;terraform_web_server&quot;<br>  }<br>}<br><br>#create a private S3 bucket<br>resource &quot;aws_s3_bucket&quot; &quot;buckettf&quot; {<br>  bucket = &quot;luits3-t3rraf0rm-buck3t&quot; #this needs to be globally unique<br><br>  tags = {<br>    Name        = &quot;TerraformS3bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*gc1TTTmCRjNqYOEhwtDJdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*Ue9k5AwngDKgeaC1ZEa7Qw.png" /></figure><p>Finally, move to the variables.tffile and add this code:</p><pre>variable &quot;subnet_id&quot; {<br>    description = &quot;The VPC subnet the instance will be created in&quot;<br>    default = &quot;subnet-&lt;add_number&gt;&quot; #refer to the AWS console for your default subnet<br>}<br><br>variable &quot;vpc_id&quot; {<br>    type = string<br>    default = &quot;vpc-&lt;add_number&gt;&quot; #refer to the AWS console for your default VPC<br>}<br><br>variable &quot;instance_type&quot; {<br>    type = string<br>    default = &quot;t2.micro&quot;<br>}<br><br>variable &quot;key_name&quot; {<br>    type = string<br>    default = &quot;&lt;add_name&gt;&quot; #refer to the AWS console for your key name<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*YJ6VdZR8WR7Hh_QlCkWnvA.png" /></figure><h4><strong>Step 3: Create the install.sh file</strong></h4><p>The last code we need to create is the install file. Create a new file using the touch command and name it install_jenkins.sh :</p><pre>#!/bin/bash<br>sudo yum update &amp;&amp;<br>sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo<br>sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key<br>sudo yum upgrade -y &amp;&amp;<br>sudo amazon-linux-extras install java-openjdk11 -y<br>sudo yum install jenkins -y &amp;&amp;<br>sudo systemctl enable jenkins<br>sudo systemctl start jenkins<br>sudo systemctl status jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*3IleDdtLjJ2In0bGPnSNxg.png" /></figure><h4><strong>Step 4: Initialize Terraform</strong></h4><p>Run the following commands in your terminal:</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*OG_36dI3y7i4GznI3e5qYA.png" /></figure><pre>terraform plan</pre><p>You’ll see your execution plan as the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*uJLnxoAEBEUTJG3UpB9RJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*055kt5EUwt7-vswrq5s6GA.png" /></figure><h4><strong>Step 5: Apply our Terraform configuration</strong></h4><p>Apply the changes to create the resources:</p><pre>terraform apply</pre><p>Confirm the security group and S3 bucket have been created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lEAAu--CsC3B82pan13hUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpSzPUycz8xZfFVIC_3ANA.png" /></figure><h4><strong>Step 6: Verify Jenkins installation with a Screenshot</strong></h4><p>Navigate to http://&lt;public_ip&gt;:<strong>8080</strong> in your browser and follow the Jenkins setup wizard. Once Jenkins is set up, you should see the Jenkins login screen. You can also use <a href="http://kins.io/doc/tutorials/tutorial-for-installing-jenkins-on-AWS/?source=post_page-----ceb02133c913--------------------------------#launching-an-amazon-ec2-instance">these instructions</a> to set up Jenkins in the command line, which is what I did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNtDx5xvL_f4wSEyyzLKlA.png" /></figure><h4>Step 7: Push to GitHub</h4><p><a href="https://github.com/racostanzo/terraformProjects/tree/main">GitHub - racostanzo/terraformProjects</a></p><p>That’s it! Another project completed! If you followed along, I’d love to know how it went.</p><h3>Roadblocks</h3><p>I had some trial and error with my code, and this site was immensely helpful in getting it in working order:</p><p><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs">Terraform Registry</a></p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VQMTTOqC0n5-rWX_.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd35268fec1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Terraform to Deploy A Highly Available 2-Tier Architecture]]></title>
            <link>https://medium.com/@costanzo.rebecca/using-terraform-to-deploy-a-highly-available-2-tier-architecture-accd7829a766?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/accd7829a766</guid>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 03:34:29 GMT</pubDate>
            <atom:updated>2024-03-25T03:34:29.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*AOtIXDpwIekHqpzG1FTUiw.png" /></figure><h3>Scenario</h3><p><em>Create a highly available two-tier AWS architecture containing the following:</em></p><ul><li><em>Custom VPC with:</em></li><li><em>Two Public Subnets for the Web Server Tier</em></li><li><em>Two Private Subnets for the RDS Tier*</em></li><li><em>Appropriate route tables</em></li></ul><ol><li><em>Launch an EC2 Instance with your choice of webserver in each public web tier subnet (Apache, NGINX, etc.).</em></li><li><em>One RDS MySQL Instance (micro) in the private RDS subnets</em></li><li><em>Security Groups properly configured for needed resources ( web servers, RDS)</em></li><li><em>Deploy this using Terraform Cloud as a CI/CD tool to check your build.</em></li><li><em>Push your code to GitHub and include the link in your write-up.</em></li></ol><h3>Solution</h3><h4>Step 1: Set up Terraform Environment</h4><ol><li>Install Terraform on your local machine by following the instructions on the official Terraform website.</li><li>Create a new directory for your Terraform configuration files.</li><li>Initialize a new Terraform project by running terraform init within your project directory.</li></ol><h4>Step 2: Write Terraform Configuration</h4><ol><li>We’ll start by creating a file named main.tf within the project directory to define our infrastructure.</li><li>Define the AWS provider configuration in main.tf:</li></ol><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><ol><li>Next, we need to define our custom VPC, public and private subnets, route tables, and internet gateway:</li></ol><pre>resource &quot;aws_vpc&quot; &quot;custom_vpc&quot; {<br>  cidr_block = &quot;10.0.0.0/16&quot;<br>}<br><br>resource &quot;aws_subnet&quot; &quot;public_subnet&quot; {<br>  vpc_id            = aws_vpc.custom_vpc.id<br>  cidr_block        = &quot;10.0.1.0/24&quot;<br>  availability_zone = &quot;your_az_1&quot;<br>}<br><br>resource &quot;aws_subnet&quot; &quot;private_subnet&quot; {<br>  vpc_id            = aws_vpc.custom_vpc.id<br>  cidr_block        = &quot;10.0.2.0/24&quot;<br>  availability_zone = &quot;your_az_2&quot;<br>}<br><br>resource &quot;aws_internet_gateway&quot; &quot;igw&quot; {<br>  vpc_id = aws_vpc.custom_vpc.id<br>}<br><br>resource &quot;aws_route_table&quot; &quot;public_route_table&quot; {<br>  vpc_id = aws_vpc.custom_vpc.id<br><br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.igw.id<br>  }<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;public_subnet_association&quot; {<br>  subnet_id      = aws_subnet.public_subnet.id<br>  route_table_id = aws_route_table.public_route_table.id<br>}<br><br>resource &quot;aws_route_table&quot; &quot;private_route_table&quot; {<br>  vpc_id = aws_vpc.custom_vpc.id<br>}</pre><ol><li>Next, define the security groups for our web servers and RDS instance:</li></ol><pre>resource &quot;aws_security_group&quot; &quot;web_server_sg&quot; {<br>  vpc_id = aws_vpc.custom_vpc.id<br><br>  // Define inbound and outbound rules as needed<br>}<br><br>resource &quot;aws_security_group&quot; &quot;rds_sg&quot; {<br>  vpc_id = aws_vpc.custom_vpc.id<br><br>  // Define inbound and outbound rules as needed<br>}</pre><ol><li>Launch EC2 instances for the web servers and RDS instance:</li></ol><pre>resource &quot;aws_instance&quot; &quot;web_server&quot; {<br>  count         = 2<br>  ami           = &quot;your_ami_id&quot;<br>  instance_type = &quot;t2.micro&quot;<br>  subnet_id     = aws_subnet.public_subnet.id<br><br>  // Define other necessary attributes<br>}<br><br>resource &quot;aws_db_instance&quot; &quot;rds_instance&quot; {<br>  allocated_storage    = 20<br>  engine               = &quot;mysql&quot;<br>  engine_version       = &quot;5.7&quot;<br>  instance_class       = &quot;db.t2.micro&quot;<br>  name                 = &quot;your_database_name&quot;<br>  username             = &quot;your_database_username&quot;<br>  password             = &quot;your_database_password&quot;<br>  subnet_group_name    = &quot;your_database_subnet_group&quot;<br>  parameter_group_name = &quot;your_database_parameter_group&quot;<br>  vpc_security_group_ids = [aws_security_group.rds_sg.id]<br>}</pre><h4>Step 3: Configure CI/CD with Terraform Cloud</h4><ol><li>Sign up for Terraform Cloud and create a new workspace.</li><li>Connect your workspace to your GitHub repository.</li><li>Configure your Terraform Cloud workspace to trigger runs automatically when changes are pushed to your GitHub repository.</li></ol><h4>Step 4: Push Code to GitHub</h4><p>Here’s my repository:</p><p><a href="https://github.com/racostanzo/terraform2tier">GitHub - racostanzo/terraform2tier</a></p><h4>Step 5: Verify Deployment</h4><ol><li>Monitor the Terraform Cloud dashboard for any runs triggered by changes to your GitHub repository.</li><li>Verify that your infrastructure is provisioned correctly in the AWS Management Console.</li></ol><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JiJMOt92PmnuGXbr.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=accd7829a766" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Auto Scaling Group Deployment]]></title>
            <link>https://medium.com/@costanzo.rebecca/terraform-auto-scaling-group-deployment-681f8b1e07cb?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/681f8b1e07cb</guid>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 03:12:31 GMT</pubDate>
            <atom:updated>2024-03-30T18:49:58.931Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*pgCXXVTS1frRM8FkK0WnsQ.png" /></figure><h3>Scenario</h3><p><em>An e-commerce company needs to handle a surge in traffic during the holiday season. The company wants to ensure that their website remains available and responsive to customers even during high traffic periods.</em></p><p><em>The project can be used to launch an Auto Scaling group that spans two subnets in the default VPC, ensuring high availability and fault tolerance. The Auto Scaling group will automatically scale up or down based on traffic, ensuring that the website remains responsive to customers at all times.</em></p><p><em>To ensure that the instances in the Auto Scaling group are secure, a security group is created that allows traffic from the internet and associates it with the instances. Additionally, a script is included in the user data to launch an Apache web server, ensuring that the website is available to customers.</em></p><p><em>To ensure that the Auto Scaling group has the appropriate capacity, it is set to have a minimum of two instances and a maximum of five. This ensures that the website can handle a surge in traffic during the holiday season, while also minimizing costs during periods of low traffic.</em></p><p><em>To verify that everything is working correctly, the public IP addresses of the two instances are checked. One of the instances is manually terminated to verify that another one spins up to meet the minimum requirement of two instances.</em></p><p><em>Finally, to ensure that the infrastructure is reliable and can be easily managed, an S3 bucket is created and set as the remote backend for Terraform. This ensures that the infrastructure is versioned and can be easily rolled back if necessary.</em></p><h3>Task</h3><ol><li><em>Launch an Auto Scaling group that spans 2 subnets in your default VPC.</em></li><li><em>Create a security group that allows traffic from the internet and associate it with the Auto Scaling group instances.</em></li><li><em>Include a script in your user data to launch an Apache webserver. The Auto Scaling group should have a min of 2 and a max of 5.</em></li><li><em>To verify that everything is working, check the public IP addresses of the two instances. Manually terminate one of the instances to verify that another one spins up to meet the minimum requirement of two instances.</em></li><li><em>Create an S3 bucket and set it as your remote backend.</em></li></ol><h3>Solution</h3><p>To achieve the requirements outlined in the scenario, we will use Terraform to provision and manage our infrastructure. Below is a Terraform configuration that accomplishes this:</p><pre># Define variables for reusability<br>variable &quot;region&quot; {<br>  default = &quot;us-east-1&quot;  # Update with your desired region<br>}<br><br>variable &quot;ami&quot; {<br>  default = &quot;ami-12345678&quot;  # Update with your desired AMI<br>}<br><br>variable &quot;instance_type&quot; {<br>  default = &quot;t2.micro&quot;  # Update with your desired instance type<br>}<br><br>variable &quot;subnet_ids&quot; {<br>  type    = list(string)<br>  default = [&quot;subnet-12345678&quot;, &quot;subnet-87654321&quot;]  # Update with your subnet IDs<br>}<br><br># Configure AWS provider<br>provider &quot;aws&quot; {<br>  region = var.region<br>}<br><br># Create security group allowing traffic from the internet<br>resource &quot;aws_security_group&quot; &quot;web_sg&quot; {<br>  name        = &quot;web_sg&quot;<br>  description = &quot;Security group for web servers&quot;<br><br>  ingress {<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br># Launch configuration with user data to install Apache<br>resource &quot;aws_launch_configuration&quot; &quot;web_launch_config&quot; {<br>  name          = &quot;web_launch_config&quot;<br>  image_id      = var.ami<br>  instance_type = var.instance_type<br><br>  security_groups             = [aws_security_group.web_sg.id]<br>  associate_public_ip_address = true<br><br>  user_data = &lt;&lt;-EOF<br>              #!/bin/bash<br>              yum update -y<br>              yum install httpd -y<br>              systemctl start httpd<br>              systemctl enable httpd<br>              EOF<br>}<br><br># Auto Scaling Group spanning 2 subnets<br>resource &quot;aws_autoscaling_group&quot; &quot;web_asg&quot; {<br>  name                 = &quot;web_asg&quot;<br>  min_size             = 2<br>  max_size             = 5<br>  desired_capacity     = 2<br>  launch_configuration = aws_launch_configuration.web_launch_config.name<br>  vpc_zone_identifier  = var.subnet_ids<br>}<br><br># Output the public IP addresses of the instances<br>output &quot;instance_ips&quot; {<br>  value = aws_instance.web_instances[*].public_ip<br>}<br><br># Manually terminate one instance to verify scaling<br># You can manually terminate an instance via AWS Console or CLI<br><br># Create S3 bucket as remote backend<br>resource &quot;aws_s3_bucket&quot; &quot;terraform_state&quot; {<br>  bucket = &quot;your-unique-bucket-name&quot;  # Update with your desired bucket name<br>  acl    = &quot;private&quot;<br><br>  versioning {<br>    enabled = true<br>  }<br>}<br><br># Configure Terraform to use S3 as remote backend<br>terraform {<br>  backend &quot;s3&quot; {<br>    bucket = aws_s3_bucket.terraform_state.bucket<br>    key    = &quot;terraform.tfstate&quot;<br>    region = var.region<br>  }<br>}</pre><p>Before applying the Terraform configuration, make sure to replace placeholder values like ami, subnet_ids, and region with your actual values. Additionally, ensure you have the appropriate AWS credentials configured.</p><p>Once you’ve set up the Terraform configuration file, you can initialize Terraform by running:</p><pre>terraform init<br>terraform apply</pre><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*nxm8EDunphz61G-l.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=681f8b1e07cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Application Deployment with a Docker Ubuntu Container]]></title>
            <link>https://medium.com/@costanzo.rebecca/web-application-deployment-with-a-docker-ubuntu-container-23f7763addad?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/23f7763addad</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 03:00:23 GMT</pubDate>
            <atom:updated>2024-03-25T03:00:23.338Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*MOmkVw2BPB5jgiBWyjLB2w.png" /></figure><h3>Problem</h3><p><em>1. Run a Docker Ubuntu container running detached and on port 80</em></p><p><em>2. Using BASH shell update all packages within the container.</em></p><p><em>3. Using BASH install Apache2 on the Ubuntu container.</em></p><p><em>4. Add a custom webpage.</em></p><p><em>5. Verify you can reach the web server from your browser.</em></p><h3>Benefits of Docker Containers</h3><p>Docker containers offer several benefits, which have contributed to their widespread adoption in software development and deployment environments.</p><ol><li>Portability: Docker containers have an application and dependencies in a single unit, making them highly portable across different environments. Developers can then build their application and run it anywhere with consistent behavior.</li><li>Isolation: Containers provide lightweight isolation, ensuring each application runs in an isolated environment. This isolation enhances security by preventing applications from interfering with each other and reduces the likelihood of dependency conflicts.</li><li>Consistency: Docker containers ensure consistency between development, testing, and production environments. Since the entire runtime environment is packaged with the application, developers can be confident that the application will behave the same across different environments.</li><li>Resource Efficiency: Containers share the host system’s kernel and resources, leading to better resource utilization than traditional virtual machines. They start quickly and have minimal overhead, making them ideal for scaling applications and optimizing resource usage.</li><li>Scalability: Docker containers enable horizontal scaling of applications by adding additional container instances to handle increased workload demands. Container orchestration tools like Kubernetes further simplify the management of containerized applications at scale.</li><li>Version Control and Rollback: Docker images are versioned, allowing developers to track changes to the application’s environment over time. This enables easy rollback to previous versions if issues arise, providing a safety net during deployment.</li><li>Continuous Integration and Deployment (CI/CD): Docker containers are well-suited for CI/CD pipelines, allowing for automated application testing, deployment, and rollback. Containers provide a consistent environment for running tests and deploying applications, streamlining the development workflow.</li><li>Microservices Architecture: Docker containers facilitate the adoption of microservices architecture by decomposing monolithic applications into smaller, independently deployable services. Each microservice can run in its container, making it easier to develop, deploy, and scale complex applications.</li><li>Ecosystem and Community: Docker has a vibrant ecosystem and a large community of developers contributing to its growth. This ecosystem includes various tools, services, and integrations that extend Docker’s capabilities and address various use cases.</li></ol><h3>Solution</h3><h4><strong>1. Run a Docker Ubuntu container detached on port 80:</strong></h4><pre>docker run -d -p 80:80 ubuntu</pre><p>This command will run a Docker container in detached mode (-d) using the Ubuntu image, and it will map port 80 of the host to port 80 of the container (-p 80:80).</p><h4><strong>2. Update all packages within the container:</strong></h4><pre>docker exec -it &lt;container_id&gt; bash -c &quot;apt-get update &amp;&amp; apt-get upgrade -y&quot;</pre><p>This command will update the package lists for upgrades and then upgrade all installed packages (-y flag means ‘yes’ to all prompts).</p><h4><strong>3. Install Apache2 on the Ubuntu container:</strong></h4><pre>docker exec -it &lt;container_id&gt; bash -c &quot;apt-get install apache2 -y&quot;</pre><p>This command installs the Apache2 web server on the Ubuntu container.</p><h4><strong>4. Add a custom webpage:</strong></h4><p>You can create a custom webpage and copy it into the container. Let’s assume you have a webpage named index.html:</p><pre>docker cp index.html &lt;container_id&gt;:/var/www/html/</pre><p>This command copies the index.html file into the /var/www/html/ directory of the container.</p><h4>5. Verify you can reach the web server from your browser:</h4><p>Open a web browser and navigate to <a href="http://localhost/">http://localhost</a> or http://&lt;docker_host_ip&gt; (replace &lt;docker_host_ip&gt; with your Docker host IP address). If everything is set up correctly, you should see your custom webpage.</p><p>That’s it! Mission complete.</p><p>If you’re a visual learner like me. You’ll appreciate this video: <a href="https://www.youtube.com/watch?v=kICnD0pRBZU">How to Run Ubuntu as a Docker Container</a></p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*xmGvtB-7WrHyO3yq.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23f7763addad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure and Efficient Infrastructure Management with Linux]]></title>
            <link>https://medium.com/@costanzo.rebecca/secure-and-efficient-infrastructure-management-with-linux-6b9c858cc764?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b9c858cc764</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 02:27:00 GMT</pubDate>
            <atom:updated>2024-03-29T19:18:15.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*XiFMgh13KAX2Pxzn9Hw-Bw.png" /></figure><h3>Background</h3><p><em>In the competitive banking landscape, Level Up Bank aims to continuously update its IT infrastructure to meet operational and customer service demands. With a growing team spanning Development, Operations, and Analytics, prioritizing a secure and efficient user management system is vital. This system must ensure seamless data accessibility and interdepartmental operations and uphold stringent data privacy and security standards. Crucially, it involves effectively managing IT resources, including segregating data and system access based on departmental roles. As the team expands, safeguarding individual user profiles becomes imperative, respecting privacy and ensuring compliance with regulations. Additionally, automation is key for handling repetitive administrative tasks, enhancing efficiency and scalability. Overall, this project aligns with Level Up Bank’s business needs, offering practical skills applicable to roles in system administration and DevOps within growing organizations.</em></p><h3>Objective</h3><p><em>As the root user, successfully run a bash script that can do the following:</em></p><ol><li><em>Create three directories: Development, Operations, Analytics</em></li><li><em>Add several blank dummy files to each directory using the appropriate commands.</em></li><li><em>Create three groups in Linux: Developers, Operations, Data Analysts</em></li><li><em>Each group should only have view and access to their respective directory.</em></li><li><em>Create the following users with the associated information: Jess Waller, username= jwaller, email=jwaller@‌</em><a href="http://levelupbank.com/"><em>levelupbank.com</em></a><em>, group= Developers; Blake Dorsey, username= bdorsey, email=bdorsey@‌</em><a href="http://levelupbank.com/"><em>levelupbank.com</em></a><em>, group= Operations; Joey Ewart, username= jewart, email=</em><a href="/service/mailto:jewart@levelupbank.com"><em>jewart@levelupbank.com</em></a><em>, group= Data Analysts</em></li><li><em>Switch to each newly created user and verify that they can only see the directories associated with their group and can view and open the files in the directory.</em></li><li><em>Set permissions so that users can only view their profile.</em></li><li><em>Verify that each user can only view their profile.</em></li></ol><h3>Solution</h3><p>Because I didn’t want to create users, files, and folders on my Macbook Air, I launched an Amazon Linux 2023 AMI EC2 instance and worked in the <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-linux-inst-eic.html">EC2 Instance Connect</a>. I verified the user name and clicked <strong>Connect</strong> to open a terminal window right in my browser. Once connected, switch to the root user using the sudo command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*usOkOy5EmIRQu-PD222-ZQ.png" /></figure><h4><strong>Create directories</strong></h4><p>We’ll start by creating our three directories:</p><pre>mkdir Development Operations Analytics</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUVQJYAJLKbH0FuIsVZFIA.png" /><figcaption>The ls command confirms our directories</figcaption></figure><h4>Add dummy files</h4><p>Next, we’ll add three dummy files to each directory:</p><pre>touch Development/file1 Development/file2 Development/file3<br>touch Operations/file1 Operations/file2 Operations/file3<br>touch Analytics/file1 Analytics/file2 Analytics/file3</pre><p>You can cdinto each to confirm the files are there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*UNiMnWwnG89g0OZHeFk53A.png" /></figure><h4>Create groups</h4><p>Our next step is to create the three groups.</p><pre>groupadd Developers<br>groupadd Operations<br>groupadd DataAnalysts</pre><p>You can confirm these have been created with the tail /etc/group command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*nKX5VJaTZF7CxdI4ILdOMg.png" /></figure><h4>Set directory permissions</h4><p>Next, set up the permissions. The chowncommand allows you to change ownership of directories and their contents. The command chmod 770 means the owner of the file and the group can read, write, and execute it. This configuration would allow the owner full access, the group read and execute access, and deny access to others.</p><pre>chown :Developers Development/<br>chown :Operations Operations/<br>chown :DataAnalysts Analytics/<br><br>chmod 770 Development/<br>chmod 770 Operations/<br>chmod 770 Analytics/</pre><h4>Create users</h4><p>Add users using the following format:</p><pre>sudo useradd -m -g Developers -s /bin/bash -c &quot;Jess Waller &lt;jwaller@levelupbank.com&gt;&quot; jwaller<br>sudo useradd -m -g Operations -s /bin/bash -c &quot;Blake Dorsey &lt;bdorsey@levelupbank.com&gt;&quot; bdorsey<br>sudo useradd -m -g DataAnalysts -s /bin/bash -c &quot;Joey Ewart &lt;jewart@levelupbank.com&gt;&quot; jewart</pre><h4>Update passwords</h4><p>Update the password for each user using the sudo passwd &lt;user&gt;command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*okVt4iUYquGu4Nyr-bFX8g.png" /></figure><p>I can confirm my users and their information using the cat /etc/passwd | grep &lt;username&gt; command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*12-PiXvM95UnJfoee4sNGQ.png" /></figure><h4>Move the directories</h4><p>The following commands will set up our user permissions:</p><pre>mv /home/ec2-user/Development /<br>mv /home/ec2-user/Operations /<br>mv /home/ec2-user/Analytics /</pre><h4>Confirm user permissions</h4><p>Log into each user to confirm they can only access their respective directories:</p><pre>su - &lt;username&gt;</pre><p>Enter the user’s password and then check each of the directories using the cd command.</p><p>That’s it! You’ve successfully set up the directories, permissions, groups, and users. If you followed along, let me know how it went.</p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*tjB-__0T9xuy-5jx.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b9c858cc764" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stopping EC2 Instances on a Schedule using Boto3, Lambda, and EventBridge]]></title>
            <link>https://awstip.com/stopping-ec2-instances-on-a-schedule-using-boto3-lambda-and-eventbridge-9df253daa037?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/9df253daa037</guid>
            <category><![CDATA[aws-eventbridge]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 19:29:02 GMT</pubDate>
            <atom:updated>2024-03-27T19:26:51.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*5qRv4GdeGT3__K3baOwi0w.png" /></figure><h3>Scenario</h3><p><em>Our DevOps engineering team often uses a development lab to test our application’s releases. The Managers are complaining about the rising cost of our development lab and need to save money by stopping our three EC2 instances after the Development engineers have clocked out at 7:00 pm Pacific Time. We want to confirm that only our Development instances are stopped to ensure nothing in Production is accidentally stopped. Use your script in a Lambda function using Python 3.7 or higher runtime. Make sure the lambda runs on a set schedule daily.</em></p><h3>Solution</h3><p>Let’s start by creating a Python script that stops EC2 instances with our Dev tag and then deploy it as an AWS Lambda function.</p><pre>import boto3<br>from datetime import datetime, timezone<br><br>def stop_dev_instances(event, context):<br>    # Set up AWS clients<br>    ec2_client = boto3.client(&#39;ec2&#39;)<br><br>    # Get current time in Pacific Timezone<br>    current_time = datetime.now(timezone.utc)<br>    current_time = current_time.astimezone(timezone(-timedelta(hours=7))) # Convert to Pacific Time<br><br>    # Check if it&#39;s after 7:00 pm Pacific Time<br>    if current_time.hour &gt;= 19:<br>        # Get list of instances with &#39;Dev&#39; tag<br>        response = ec2_client.describe_instances(Filters=[{&#39;Name&#39;: &#39;tag:Environment&#39;, &#39;Values&#39;: [&#39;Dev&#39;]}])<br><br>        # Extract instance IDs<br>        instance_ids = []<br>        for reservation in response[&#39;Reservations&#39;]:<br>            for instance in reservation[&#39;Instances&#39;]:<br>                instance_ids.append(instance[&#39;InstanceId&#39;])<br><br>        # Stop instances<br>        if instance_ids:<br>            ec2_client.stop_instances(InstanceIds=instance_ids)<br>            print(&quot;Stopped the following instances:&quot;, instance_ids)<br>        else:<br>            print(&quot;No instances with &#39;Dev&#39; tag found.&quot;)<br><br>    else:<br>        print(&quot;It&#39;s not yet time to stop instances.&quot;)<br><br># For testing purposes<br>if __name__ == &quot;__main__&quot;:<br>    stop_dev_instances(None, None)</pre><p>Now we need to create an AWS Lambda function with a trigger set to run on a schedule:</p><ul><li>Go to the AWS Management Console and open the AWS Lambda console. Click on <strong><em>Create function</em></strong>.</li><li>Choose <strong><em>Author from scratch</em></strong>.</li><li>Add the details like the function name, runtime (Python 3.7 or higher), and permissions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycbkv1yN0j6Kq9n2QS8E6g.png" /></figure><ul><li>Click <strong><em>Create function</em></strong>.</li><li>In the <strong><em>Function code</em></strong> section, paste your Python script.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*msuz636R86gn0IBqkVhjkA.png" /></figure><ul><li>Set up a CloudWatch Events trigger by clicking on <strong><em>Add trigger</em></strong>, then select <strong><em>CloudWatch Events</em></strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*3T57b5XegioUXjomUK3H9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3o3yC2Tv4UQTvbzhwBTpXg.png" /></figure><ul><li>Configure the trigger to run on a daily schedule at 7:00 PM Pacific Time.</li><li>Click on <strong><em>Add</em></strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0DSUv2aoeNIpLyFtP-A95A.png" /></figure><ul><li>Review your settings and click on <strong><em>Create function</em></strong>.</li></ul><p>Now, our Lambda function will run daily at 7:00 PM Pacific Time and stop EC2 instances with the Dev tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bwfzh9dlLAk6WP4d17YURg.png" /></figure><p>Let’s check our work by testing some EC2 instances in my AWS account.</p><h4>Create multiple EC2 instances.</h4><p>Start by creating multiple EC2 instances. I like to use an AMI I created for a <a href="https://medium.com/@costanzo.rebecca/launching-an-ec2-instance-with-apache-creating-an-ami-and-working-in-cli-91dae6c6ccc4">previous project</a>, so I launched three of those. Make sure to use the Dev tag with these instances so they will stop with our Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XCkl9dPhkhEfJ9kNY2_qOQ.png" /><figcaption>Click the launch instance from AMI.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1wHRvZ_Mw5GohylK4hnKw.png" /><figcaption>Confirm the number of instances and that you’re duplicating your AMI, and then launch!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*OqZGncaNtFU4JHvCiu0q1Q.jpeg" /><figcaption>Add tags for the instances.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GPLNeH3kTpsV5TicTA8OFg.png" /><figcaption>Here are my three instances.</figcaption></figure><p>Now we wait for 7:00 pm Pacific Time to confirm our function worked. Here is our proof:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjzteDgTgNi1g7-fiA9y9A.png" /></figure><p>If you worked along with my guide, please let me know how it went.</p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*VoAsCoGDhRS4Qp3y.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9df253daa037" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/stopping-ec2-instances-on-a-schedule-using-boto3-lambda-and-eventbridge-9df253daa037">Stopping EC2 Instances on a Schedule using Boto3, Lambda, and EventBridge</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Docker Swarm]]></title>
            <link>https://medium.com/@costanzo.rebecca/setting-up-docker-swarm-4d7adf32580d?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d7adf32580d</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker-swarm]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 17:53:18 GMT</pubDate>
            <atom:updated>2024-03-24T19:25:02.687Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*pGVTkEOYlGkb6PMI_85Cpw.png" /></figure><h3>Scenario</h3><p><em>Your company is new to using containers and has had issues with containerized workloads failing for their global shipping application. The company is worried about additional potential data loss as they have no way to reschedule containers that are failing. The company has one week to update its infrastructure and leverage the use of Docker Swarm so that data can be restored for the containers that are no longer in a healthy state. Because they are unfamiliar with Docker Swarm, they will need a step-by-step guide on setting up a Swarm for their containerized workloads to assist with container orchestration.</em></p><p><em>The solution should include using a global service since the company’s global shipping application is having issues. Your Swarm should be able to launch the containers using a global service. Remember, a service is simply a group of containers of the same image that facilitates the scaling of applications. Your global shipping application will require the use of at least three networked hosts, which should be AWS EC2 Ubuntu 20.04 instances.</em></p><p><strong><em>Problem: </em></strong><em>As the junior engineer, you are responsible for only configuring Docker Swarm and providing your team with a step-by-step guide to setting up the Swarm. You should assume that there are new team members who may not have Docker installed on their devices. Your swarm creation should include the following steps via your remote SSH terminal in VSCode:</em></p><ul><li><em>Installing docker on all hosts</em></li><li><em>Verifying that docker is in an active state</em></li><li><em>Change the hostname on each node to identify the master node and the two worker nodes</em></li><li><em>Validating the worker nodes all share the same security group as the master node</em></li><li><em>Be sure to add your SSH key to each node</em></li><li><em>Running the necessary containers using the CLI</em></li><li><em>Creating the Swarm using one master node and two worker nodes</em></li></ul><h3>Docker Swarm</h3><p><a href="https://docs.docker.com/engine/swarm/">Docker Swarm</a> is a container orchestration tool provided by Docker, Inc. It allows you to manage a cluster of Docker hosts as a single virtual system. Here’s a quick overview of Docker Swarm’s benefits:</p><ol><li><strong>Container Orchestration</strong>: Docker Swarm enables you to deploy and manage a cluster of Docker containers across multiple hosts. It automates the deployment, scaling, and management of containerized applications.</li><li><strong>High Availability</strong>: Docker Swarm ensures high availability of your applications by distributing container replicas across multiple nodes in the cluster. If any node fails, Swarm automatically reschedules containers on healthy nodes, minimizing downtime.</li><li><strong>Scalability:</strong> With Docker Swarm, you can quickly scale your applications by adding or removing worker nodes to the cluster. This allows you to accommodate changes in workload demand without manual intervention.</li><li><strong>Load Balancing</strong>: Swarm includes built-in load balancing functionality that distributes incoming traffic among containers running the same service. This improves the performance and availability of your applications by evenly distributing the workload.</li><li><strong>Self-Healing:</strong> Docker Swarm automatically detects and replaces failed containers. It continuously monitors the health of containers and restarts them on healthy nodes if necessary, ensuring the overall reliability of your applications.</li><li><strong>Simple Setup and Management: </strong>Compared to other container orchestration tools, setting up a Docker Swarm cluster is relatively straightforward. It leverages Docker’s familiar command-line interface and APIs, making it easy for users familiar with Docker to get started.</li><li><strong>Integrated with Docker: </strong>Since Docker Swarm is part of the Docker ecosystem, it seamlessly integrates with other Docker tools and services for defining multi-container applications and Docker Hub for hosting and sharing container images.</li><li><strong>Security:</strong> Docker Swarm provides built-in security features, such as mutual TLS authentication between nodes and encryption of control plane traffic. These help ensure the confidentiality and integrity of communications within the cluster.</li></ol><h3>Solution</h3><p>We’ll need three EC2 instances to work with, so I’ve already got those running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdNWSQzzhWWbfHcCs6yd-Q.png" /></figure><p><strong>Step 1: Install Docker on all hosts</strong><br>Start by connecting to each AWS EC2 Ubuntu 20.04 instance using SSH. Then, run the following commands to make sure all packages are up to date and that Docker is installed:</p><pre>sudo apt update<br>sudo docker version</pre><p><strong>Step 2: Verify Docker installation<br></strong>After installing Docker, check its status to confirm it is active:</p><pre>sudo systemctl status docker</pre><p><strong>Step 3: Change hostnames</strong><br>Identify the master node and worker nodes. I used the following hostnames:<br> — Master node: swarm-master<br> — Worker nodes: swarm-worker-1 and swarm-worker-2</p><p>Use the following commands to change your hostname:</p><pre>sudo hostnamectl set-hostname &lt;host_name&gt;<br>sudo reboot</pre><p>Log back into your instance, and you should see the new hostname.</p><p><strong>Steps 4 and 5: Validate security groups and add SSH keys:</strong><br>You can verify security groups in the AWS Management Console by navigating to each instance and looking at the attached security group. We can confirm our ssh keys using the following commands:</p><pre>cd ~/.ssh<br>cat authorized_keys</pre><p>You should see the key pair listed in your output.</p><p><strong>Step 6: Run the necessary containers</strong></p><p>To confirm we have the necessary containers uploaded to our instances, run the following command:</p><pre>sudo docker container ls</pre><p><strong>Step 7: Initialize Docker Swarm on the master node:</strong><br>SSH into the master node and run the following command to initialize Docker Swarm:</p><pre>sudo docker swarm init --advertise-addr &lt;master-node-ip&gt;</pre><p>This command will output a token that can be used to join worker nodes to the Swarm.</p><p><strong>Step 8: Join worker nodes to the Swarm</strong><br>SSH into each worker node and run the following command:</p><pre>sudo docker swarm join - token &lt;token&gt; &lt;master-node-ip&gt;:2377</pre><p>Fortunately, this command, minus sudo, is provided after initializing the Docker Swarm on the master node. After running this command on both worker nodes, they should join the Docker Swarm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nvZ9lRpeIVQOgyvB-Fp90w.png" /></figure><p>That’s it! We’ve set up Docker Swarm with one master node and two worker nodes for the company’s global shipping application. These containers will be orchestrated across the Swarm, ensuring high availability and fault tolerance.</p><p>If you worked along with my guide, please let me know how it went.</p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*V2DL-CJWX4UIOgUG.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d7adf32580d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Extraction: Dictionaries in Python with AWS Cloud9]]></title>
            <link>https://blog.devgenius.io/data-extraction-dictionaries-in-python-with-aws-cloud9-b4d9b99d6dbd?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4d9b99d6dbd</guid>
            <category><![CDATA[cloud9]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Tue, 19 Mar 2024 13:35:03 GMT</pubDate>
            <atom:updated>2024-03-21T18:15:49.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STgIv7GZeCBZ2uKNBhnshw.png" /></figure><h3>Scenario</h3><p><em>Your company needs to learn about the files located on various machines. You have been asked to build a script that extracts information such as the name and size of the files in the current working directory and stores it in a list of dictionaries.</em></p><p><em>Objective: Create a script that generates a list of dictionaries about files in the working directory. Print the list and push your code to GitHub.</em></p><h3>AWS Cloud9 and Python Dictionaries</h3><p>AWS Cloud9 is an integrated development environment (IDE) provided by Amazon Web Services (AWS) that allows developers to write, run, and debug code from within a web browser. It offers a cloud-based environment for software development, enabling collaboration and easy access to development resources from anywhere with an internet connection.</p><p>Some key features of AWS Cloud9:</p><ul><li><strong>Code Editing</strong>: Cloud9 provides a feature-rich code editor with syntax highlighting, code completion, and other productivity-enhancing tools. It supports various programming languages, including Python, JavaScript, Java, PHP, and more.</li><li><strong>Terminal Access</strong>: Cloud9 includes a built-in terminal emulator that allows developers to run commands and scripts directly within the IDE, eliminating the need for external terminal applications.</li><li><strong>Collaboration Tools</strong>: Cloud9 enables real-time collaboration, allowing multiple developers to work on the same codebase simultaneously. It supports features such as shared editing, chat, and screen sharing.</li><li><strong>Integration with AWS Services</strong>: As an AWS service, Cloud9 seamlessly integrates with other AWS services, such as AWS Lambda, AWS CodeCommit, and AWS CodePipeline, enabling developers to build, test, and deploy applications directly from the IDE.</li><li><strong>Customizable Environments</strong>: Cloud9 allows developers to create custom development environments tailored to their specific needs, including selecting the programming language, runtime, and dependencies.</li><li><strong>Security and Access Control</strong>: AWS Cloud9 provides security features such as encryption of data in transit and at rest and integration with AWS Identity and Access Management (IAM) for managing user permissions.</li></ul><p>AWS Cloud9 streamlines the development process by providing a flexible and collaborative environment for writing, testing, and deploying code, all within the AWS ecosystem.</p><p>In Python, <a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries">a dictionary</a> is a built-in data structure that stores data in key-value pairs. Each key in a dictionary must be unique and unchangeable, such as strings, numbers, or tuples. The values associated with these keys can be of any data type and can be changed. Dictionaries are unordered collections, meaning that the order in which the items are stored does not matter.</p><p>Here’s an example of a dictionary in Python from python.org’s site:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*lJUQgwQtm2t9uORTb4mUqQ.png" /><figcaption>example dictionary from <a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries">https://docs.python.org/3/tutorial/datastructures.html#dictionaries</a></figcaption></figure><h4>Step 1: Log in to AWS Cloud9 Environment</h4><p>For this project, we will work in <a href="https://aws.amazon.com/pm/cloud9/?gclid=CjwKCAjw17qvBhBrEiwA1rU9w1bXN-eOpKLsH1rMdUvJ7fzu_N2iR-mPvzWRJuie5tSZkYzJkOCDQxoCYPkQAvD_BwE&amp;trk=eb97eaaf-ab47-4fa1-af41-65550f25b5e8&amp;sc_channel=ps&amp;ef_id=CjwKCAjw17qvBhBrEiwA1rU9w1bXN-eOpKLsH1rMdUvJ7fzu_N2iR-mPvzWRJuie5tSZkYzJkOCDQxoCYPkQAvD_BwE:G:s&amp;s_kwcid=AL!4422!3!651212652672!e!!g!!cloud9%20amazon!1442694377!56026461773">AWS Cloud9</a>. I previously created an environment in AWS Cloud9 for practicing with Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*IaQLjV9QyZRmb0ZwO6MIOw.png" /></figure><h4>Step 2: Create the Python File for Our Script</h4><p>In the AWS Cloud9 environment, click <strong>File</strong>, <strong>New From Template,</strong> and then <strong>Python File</strong> to get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*qYk7sNcs5tFr8jOqXWcsAQ.png" /></figure><p>Here’s where we will create our script. Using the os module, you can create a Python script to generate a list of dictionaries containing information about files in the working directory.</p><h3>Step 3: Create Script</h3><p>Here’s the code I created:</p><pre>import os<br><br>def get_files_info(directory):<br>    files_info = []<br>    # Get the list of files in the directory<br>    files = os.listdir(directory)<br>    for file_name in files:<br>        file_path = os.path.join(directory, file_name)<br>        # Checks if it&#39;s a file (not a directory)<br>        if os.path.isfile(file_path):<br>            # Get file size<br>            size = os.path.getsize(file_path)<br>            # Create a dictionary with file information<br>            file_info = {<br>                &quot;name&quot;: file_name,<br>                &quot;size&quot;: size<br>            }<br>            # Add the dictionary to the list<br>            files_info.append(file_info)<br>    return files_info<br><br>if __name__ == &quot;__main__&quot;:<br>    current_directory = os.getcwd()  # Get the current working directory<br>    files_info = get_files_info(current_directory)<br>    print(&quot;List of files in the current directory:&quot;)<br>    for file_info in files_info:<br>        print(file_info)</pre><h4><strong>Notes about this script</strong></h4><p>This script will retrieve information about all the files in a specified directory. Using the os module lets us interact with the operating system. The script will get a list of all files in a directory, check if each item is a file (not a directory), get the size of each file, and store the file name and size in a dictionary. This dictionary is then added to a list. The script finally prints out the list of dictionaries containing information about a file in the directory.</p><ul><li>The function get_files_info(directory)takes a directory path as an argument and returns a list of dictionaries. Each dictionary contains the name and size of a file in the directory.</li><li>This script examines files in the working directory (os.listdir()), checks if each item is a file (os.path.isfile()), and then gathers information about each file using os_stat().</li><li>It creates a dictionary for each file containing the filename, size, and last modified timestamp, and adds it to the list files_info.</li><li>In the if __name__==&quot;__main__&quot;: block, the script gets the current working directory using os.getcwd() and then calls the get_files_info() function to get the file information. Finally, it prints out each dictionary containing file information.</li></ul><h3>Step 4: Run Script</h3><p>Here’s the output from running my script in my AWS Cloud9 environment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1IwetBJDY9sTisL8F7WKQ.png" /></figure><p>Because my EC2 instances are virtually empty, I’ve run the script on my personal PC to show how this output would look when more than one file is returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*LHL0JBa2GQlOhgzX5GQ4ig.png" /></figure><h3>Step 5: Push to GitHub</h3><p>I’ve already connected my GitHub account, so I only have a few clicks to push this to my account.</p><ul><li>Click the <strong><em>main branch</em></strong> at the bottom left corner.</li><li>Click <strong><em>Create a new branch</em> </strong>and name it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*sYS9S_axLgSwM_WR0a3lYQ.png" /></figure><ul><li>Click the <strong><em>cloud icon with the up arrow</em></strong> to push the new branch to the GitHub repository.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*AKMzcUx6cw_HU7NMQQGCKQ.jpeg" /></figure><ul><li>You will see a new branch added to your GitHub repository under the Main or branches on your GitHub account, depending on where you placed this branch.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*Lo2vExuXi0cWtze8PMjwmA.png" /></figure><ul><li>Click the Git icon on the menu to the left and then the plus icon under <strong><em>Changes to Stage</em></strong> to GitHub. You’ll then add a commit message in the box and <strong><em>press CTRL + Enter</em></strong>.</li><li>To push your files to the GitHub repo, click the <strong><em>up arrow </em></strong>icon with the number of new commits at the bottom left next to your new branch name.</li><li>Navigate to your <strong><em>GitHub </em></strong>repo and click <strong><em>Compare &amp; pull request</em></strong> .</li><li>Click <strong><em>Create pull request</em></strong>.</li><li>Check <strong><em>Merge</em></strong> <strong><em>without waiting for requirements to be met</em></strong>.</li><li>Click <strong><em>Merge pull request</em></strong>.</li><li>Click <strong><em>Confirm merge</em></strong>.</li><li><strong><em>Delete the branch</em></strong>.</li></ul><p>That’s it! You’ve successfully pushed your code to GitHub. merged and deleted the branch. Bravo!!</p><p>Here you can view the repository on my GitHub:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*6PryMXG_XKrgoJisfc8cWA.png" /><figcaption><a href="https://github.com/racostanzo/black_march_2024_python/blob/dictionary_project/dictionaries.py">https://github.com/racostanzo/black_march_2024_python/blob/dictionary_project/dictionaries.py</a></figcaption></figure><h3>Roadblocks</h3><p>I relied heavily on <a href="https://www.udemy.com/course/python-pcep/?couponCode=LETSLEARNNOWPP">this Python course</a> from Udemy. I had also previously taken <a href="https://www.coursera.org/specializations/python">this course</a> on Coursera and looked through those notes. It took some trial and error to get my script to run, and I spent several hours tweaking it. There’s always room for improvement, as well as other ways this script could have been written.</p><p>I’m a visual learner, and these YouTube videos are great free resources as well:</p><ul><li><a href="https://www.youtube.com/watch?v=MZZSMaEAC2g">Python dictionaries are easy</a></li><li><a href="https://www.youtube.com/watch?v=daefaLgNkw0">Python Tutorial for Beginners 5: Dictionaries — Working with Key-Value Pairs</a></li><li><a href="https://www.youtube.com/watch?v=2IsF7DEtVjg">Dictionary in Python</a></li></ul><p>If you worked along with my guide, please let me know how it went.</p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*jf65QOpMQnaaRcYv.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4d9b99d6dbd" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/data-extraction-dictionaries-in-python-with-aws-cloud9-b4d9b99d6dbd">Data Extraction: Dictionaries in Python with AWS Cloud9</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IAM Roles with Dynamo DB and EC2]]></title>
            <link>https://medium.com/@costanzo.rebecca/iam-roles-with-dynamo-db-and-ec2-6bc7fec4c5ce?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bc7fec4c5ce</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[iam-roles]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Sat, 02 Mar 2024 04:33:50 GMT</pubDate>
            <atom:updated>2024-03-30T19:29:03.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KPZ3FKUdNQlWOZJm3nq8ug.png" /></figure><h3>Objective</h3><ol><li><em>Create a DynamoDB table with the ten latest Movie releases, including the title, genre, release date, and rating.</em></li><li><em>Create a t2.micro Ec2 instance.</em></li><li><em>Using an IAM role and the principle of least privilege, grant the EC2 instance read access to DynamoDB.</em></li><li><em>Use the AWS CLI in the EC2 instance to scan the DynamoDB table.</em></li><li><em>Use the AWS CLI in the EC2 instance to validate you cannot write an item to the DynamoDB table.</em></li></ol><h3><strong>Solution</strong></h3><h4><strong>Step 1: Create the DynamoDB table</strong></h4><p>Navigate to the DynamoDB dashboard in your AWS console. Select <strong>Tables</strong> from the left side panel menu. Click <strong>Create table</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RtjDvp-6Bv5yFZSbYcUmIw.png" /></figure><p>Give your table a <em>name</em> and a <em>partition key</em>. The partition key will be used to retrieve items from the table. <em>Sort keys</em> are optional, and I chose not to use one in this project. I also decided to use the default table settings. Add any relevant tags and click <strong>Create table</strong>.</p><p>Next, we need to add data to our table. Click <strong>Explore items</strong> under the <strong>Actions</strong> drop-down menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAZWbijwfKyG8BajjfYLsA.png" /></figure><p>Click <strong>Create item</strong> to add data to our table. You can manually add information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74no5ybZ_TmsBwv859Yxbg.png" /></figure><p>Or use JSON, which I think is faster, thanks to copy/paste.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLqcTtSCYlIaiyqBygl8bA.png" /></figure><p>Once you’ve entered all the data, you should see something like the example below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPZJKg895NeNQQSoxptuDA.png" /></figure><h4><strong>Step 2: Create an EC2 Instance and an IAM Role</strong></h4><p>Navigate to the EC2 Dashboard and create a t2.micro instance. I used AWS Linux as my OS and a previously created key pair and security group. Step-by-step instructions can be found <a href="https://medium.com/@costanzo.rebecca/secure-remote-administration-and-troubleshooting-of-ec2-instances-e5afa2bda227">here</a>, in a previous project, if needed.</p><p>Next, navigate to the Identity and Access Management (IAM) dashboard. Select <strong>Roles</strong> from the left side panel menu. Click <strong>Create role</strong>.</p><p>Choose <em>AWS service</em> under <strong>Trusted entity type</strong> and <em>EC2</em> under <strong>Use case</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zsXAafGbTUS7fcr61sRmQ.png" /></figure><p>On the next page, under <strong>Permissions policies, </strong>search for <em>AmazonDynamoDBReadOnlyAccess</em>. Select this policy and click <strong>Next</strong>. On this page, you’ll add a name to your role and click <strong>Create role</strong>.</p><h4>Step 4: Attach IAM Role to EC2 Instance</h4><p>Navigate back to your EC2 instances and select the instance we created earlier. Click on the <strong>Actions</strong> drop-down menu, then <strong>Security</strong>, and then <strong>Modify IAM role</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dM7uTSvi1kBOUfZ4Biy-cA.png" /></figure><p>Choose the IAM role we just created and click Update IAM role.</p><h4><strong>Step 5: Scan the DynamoDB Table using AWS CLI</strong></h4><p>SSH into your EC2 instance by copying the command from the <strong>Connect to instance</strong> tab and entering it into your CLI.</p><p>Once connected, use the following command to scan our table:</p><pre>aws dynamodb scan --table-name &lt;table_name&gt; --region &lt;region_name&gt;</pre><p>You should see the JSON code of your table as the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EO-AbfDMo6dVWeiN1UpxbQ.png" /></figure><p>Next, attempt to modify the table with the command.</p><pre>aws dynamodb put-item \<br>--table-name &lt;table_name&gt; \<br>--item &#39;{&quot;&lt;partition_key&gt;&quot;: {&quot;S&quot;: &quot;&lt;value&gt;&quot;}, \<br>&quot;&lt;sort_key&gt;&quot;: {&quot;S&quot;: &quot;&lt;value&gt;&quot;}}&#39; \<br>--region &lt;region_name&gt;</pre><p>Because we only have read access, you should see an error message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-mX_8w_uUTN6QQ4IEL2qw.png" /></figure><h4>That’s it! Project complete.</h4><p>This was a fun, quick project to complete! I got the opportunity to work with some AWS services I’ve never used before, and once again, the Amazon Web Services <a href="https://docs.aws.amazon.com/index.html">documentation section</a> helped with any questions I had. If you followed my guide, please let me know how it went.</p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pza8FvYXQk0G66OB.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bc7fec4c5ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a Virtual Private Cloud with Auto Scaling Group and Application Load Balancer]]></title>
            <link>https://medium.com/@costanzo.rebecca/setting-up-a-virtual-private-cloud-with-auto-scaling-group-and-application-load-balancer-abd336353144?source=rss-f062ccdae198------2</link>
            <guid isPermaLink="false">https://medium.com/p/abd336353144</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[auto-scaling-groups]]></category>
            <category><![CDATA[application-load-balancer]]></category>
            <dc:creator><![CDATA[Rebecca Costanzo]]></dc:creator>
            <pubDate>Fri, 01 Mar 2024 15:37:02 GMT</pubDate>
            <atom:updated>2024-03-30T19:31:39.667Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZ9Opijz0ajeLOT9ZXhf6w.png" /></figure><p><em>After testing and moving a server over to Ec2, the Level-Up Bank is looking to move its network to the cloud to improve scalability, reliability, and security. The bank decides to use AWS for its cloud services and starts by creating a VPC with a CIDR of 10.10.0.0/16. Next, the bank creates three public subnets with CIDR blocks of 10.10.1.0/24, 10.10.2.0/24, and 10.10.3.0/24. These subnets will be used to host an autoscaling group of t2.micro instances with Apache installed on each instance. The bank creates an autoscaling group with a minimum of 2 instances and a maximum of 5 instances. Each instance has Apache installed and is configured to produce a test page when checking a random IP address. The autoscaling group uses the three public subnets created earlier to ensure that instances are launched in different availability zones for high availability. The bank creates an Application Load Balancer to distribute traffic to the autoscaling group. The Load Balancer is configured to use the web server security group created next. The bank creates a web server security group that allows inbound traffic from HTTP from the Application Load Balancer. This security group ensures that the instances in the autoscaling group can receive traffic from the Load Balancer. Finally, the bank creates a load balancer security group that allows inbound traffic from HTTP from 0.0.0.0/0. This security group ensures that the Load Balancer is accessible from the internet.</em></p><p>Let’s work on creating this setup for our client!</p><h3>Solution</h3><h4>Step 1: Create your VPC</h4><p>Log in to your AWS Console and navigate to your VPC. Click on <strong>Create VPC</strong>. For this project, we will choose to create <em>VPC only</em> under the <strong>VPC settings. </strong>You will need to enter a value for the <strong>Name tag</strong> and input your IPv4 CIDR. Select <em>No IPv6 CIDR block</em> under the <strong>IPv6 CIDR block</strong> section. Add any relevant tags and click <strong>Create VPC</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*Lx9bhF0WC4r3AlMh1MELMg.png" /></figure><h4>Step 2: Create subnets</h4><p>Next, navigate to subnets and click <strong>Create subnet</strong>. We are going to create three public subnets with the following IPv4 CIDRs: 10.10.1.0/24 &amp; 10.10.2.0/24 &amp; 10.10.3.0/24. Give each subnet a name and choose your availability zone. I am going to use us-east-1a, us-east-1b, and us-east-1c. After adding the details for the first subnet, you can click <strong>Add new subnet</strong>. This will allow you to create all three subnets at once, saving you time and effort. Make sure to attach these subnets to the VPC we just created, and then click <strong>Create subnet</strong>.</p><h4>Step 3: Create Internet Gateway</h4><p>Next, we must create an <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html">Internet Gateway</a> to allow communication between the VPC and the Internet. Give your internet gateway a name tag, add any relevant tags, and then click <strong>Create Internet gateway</strong>. Select the gateway you created, and then, under <strong>Actions</strong>, select <strong>Attach to VPC</strong>. There will be a drop-down menu under Availavel VPCs. Choose the VPC we created earlier and then click <strong>Attach internet gateway</strong>. You should see <em>Attached</em> under our Internet gateway State.</p><h4>Step 4: Create Route Table</h4><p>From here, we need to create our <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Route_Tables.html"><strong>route table</strong></a>, which will determine where network traffic from our subnet or gateway is directed. Navigate to Route tables under the VPC dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*2MOkwc0NsMC2nt4ugZjDtw.png" /></figure><p>Name your route table and use the VPC from earlier. Click <strong>Create route table</strong>. Under the <strong>Routes</strong> tab, select <strong>Edit routes</strong>. Add a new route with the destination 0.0.0.0/0. This allows all internet traffic. The target will be <em>Internet Gateway</em>, and then select the internet gateway we created. Click <strong>Save changes</strong>.</p><h4>Steps 5 &amp; 6: Create Auto Scaling Group and an Application Load Balancer</h4><p>Navigate to the EC2 dashboard. Select Auto Scaling Groups under Resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*xX6YsMlAJeV_148-wZJ8Zg.png" /></figure><p>Click <strong>Create a launch template </strong>(opens in a new window) under the <strong>Launch template</strong> section. Name the Launch template and give it a description. Under the <strong>Application and OS Images (Amazon Machine Image)</strong> section, choose Amazon Linux under the <strong>Quick Start</strong> tab. Under the <strong>Instance type</strong>, choose the t2.micro (free tier eligible). Generate a new key pair, and under <strong>Network settings</strong>, leave the subnet as is, but let’s set up a new security group. Name the security group and give a description. Select the VPC we created earlier and then add the security group rule to allow inbound traffic from HTTP from 0.0.0.0/0. Under <strong>Advanced network configuration</strong>, select <strong>Add network interface</strong>, and for the drop-down under <strong>Auto-assign public IP</strong>, click on <em>Enable</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFjBvrg85A_smA-XPtHFhg.png" /></figure><p>Under <strong>Advanced settings</strong>, you’ll see the<strong> user-data</strong> field. We’ll add a script here to allow our EC2 instance to install, update, and run Apache. I used this script in two previous projects, my <a href="https://medium.com/@costanzo.rebecca/creating-a-custom-html-page-on-an-aws-ec2-centos-server-dcc06cc565d6">Linux project</a> and my project <a href="https://medium.com/@costanzo.rebecca/launching-an-ec2-instance-with-apache-creating-an-ami-and-working-in-cli-91dae6c6ccc4">Amazon Machine Image (AMI) project</a>, so I knew it would come in handy for this project as well.</p><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd</pre><p>Scripts entered as user data are run as the root user, so there’s no need for the sudo command here. Also, because the script is not run interactively, we’ll need to include the -y flag on any commands that require user feedback. Click <strong>Create launch template</strong>.</p><p>Navigate back to Auto Scaling groups on the EC2 dashboard. Click <strong>Create Auto Scaling group</strong>. Name your Auto Scaling group. Choose the launch template we just created and click <strong>Next</strong>. Under <strong>Network</strong>, make sure the VPC we created for this project is selected, and select the 3 public subnets we created earlier. Click <strong>Next</strong>.</p><p>Under the <strong>Load balancing</strong> section, select the option to <em>Attach to a new load balancer</em>. For our Load balancer type, we’ll be using <strong>Application Load Balancer</strong>. A name is automatically generated; change it if you so desire, and then choose <em>Internet-facing</em> under <strong>Load balancer scheme</strong>. Under <strong>Listeners and routing</strong>, choose to <em>Create a target group</em>. Click <strong>Next</strong>.</p><p>On the next page, under the <strong>Scaling </strong>section, I am going to set my minimum and maximum desired capacities to 2 and 5, respectively. <strong>Under Automatic scaling</strong>, turn on <em>Target tracking scaling policy. </em>Click <strong>Next</strong>. Review your settings and click <strong>Create Auto Scaling group</strong> when you’re ready.</p><p>Navigate back to the EC2 dashboard, and you should see two instances running! Once you’re up and running, grab the public IPv4 of either instance and test it in your browser. You should see the Apache test page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uwfJdKEnuUhPJ5Rn.png" /></figure><h4>That’s it! Project complete.</h4><p>This project was fun and pretty straightforward. I enjoyed accessing some AWS services I’ve not used before, and once again, the Amazon Web Services <a href="https://docs.aws.amazon.com/index.html">documentation section</a> helped with any questions I had. If you followed along with my guide, please let me know how it went.</p><p>I’m documenting my journey from Teacher to Cloud DevOps Engineer. It’s been an exciting endeavor so far. Thank you for taking the time to stop by. I’d love to connect. <a href="https://www.linkedin.com/in/becca-costanzo/">https://www.linkedin.com/in/becca-costanzo/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_bSfoTZrDdoT1d6q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abd336353144" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>