<?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 Ray Sylverne on Medium]]></title>
        <description><![CDATA[Stories by Ray Sylverne on Medium]]></description>
        <link>https://medium.com/@RaySylverne?source=rss-322c6aa4d97c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Elxss-nJ7KvvaYRzW9I6Fg.png</url>
            <title>Stories by Ray Sylverne on Medium</title>
            <link>https://medium.com/@RaySylverne?source=rss-322c6aa4d97c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:18:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@RaySylverne/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[Use Terraform To Deploy Jenkins Server On EC2]]></title>
            <link>https://aws.plainenglish.io/use-terraform-to-deploy-jenkins-server-on-ec2-4d173ba7eb54?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d173ba7eb54</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 16:42:06 GMT</pubDate>
            <atom:updated>2023-03-04T03:37:23.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W7J9NFPNGhXm2IF99lqwwg.png" /></figure><h3>Objective:</h3><p>To facilitate the team’s use of Jenkins as their preferred CI/CD tool for DevOps projects, it is necessary to create a Jenkins server using Terraform. This will allow the team to utilize the tool in multiple environments and better track any changes made to the environment. The document provides a comprehensive summary of the benefits of Jenkins and Terraform to ensure their successful integration into the team’s workflow.</p><h4><strong>What is Jenkins at a high level?</strong></h4><p>Jenkins is an open-source automation server for continuous integration and delivery (CI/CD) of software projects. The best way to explain how something works is to understand what problems it solves.</p><h4>Here a 5 common business challenges that Jenkins addresses:</h4><ol><li><strong>Automating the software development process:</strong> Jenkins can automate tasks such as building, testing, and deploying software, reducing the time and effort required from developers and ensuring consistent quality and reliability.</li><li><strong>Improved collaboration: </strong>Jenkins provides a shared platform for developers to work together, enabling them to collaborate more effectively and avoid conflicts.</li><li><strong>More efficient release management:</strong> By automating the release process, Jenkins can help businesses to deploy software changes more quickly and efficiently, with less risk of errors or downtime.</li><li><strong>Increased visibility and transparency:</strong> Jenkins provides visibility into the entire software development process, making it easier for businesses to manage their projects and track progress.</li><li><strong>Scalability and flexibility: </strong>Jenkins can automate the development process for any software, from small projects to large-scale enterprise applications, making it an ideal solution for businesses of all sizes.</li></ol><h4><strong>What is Terraform at a high level?</strong></h4><p>Terraform helps businesses manage their infrastructure more efficiently and effectively, which can lead to cost savings, improved reliability, and faster time-to-market for new applications and services.</p><h4><strong>Here a 5 common business challenges that Terraform addresses:</strong></h4><ul><li><strong>Infrastructure automation: </strong>Terraform enables businesses to automate the provisioning and management of infrastructure resources, saving time and reducing errors.</li><li><strong>Cross-platform support:</strong> Terraform supports multiple cloud platforms, including AWS, Azure, and Google Cloud, which makes it easier for businesses to manage their infrastructure across different environments.</li><li><strong>Consistent infrastructure:</strong> Terraform helps businesses maintain consistent infrastructure by defining infrastructure as code, which makes it easier to manage and update.</li><li><strong>Collaboration: </strong>Terraform enables multiple teams to collaborate on infrastructure management by providing a version-controlled, modular approach to infrastructure as code.</li><li><strong>Cost optimization: </strong>Terraform helps businesses optimize their infrastructure costs by providing visibility into resource usage and enabling them to scale resources up or down as needed.</li></ul><h4>Pre-Requisites To Follow Along</h4><ol><li>General Knowledge of AWS &amp; Terraform is required</li><li>AWS Account with Admin Level Access</li><li>Terraform Installed</li><li>An I<strong>ntegrated Development Environment</strong> (IDE)<br>I’m using VS Code</li><li>AWS CLI Installed &amp; Configured with Programmatic Access</li><li>Here is the link to my <a href="https://github.com/raysylverne/terraform_jenkins_aws.git"><strong>GitHub Repo</strong></a><strong> </strong>for this deployment</li><li>Links to Documentation at the end of the article!</li></ol><h3>Step1: Set Up Your Workspace</h3><p>When you are deploying a task using Terraform, the first thing you need to do is create a new directory for your Terraform code. You can do this from your terminal <strong>mkdir &lt;directory_name&gt; . </strong>However, you’ll notice that I mainly work out of VS Code during this project. I like VS Code because it is a lightweight, fast, and highly customizable code editor. It has many useful features, such as built-in debugging, Git integration, and support for various programming languages and extensions. Additionally, it is free and open source, making it accessible to developers of all backgrounds and skill levels. After creating your directory you’ll want to create the four .tf files for our architecture.</p><pre><br>main.tf <br>variables.tf<br>outputs.tf<br>providers.tf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*NHlRw8MQU9IaxikZpFYesg.png" /></figure><h3>Step 2: Define AWS Resources In main.tf</h3><p>Here, the main.tf file is provisioning the following resources:</p><ul><li>AWS VPC</li><li>AWS Subnet</li><li>AWS Internet Gateway</li><li>AWS Default Route</li><li>IAM Instance Profile with S3 access</li><li>AWS Security Group</li><li>AWS S3 bucket</li><li>AWS EC2 instance with a user data script installing Jenkins</li></ul><p>The VPC is defined using the aws_vpc resource, which takes the CIDR block and name tag as input. The Internet Gateway is defined using the aws_internet_gateway resource, which takes in the VPC ID and name tag as input. The Route Table is defined using the aws_route_table resource, which takes in the VPC ID and Internet Gateway ID as input.</p><p>The datablock named myipaddrretrieves the external IP address of a machine by running a Bash command that uses the curl utility to fetch data from the <a href="http://ipinfo.io/">ipinfo.io</a> website. The output of the command is then assigned to a property called “program” within the data block.</p><p>The Subnet is defined using the aws_subnet resource, which takes in the VPC ID, CIDR block, availability zone, and name tag as input. The Security Group is defined using the aws_security_group resource, which takes in the VPC ID, name prefix, and ingress/egress rules as input.</p><p>The IAM Role is defined using the aws_iam_role resource, which takes in the name and assume role policy as input. The IAM Policy is defined using the aws_iam_policy resource, which takes in the name and policy document as input. The IAM Role Policy Attachment is defined using the aws_iam_role_policy_attachment resource, which takes in the policy ARN and role name as input. The IAM Instance Profile is defined using the aws_iam_instance_profile resource, which takes in the name and role name as input.</p><p>The EC2 Instance is defined using the aws_instance resource, which takes in the AMI, instance type, key name, VPC security group IDs, Subnet ID, IAM instance profile name, user data script, and name tag as input.</p><p>The S3 bucket is defined using the aws-_s3_bucket resource which takes in the bucket as input. The S3 bucket ACL is defined using the aws_s3_bucket_acl resource which takes in the bucket and acl type as input.</p><pre># VPC<br>resource &quot;aws_vpc&quot; &quot;vpc&quot; {<br>  cidr_block = var.vpc_cidr<br><br>  tags = {<br>    Name = var.vpc_tag<br>  }<br>}<br><br># Subnet<br>resource &quot;aws_subnet&quot; &quot;subnet&quot; {<br>  vpc_id            = aws_vpc.vpc.id<br>  cidr_block        = var.subnet_cidr<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = var.subnet_tag<br>  }<br>}<br><br># Internet Gateway<br>resource &quot;aws_internet_gateway&quot; &quot;internet_gateway&quot; {<br>  vpc_id = aws_vpc.vpc.id<br><br>  tags = {<br>    Name = var.internet_gateway_tag<br>  }<br>}<br><br># Route Table<br>resource &quot;aws_default_route_table&quot; &quot;default_route&quot; {<br>  default_route_table_id = aws_vpc.vpc.default_route_table_id<br><br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.internet_gateway.id<br>  }<br>}<br><br># Public IP and add to Security Group<br><br>data &quot;external&quot; &quot;myipaddr&quot; {<br>  program = [&quot;bash&quot;, &quot;-c&quot;, &quot;curl -s &#39;https://ipinfo.io/json&#39;&quot;]<br>}<br><br># Security Group<br>resource &quot;aws_security_group&quot; &quot;jenkins_security_group&quot; {<br>  name_prefix = var.security_group_name<br>  description = &quot;Jenkins EC2 instance&quot;<br>  vpc_id      = aws_vpc.vpc.id<br><br>  ingress {<br>    description = &quot;Allow SSH from my Public IP&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;Allows Access to the Jenkins Server&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;Allows Access to the Jenkins Server&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>  tags = {<br>    Name = &quot;Jenkins_Security_Group&quot;<br>  }<br>}<br><br># IAM Role<br>resource &quot;aws_iam_role&quot; &quot;ec2_role&quot; {<br>  name = var.ec2_role_name<br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Action = &quot;sts:AssumeRole&quot;<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Service = &quot;ec2.amazonaws.com&quot;<br>        }<br>      }<br>    ]<br>  })<br>}<br><br># IAM Policy<br>resource &quot;aws_iam_policy&quot; &quot;ec2_role_policy&quot; {<br>  name = var.ec2_role_policy_name<br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Action = [<br>          &quot;s3:Get*&quot;,<br>          &quot;s3:List*&quot;<br>        ]<br>        Effect   = &quot;Allow&quot;<br>        Resource = &quot;*&quot;<br>      }<br>    ]<br>  })<br>}<br><br># IAM Role Policy Attachment<br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;ec2_role_policy_attachment&quot; {<br>  policy_arn = aws_iam_policy.ec2_role_policy.arn<br>  role       = aws_iam_role.ec2_role.name<br>}<br><br># IAM Instance Profile<br>resource &quot;aws_iam_instance_profile&quot; &quot;ec2_instance_profile&quot; {<br>  name = var.ec2_instance_profile_name<br>  role = aws_iam_role.ec2_role.name<br>}<br><br># EC2 Instance<br>resource &quot;aws_instance&quot; &quot;ec2_instance&quot; {<br>  ami                    = var.ami<br>  instance_type          = var.instance_type<br>  key_name               = var.ssh_key_name<br>  security_groups        = [aws_security_group.jenkins_security_group.id]<br>  subnet_id              = aws_subnet.subnet.id<br>  iam_instance_profile   = aws_iam_instance_profile.ec2_instance_profile.name<br>  user_data              = var.ec2_user_data<br>  tags = {<br>    Name = var.ec2_tag<br>  }<br>}<br><br># S3 Bucket<br>resource &quot;aws_s3_bucket&quot; &quot;s3&quot; {<br>  bucket = var.bucket_name<br><br>  tags = {<br>    Name = var.bucket_name<br>  }<br>}<br><br>resource &quot;aws_s3_bucket_acl&quot; &quot;jenkinsbucketacl&quot; {<br>  bucket = var.bucket_name<br>  acl    = &quot;private&quot;<br>}</pre><h3>Step 3: Define providers.tf</h3><p>In Terraform, providers are plugins that define the resources that Terraform can manage. The provider block contains authentication information that allows Terraform to interact with the AWS APIs to create, update, and delete resources.</p><p>In this code block, the terraform block is used to specify the required provider for the Terraform code. The required_providers block is used to specify the provider name and its source, which is the location of the provider’s plugin. The aws provider is specified with the hashicorp/aws source and version ~&gt; 4.55.0.</p><p>By specifying the aws provider in the terraform block, Terraform knows to load the hashicorp/aws plugin and use it to manage the AWS resources defined in the Terraform configuration.</p><pre># Terraform Providers<br><br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.55.0&quot;<br>    }<br>  }<br><br>  required_version = &quot;&gt;= 1.3.0&quot;<br>}<br><br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><h3>Step 4: Define variables.tf</h3><p>The variables.tf file defines the variables used in the Terraform code, such as the CIDR block for the VPC and subnet, the AMI ID for the EC2 instance, and the name of the S3 bucket. These variables can be set to different values in different environments, making the Terraform code more flexible and reusable.</p><p>This section of the Terraform code sets the necessary variables for the resources being created.</p><ul><li><strong>vpc_cidr</strong>: This sets the CIDR block for the VPC resource.</li><li><strong>vpc_tag</strong>: This sets the name tag for the VPC resource.</li><li><strong>subnet_cidr</strong>: This sets the CIDR block for the subnet resource.</li><li><strong>subnet_tag</strong>: This sets the name tag for the subnet resource.</li><li><strong>internet_gateway_tag</strong>: This sets the name tag for the Internet Gateway resource.</li><li><strong>ec2_role_name</strong>: This sets the name for the IAM Role resource.</li><li><strong>ec2_instance_profile_name</strong>: This sets the name for the IAM Instance Profile resource.</li><li><strong>ec2_role_policy_name</strong>: This sets the name for the IAM Policy resource.</li><li><strong>ec2-trust-policy</strong>: This sets the filename for the assume role policy document.</li><li><strong>ec2-s3-permissions</strong>: This sets the filename for the S3 permissions policy document.</li><li><strong>bucket_name</strong>: This sets the name for the S3 bucket resource.</li><li><strong>security_group_name</strong>: This sets the name prefix for the Security Group resource.</li><li><strong>ami</strong>: This sets the AMI ID for the EC2 instance resource.</li><li><strong>instance_type</strong>: This sets the instance type for the EC2 instance resource.</li><li><strong>ssh_key_name</strong>: This sets the name of the SSH key for the EC2 instance resource.</li><li><strong>ec2_user_data</strong>: This sets the user data script for the EC2 instance resource.</li><li><strong>ec2_tag</strong>: This sets the name tag for the EC2 instance resource.</li></ul><pre># This file references the resources and sets the necessary variables.<br>variable &quot;vpc_cidr&quot; {<br>  description = &quot;CIDR block for the VPC&quot;<br>  default = &quot;10.0.0.0/16&quot;<br>}<br><br>variable &quot;vpc_tag&quot; {<br>  description = &quot;Tag for the VPC&quot;<br>  default = &quot;my-vpc&quot;<br>}<br><br>variable &quot;subnet_cidr&quot; {<br>  description = &quot;CIDR block for the subnet&quot;<br>  default = &quot;10.0.0.0/24&quot;<br>}<br><br>variable &quot;subnet_tag&quot; {<br>  description = &quot;Tag for the subnet&quot;<br>  default = &quot;my-subnet&quot;<br>}<br><br>variable &quot;internet_gateway_tag&quot; {<br>  description = &quot;Tag for the Internet Gateway&quot;<br>  default = &quot;my-igw&quot;<br>}<br><br>variable &quot;ec2_role_name&quot; {<br>  description = &quot;Name of the EC2 instance role&quot;<br>  default = &quot;ec2_role&quot;<br>}<br><br>variable &quot;ec2_instance_profile_name&quot; {<br>  description = &quot;Name of the EC2 instance profile&quot;<br>  default = &quot;ec2_instance_profile&quot;<br>}<br><br>variable &quot;ec2_role_policy_name&quot; {<br>  description = &quot;Name of the policy attached to the EC2 instance role&quot;<br>  default = &quot;ec2_role_policy&quot;<br>}<br><br>variable &quot;ec2-trust-policy&quot; {<br>  description = &quot;Name of the JSON file containing the trust policy for the EC2 instance role&quot;<br>  default = &quot;trust-policy.json&quot;<br>}<br><br>variable &quot;ec2-s3-permissions&quot; {<br>  description = &quot;Name of the JSON file containing the S3 bucket permissions for the EC2 instance role&quot;<br>  default = &quot;s3-permissions.json&quot;<br>}<br><br>variable &quot;bucket_name&quot; {<br>  description = &quot;Name of the S3 bucket&quot;<br>  default = &quot;rayblackteam&quot;<br>}<br><br>variable &quot;security_group_name&quot; {<br>  description = &quot;Name of the security group&quot;<br>  default = &quot;my-security-group&quot;<br>}<br><br>variable &quot;ami&quot; {<br>  description = &quot;AMI ID for the EC2 instance&quot;<br>  default = &quot;ami-0dfcb1ef8550277af&quot;<br>}<br><br>variable &quot;instance_type&quot; {<br>  description = &quot;Type of the EC2 instance&quot;<br>  default = &quot;t2.micro&quot;<br>}<br><br>variable &quot;ssh_key_name&quot; {<br>  description = &quot;Name of the SSH key pair&quot;<br>  default = &quot;cli-dev-proj&quot;<br>}<br><br>variable &quot;ec2_user_data&quot; {<br>  description = &quot;User data script for EC2 instances&quot;<br>  type        = string<br>  default     = &lt;&lt;EOF<br>#!/bin/bash<br># Install Jenkins and Java<br>sudo wget -O /etc/yum.repos.d/jenkins.repo \\<br>    &lt;https://pkg.jenkins.io/redhat-stable/jenkins.repo&gt;<br>sudo rpm --import &lt;https://pkg.jenkins.io/redhat-stable/jenkins.io.key&gt;<br>sudo yum -y upgrade<br># Add required dependencies for the jenkins package<br>sudo amazon-linux-extras install -y java-openjdk11<br>sudo yum install -y jenkins<br>sudo systemctl daemon-reload<br><br># Start Jenkins<br>sudo systemctl enable jenkins<br>sudo systemctl start jenkins<br><br># Firewall Rules<br>if [[ $(firewall-cmd --state) = &#39;running&#39; ]]; then<br>    YOURPORT=8080<br>    PERM=&quot;--permanent&quot;<br>    SERV=&quot;$PERM --service=jenkins&quot;<br><br>    firewall-cmd $PERM --new-service=jenkins<br>    firewall-cmd $SERV --set-short=&quot;Jenkins ports&quot;<br>    firewall-cmd $SERV --set-description=&quot;Jenkins port exceptions&quot;<br>    firewall-cmd $SERV --add-port=$YOURPORT/tcp<br>    firewall-cmd $PERM --add-service=jenkins<br>    firewall-cmd --zone=public --add-service=http --permanent<br>    firewall-cmd --reload<br>fi<br>EOF<br>}<br><br>variable &quot;ec2_tag&quot; {<br>  description = &quot;Tag for the EC2 instance&quot;<br>  default = &quot;jenkins-server&quot;<br>}These variables are used throughout the Terraform configuration file to create the necessary resources for provisioning an EC2 instance that installs Jenkins.</pre><p><strong>Modify the default values for these variables in the variables.tf file to match your requirements.</strong></p><h3>Step 5: Define output.tf</h3><p>This step creates and outputs the bucket domain name, S3 bucket URI, and instance public IP. The <strong>aws_s3_bucket</strong> resource is created in the <strong>main</strong>.<strong>tf</strong> file and takes in the bucket name as input. The <strong>aws_s3_bucket</strong> resource creates an S3 bucket with the specified name.</p><p>The <strong>outputs.tf</strong> file creates an output for each of the desired values. The <strong>bucket_domain_name</strong> output retrieves the domain name of the S3 bucket created by the <strong>aws_s3_bucket</strong> resource. The <strong>s3_bucket_uri</strong> output creates a string that includes the S3 URI and the ID of the S3 bucket created by the <strong>aws_s3_bucket</strong> resource. The <strong>instance_public_ip</strong> output retrieves the public IP address of the EC2 instance created by the <strong>aws_instance</strong> resource.</p><p>These outputs can be referenced in other Terraform files or used for debugging.</p><pre># Creates and outputs the bucket_domain_name, s3_bucket_uri, and instance_public_ip.<br>output &quot;bucket_domain_name&quot; {<br>  description = &quot;FQDN of bucket&quot;<br>  value       = &quot;https://${aws_s3_bucket.s3.bucket_domain_name}&quot;<br>}<br><br>output &quot;s3_bucket_uri&quot; {<br>  description = &quot;S3 bucket URI&quot;<br>  value       = &quot;s3://${aws_s3_bucket.s3.id}&quot;<br>}<br><br>output &quot;instance_public_ip&quot; {<br>  value = aws_instance.ec2_instance.public_ip<br>}</pre><p>After creating these files, run <strong>terraform init</strong>, <strong>terraform plan</strong> ,and <strong>terraform apply</strong>within the directory containing the Terraform files. This will create the resources in your AWS account.</p><h3>Step 6: Ready To Deploy</h3><p><strong>terraform init</strong>is a command used to initialize a working directory containing Terraform configuration files. It is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. This command downloads and installs the modules and providers required for the configuration and sets up the backend configuration if one is specified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*4MO-xKocJSgll3DaAvjwMQ.png" /></figure><p>After initializing our directory I like to run <strong>terrafrom fmt — diff</strong> . This command automatically formats your Terraform code according to best practices and conventions. It can be used to ensure consistency and readability in your codebase. The --diff is can be added to get an output of the changes made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*QxsxR99Pr3Gjd4aguLIiyw.png" /><figcaption><strong>The + &amp;- symbols represent which lines are being modified</strong></figcaption></figure><p><strong>terraform validate</strong> is a command that checks the syntax and validity of your Terraform code. It can be used to catch errors and issues before applying your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*ff-F6GISn3kB8Cy9ym8Crw.png" /><figcaption><strong>It took a lot of trial and error to get to this point</strong></figcaption></figure><p><strong>terraform plan</strong> command shows you what changes will be made to your infrastructure if you apply the current Terraform configuration. It compares the current state of your infrastructure to the desired state described in your Terraform configuration files and displays the changes that Terraform plans to make. This can help you verify that your configuration is correct and that you understand the impact of the changes that you’re about to apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sz9spV2h_O8Rk0aIeNyUYw.png" /><figcaption><strong>The actual output is about the length of this entire article.</strong></figcaption></figure><p><strong>terraform apply</strong> is a command that creates or updates infrastructure resources in accordance with the configuration file. It also generates an execution plan that describes what changes will be made to the infrastructure. When you run <strong>terraform apply</strong>, Terraform reads the configuration file and compares it to the current state of the infrastructure. It then makes the necessary changes to bring the infrastructure into the desired state as defined in the configuration file.</p><p>You should be careful when running <strong>terraform apply</strong> because it can make changes to your infrastructure that can&#39;t be undone. It&#39;s a good idea to review the execution plan before applying changes to ensure you understand what will be changed.</p><p>After running terraform apply, you will be prompted to confirm that you accept the changes Do you want perform these actions? Upon entering, yes, you will immediately see your resources being provisioned.</p><p>Terraform plan and apply appear to do the same thing, but there are some distinct differences. <strong>terraform plan</strong>is used to preview the changes that will be made to your infrastructure before actually applying them with <strong>terraform apply</strong>. This allows you to review and verify the changes that will be made and catch any potential issues or errors before they are applied. It can also be useful for understanding the dependencies between resources and the order in which they will be created or modified. <strong>terraform apply</strong> will make the changes to your infrastructure, so it’s important to use terraform plan first to ensure that you are making the changes you expect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*l8FOZiKdnsvjxNDw_awAfw.png" /></figure><p>You can get more insight into your deployment by running <strong>terraform show</strong>.This command displays the current state of your infrastructure in a human-readable format. It can be used to verify your resources&#39; current state and understand the dependencies and relationships between resources. It&#39;s a lot of information so I won’t post it here, but no need to take my word for it. If you followed along until now, you could run it to see for yourself. Here is the link to my <a href="https://github.com/raysylverne/terraform_jenkins_aws.git"><strong>GitHub Repo</strong></a><strong> </strong>where you can find the source code.</p><p>Another command that I find helpful is <strong>terraform state list</strong> This command displays a list of all resources in the Terraform state file. This command can be useful for troubleshooting and verifying the current state of your infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*tPRe7Ff2WtpVANyyo6XRgQ.png" /></figure><h3>Quality Assurance Check</h3><p><strong>terraform output</strong> is used to display the attributes&#39; values for resources created and managed using Terraform. It can be used to output the IP address, domain name, or other attributes of resources that were created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*n1wz8tFEu-gZJc3b0y0dOA.png" /></figure><p>Next, enter the value returned from the instance_public_ip in your browser with “:8080” appended to the end. If you have reached the Jenkins “Getting Started” page displayed on every new Jenkins installation, you have successfully completed the installation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pbev30bN5qNoiPPWBsTdxw.png" /></figure><h3>Destroy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*TeSiyalUQ1UODtixng0elQ.gif" /></figure><p><strong>terraform destroy</strong> is a Terraform command that destroys all resources created by a Terraform configuration. It cleans up resources and ensures you are not charged for resources you are no longer using. You will again be prompted to confirm that change to your architecture. Upon entering <br><strong>“yes”</strong> all resources will be deleted.</p><h3>Conclusion</h3><p>Thank you for taking the time out of your day to read this article. I hope you were able to get some value from the content. If this content interests you, check out my <a href="https://medium.com/@RaySylverne"><strong>medium profile</strong></a> for more articles on DevOps tools and methodologies. Let’s also connect on <a href="https://www.linkedin.com/in/ray-sylverne/"><strong>LinkedIn</strong></a>, where we can continue the conversation.</p><h3>DOCUMENTATION &amp; REFERENCES</h3><p>Don’t forget to push your code and files to your Git repo.<a href="https://github.com/raysylverne/mongodb_app"><strong><br></strong></a>Here is the link to my <a href="https://github.com/raysylverne/terraform_jenkins_aws.git"><strong>GitHub Repo</strong></a><strong> for this deployment.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*lbYctTqeJJhh163s4DcMSQ.png" /></figure><ul><li><a href="https://developer.hashicorp.com/terraform/language">Overview - Configuration Language | Terraform | HashiCorp Developer</a></li><li><a href="https://developer.hashicorp.com/terraform/cli">Terraform CLI Documentation | Terraform | HashiCorp Developer</a></li><li><a href="https://kodekloud.com/courses/terraform-for-beginners/">Learn Terraform Basics Course | KodeKloud</a></li></ul><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><em> community and follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em> and</em><strong><em> </em></strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Learn how to build awareness and adoption for your startup with </em></strong><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d173ba7eb54" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/use-terraform-to-deploy-jenkins-server-on-ec2-4d173ba7eb54">Use Terraform To Deploy Jenkins Server On EC2</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Front & Backend Application on Kubernetes]]></title>
            <link>https://aws.plainenglish.io/deploy-front-backend-application-on-kubernetes-fa5f46d694c?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa5f46d694c</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Sun, 12 Feb 2023 18:45:20 GMT</pubDate>
            <atom:updated>2023-02-13T01:59:59.568Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3yr6NnIOLjRJa_iOa1R4zQ.png" /></figure><p>You’ve been tasked with deploying an entire end-to-end application using MongoDB and Mongo Express on Kubernetes. While creating this cluster, we’ll explore and analyze, how various Kubernetes components work together to streamline the deployment of applications. All of this needs to be done locally on your machine. I’ve elected to utilize minikube for this purpose. We’ll dive into minikube functions and features as we go through the setup.</p><h4>What are MongoDB and Mongo Express?</h4><p>MongoDB is a platform for general-purpose document databases, and Mongo Express is a web application server framework for Node.js. These can be combined to create a web application that uses MongoDB to store data. You can connect to and query any MongoDB database instance using the MongoDB Node.js driver because Express is a module running on top of Node.js.</p><h4>Pre-Requisites To Follow Along</h4><ul><li>Familiarity with Linux CLI</li><li>DockerHub Account</li><li>Follow the instructions to install <a href="https://minikube.sigs.k8s.io/docs/start/"><strong>minikube</strong></a><strong> </strong>based on your: OS, Architecture, Release type, &amp; Installer type.</li><li>Minikube Resource Requirments:<br><strong> — </strong>2 CPUs or more<br><strong> — </strong>2GB of free memory<br><strong> — </strong>20GB of free disk space<br><strong> — </strong>Internet connection<br><strong> — </strong>Containers or virtual machine managers</li></ul><h3>Sequence of Events:</h3><ol><li>Install the following locally: <strong><br></strong> — Hypervisor <br> — Minikube<br> — kubectl</li><li>Create a Manifest for MongoDB</li><li>Create a Secret Object</li><li>Create an Internal Service for MongoDB</li><li>Create a Manifest for Mongo Express</li><li>Create a ConfigMap for Mongo Express</li><li>Create an External Service for Express</li><li>Test, Debug, and Deploy Your Architecture</li></ol><h3>Let’s Get Started</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*Odo5qw2vLKbQWhQq63G_Lg.gif" /></figure><h3>STEP 1: Local Setup</h3><p>Minikube is an open-source tool that allows you to create a local Kubernetes environment on any Linux, Mac, or Windows system. It gives you the capability to test and experiment with Kubernetes deployments locally. It runs on your machine using some form of a hypervisor. Minikube will create a virtual machine on your laptop and the node will run inside that virtual box. By default, it creates a one-node cluster, but you can create a multi-node cluster with a Minikube environment if desired. I’m on macOS; other operating systems may have different commands and steps. At the end of the article, I have provided links to the documentation where you can find the steps for your OS.</p><p><strong>Install minikube</strong></p><pre>brew install minikube</pre><p><strong>Install kubectl</strong></p><p>Minikube has kubectl as a dependency, so the above command will also install kubectl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*cA_V-mFhIPS73YEWA7RwXg.png" /></figure><p><strong>Install hypervisor</strong></p><pre>brew install hyperkit</pre><p><strong>Create and Start Cluster:</strong></p><p>All you need is Docker (or similarly compatible) container or a Virtual Machine environment, and yo ur K8s cluster is a single command away:</p><pre>minikube start --vm-driver=hyperkit</pre><p>To start the cluster, we must instruct Minikube which hypervisor to use since it must run inside a virtual machine. As a result, we mention the Hyperkit Hypervisor in the start command. I have a similar setup on my M1 MacBook but since there are so many issues with virtualization I ended up using docker as my driver when working on that device. The command to use docker as your driver would be minikube start --driver=docker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*APKmqLPpeOkaBkO1gkhOmg.gif" /></figure><h3>STEP 2: Create a Manifest for MongoDB</h3><p>Before we create our manifest, we’ll head to <a href="https://hub.docker.com/_/mongo"><strong>DockerHub</strong></a> to review the documentation. There we will find documentation on how to use this container. We’re looking for port and external configurations. For instance, the MongoDB server in the image listens on the standard MongoDB port, 27017, so connecting via Docker networks will be the same as connecting to a remote database.</p><pre>vi mongodb-depl.yaml</pre><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mongodb-deployment<br>  labels:<br>    app: mongodb<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: mongodb<br>  template:<br>    metadata:<br>      labels:<br>        app: mongodb<br>    spec:<br>      containers:<br>      - name: mongodb<br>        image: mongo<br>        ports:<br>        - containerPort: 27017<br>        env:<br>        - name: MONGO_INITDB_ROOT_USERNAME<br>          valueFrom:<br>            secretKeyRef:<br>              name: mongodb-secret<br>              key: mongo-root-username<br>        - name: MONGO_INITDB_ROOT_PASSWORD<br>          valueFrom:<br>            secretKeyRef:<br>              name: mongodb-secret<br>              key: mongo-root-password</pre><p>In my last article, <a href="https://medium.com/aws-in-plain-english/kubernetes-minikube-101-d61947b9e091"><strong>Kubernetes &amp; MiniKube 101</strong></a>, I did an in-depth breakdown of the main components that make up a manifest. The only new parameters being passed here are the environment variables. When you create a Pod, you can set environment variables for the containers that run in the Pod. To set environment variables, including the <strong>env</strong> field in the configuration file.</p><p>In our scenario, we’re passing <strong>MONGO_INITDB_ROOT_USERNAME</strong> and <strong>MONGO_INITDB_ROOT_PASSWORD</strong> These variables, used in conjunction, create a new user and set that user’s password. This user is created in the <strong>admin</strong> authentication database and given the role of the root. <strong>secretKeyRef</strong>.<strong>name</strong> &amp; <strong>secretKeyRef</strong>.<strong>key</strong> specifies the secret and its key name, which we will declare in a subsequent step.</p><p><strong>Please note: </strong>Secret must be created before the deployment because this deployment step has dependency over the Secret step.</p><p>Since the MongoDB manifest will eventually be checked into a repository, this is not an ideal location to place an admin login and password in plain text. The solution is to create a <strong>Secret</strong> object to reference the values in our manifest. The Secret will live inside our k8 cluster and will not be available in our repo.</p><blockquote><em>“A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Using a Secret means that you don’t need to include confidential data in your application code. Because Secrets can be created independently of the Pods that use them, there is less risk of the Secret (and its data) being exposed during the workflow of creating, viewing, and editing Pods.” — Kubernetes Documentation</em></blockquote><h3>STEP 3:Create a Secrets Object</h3><p>Before we can apply our MongoDB manifest, we need to create our Secret object that our deployment will reference. When creating a secret, the values are not plain text they must be in base64 encoded. You do this by typing the following commands into your terminal:</p><pre>echo -n &#39;rootlogin&#39; | base64<br>cm9vdGxvZ2lu </pre><pre>echo -n &#39;rootpassword&#39; | base64<br>cm9vdHBhc3N3b3Jk</pre><p>Now paste these values into our Secret config file. I’m using vi to edit within the terminal but you could also do this with an IDE like VScode.</p><pre>vi mongo-secert.yaml</pre><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>    name: mongodb-secret<br>type: Opaque<br>data:<br>    mongo-root-username: cm9vdGxvZ2lu<br>    mongo-root-password: cm9vdHBhc3N3b3Jk</pre><p>Keep in mind we haven’t created anything yet. Everything we’ve done so far has been prep work. If we tried to create a deployment that references a secret that doesn’t exist, you would get an error. Time to apply our secret by running:</p><pre>kubectl apply -f mongo-secret.yaml <br>kubectl get service #run this to confirm it was created</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*7P2bST1KMzlHGj75u5q3Lw.png" /></figure><p>Now we’re able to deploy our MongoDB with the following command:</p><pre>kubectl apply -f mongodb-depl.yaml</pre><h3>STEP 4: Create an Internal Service for MongoDB</h3><p>The internal service will allow other components or pods to communicate with the MongoDB container. Now we could create a separate YAML file for our service or alternatively add it to our MongoDB deployment. Three dashes<strong>---</strong> in Yaml is interpreted as the syntax for document separation.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mongodb-deployment<br>  labels:<br>    app: mongodb<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: mongodb<br>  template:<br>    metadata:<br>      labels:<br>        app: mongodb<br>    spec:<br>      containers:<br>      - name: mongodb<br>        image: mongo<br>        ports:<br>        - containerPort: 27017<br>        env:<br>        - name: MONGO_INITDB_ROOT_USERNAME<br>          valueFrom:<br>            secretKeyRef:<br>              name: mongodb-secret<br>              key: mongo-root-username<br>        - name: MONGO_INITDB_ROOT_PASSWORD<br>          valueFrom:<br>            secretKeyRef:<br>              name: mongodb-secret<br>              key: mongo-root-password<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: mongodb-service<br>spec:<br>  selector:<br>    app: mongodb<br>  ports:<br>    - protocol: TCP<br>      port: 27017<br>      targetPort: 27017</pre><p>To apply these changes we’ll run the same command that we initially ran to create it it.</p><pre>kubectl apply -f mongodb-depl.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sMzP5xju9bkVGwrHIqmXkA.png" /></figure><p>Run the following commands to confirm that our internal service was successfully created and attached to our MongoDB pod.</p><pre>kubectl get service<br>kubectl describe service mongodb-service<br>kubectl get pod -o wide</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*GrsSNgs2xZP4XIfzzcpo_A.png" /></figure><p>With our current setup, only components with the cluster can access mongoDB. That completes the internal design, and now to move on to our external configuration.</p><h3>STEP 5: Create a Manifest for Mongo Express</h3><p>Mongo Express is an interactive lightweight Web-Based Administrative Tool to manage MongoDB Databases effectively. Numerous MongoDB Admin duties can be simplified by using Mongo Express, which was created with Node.js, Express, and Bootstrap 3. You can create, remove, update, or delete databases, collections, and documents using Mongo Express. Similar to MongoDB, we will reference the documentation in docker hub to better understand how to use this image.</p><p><a href="https://hub.docker.com/_/mongo-express">mongo-express - Official Image | Docker Hub</a></p><p>We will need to pass mongodb parameters into the mongo-express manifest so it can authenticate and connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7Apgtue2EWadanmsAbaPA.png" /></figure><p>We will reference our mongodb-secret object when accessing the base64 encoded password we assigned to MongoDB. The value for ME_CONFIG_MONGODB_SERVER which the MongoDB URL could be passed right into our deployment but we will create a ConfigMap that will be referenced. A ConfigMap stores configuration settings for your code like non-confidential data, hostnames, and URLs in key-value pairs. It also allows us to separate our configuration from the application.</p><blockquote><strong><em>Caution:</em></strong><em> ConfigMap does not provide secrecy or encryption. If the data you want to store are confidential, use a Secret rather than a ConfigMap, or use additional (third party) tools to keep your data private. — Kubernetes Documentation</em></blockquote><pre>vi mongoexpress-depl.yaml</pre><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mongo-express<br>  labels:<br>    app: mongo-express<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: mongo-express<br>  template:<br>    metadata:<br>      labels:<br>        app: mongo-express<br>    spec:<br>      containers:<br>      - name: mongo-express<br>        image: mongo-express<br>        ports:<br>        - containerPort: 8081<br>        env:<br>        - name: ME_CONFIG_MONGODB_ADMINUSERNAME<br>          valueFrom:<br>            secretKeyRef:<br>              name: mongodb-secret<br>              key: mongo-root-username<br>        - name: ME_CONFIG_MONGODB_ADMINPASSWORD<br>          valueFrom: <br>            secretKeyRef:<br>              name: mongodb-secret<br>              key: mongo-root-password<br>        - name: ME_CONFIG_MONGODB_SERVER<br>          valueFrom: <br>            configMapKeyRef:<br>              name: mongodb-configmap<br>              key: database_url</pre><p>This image will require a database name to connect, for which we will require a MongoDB address or internal service. We will specify the database URL inside ConfigMap in the next phase.</p><h3>STEP 6: Create a ConfigMap for Mongo Express</h3><p>Similar to how Secret needed to be created before it could be referenced in our earlier deployment, Configmap needs to be created before it can be referenced as well.</p><pre>vi mongo-configmap.yaml</pre><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: mongodb-configmap<br>data:<br>  database_url: mongodb-service</pre><p><strong>database_url</strong> : is MongoDB&#39;s internal service name, which we specified when we created the internal service in step 4.</p><p>Deploy both by running :</p><pre>kubectl apply -f mongo-configmap.yaml<br>kubectl apply -f mongo-express.yaml</pre><h3>STEP 8: Create an External Service for Express</h3><p>Similar to MongoDB, we could add the external service for express within our Mongo Express manifest. However, to showcase that a service can be deployed by itself, we will not merge the two this time.</p><pre>vi express-service.yaml</pre><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: mongo-express-service<br>spec:<br>  selector:<br>    app: mongo-express<br>  type: LoadBalancer  <br>  ports:<br>    - protocol: TCP<br>      port: 8081<br>      targetPort: 8081<br>      nodePort: 30000</pre><p>Let’s `unpack` what is going on in this file. We have exposed a service port at 8081.</p><p><strong>targetPort:8081</strong> is where the container port is listening.</p><p><strong>type:LoadBalancer</strong>: makes the service external by assigning the service an external IP address.</p><p><strong>nodePort: 30000 </strong>the<strong> </strong>port on which this pod can be accessed externally. This nodePort has a range between 30000–32767.</p><p>Run the following commands to confirm that our service was successfully created and attached to our pod.</p><pre>kubectl get service<br>kubectl describe service mongodb-service<br>kubectl get pod -o wide</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBS9nd3SjAy4YzBtNTFIZg.png" /></figure><h3>STEP 9: Quality Assurance Check</h3><p>This command will assign a public IP address to an external service</p><pre>minikube service mongo-express-service</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iweuuYsYa1m6T-P5LgO8Sg.png" /></figure><p>We can access the application in our browser on port 30000, as given in the external service yaml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBT5KHNCr8Bel0Wtv0CKig.png" /></figure><h3>Deletes a local Kubernetes cluster</h3><p>When you’re done testing or developing within Minikube, the cleanup is as simple as a single command. This command deletes the VM and removes all associated files.</p><pre>minikube delete</pre><h3>Conclusion</h3><p>We set up a complete, end-to-end Mongodb application on Kubernetes and used our browser to access it. Using an internal service, we built a mongodb pod and made it available to the other component. We also developed a single pod for mongo-express to modify mongodb and external service to make it reachable outside the cluster or external sources.</p><p>Thank you for taking the time out of your day to read this article. I hope you were able to get some value from the content. If this content interests you, follow my page for more articles on DevOps tools and methodologies. Let’s also connect on <a href="https://www.linkedin.com/in/ray-sylverne/"><strong>LinkedIn</strong></a>, where we can continue the conversation.</p><h3>DOCUMENTATION &amp; REFERENCES</h3><p>Don’t forget to push your code and files to your Git repo. <a href="https://github.com/raysylverne/mongodb_app"><strong><br>Link to my repo for this project</strong></a><strong><br> — Commands<br> — YAML Files</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*Z94VaAvxMjFXs_nIa4IoGA.png" /></figure><ul><li><a href="https://minikube.sigs.k8s.io/docs/start/">minikube start</a></li><li><a href="https://hub.docker.com/_/mongo">mongo - Official Image | Docker Hub</a></li><li><a href="https://hub.docker.com/_/mongo-express">mongo-express - Official Image | Docker Hub</a></li><li><a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/">kubectl Cheat Sheet</a></li></ul><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><strong><em>, </em></strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><strong><em>, and</em></strong><em> </em><a href="https://discord.com/invite/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Build awareness and adoption for your tech startup with </em></strong><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa5f46d694c" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/deploy-front-backend-application-on-kubernetes-fa5f46d694c">Deploy Front &amp; Backend Application on Kubernetes</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes & MiniKube 101]]></title>
            <link>https://aws.plainenglish.io/kubernetes-minikube-101-d61947b9e091?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d61947b9e091</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 17:09:32 GMT</pubDate>
            <atom:updated>2023-02-10T17:59:10.230Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GIp-R_p2WZb6W4-4cKx5g.png" /></figure><p><strong>What is Kubernetes?</strong></p><p>Kubernetes is a container orchestration platform that helps manage and deploy applications at scale. It has self-healing, automatic scaling, and load-balancing capabilities, which makes it the perfect solution for large-scale installations. Additionally, Kubernetes is very extensible, enabling customers to include new features as required.</p><p><strong>What problem does Kubernetes solve?</strong></p><p>The core problem that Kubernetes is solving is the ability to manage containerized apps at scale. When you migrate workloads to the cloud, the core difference between a data center and the cloud is you’re no longer managing the hardware. However, the actual complexities other than managing hardware are the same in the cloud as they would be on-premises. You would still have to figure out scaling policies, replicas, auto-healing, how you manage and interact with the applications, and how to automate everything that was just listed. I will walk you through a demo that will simplify many of the issues I just raised and some of the advantages of running Kubernetes via Minikube.</p><h3>FOUNDATIONAL OBJECTIVES<strong>:</strong></h3><ul><li>Using the command line, create a deployment that runs the nginx image</li><li>Display the details of this deployment</li><li>Check the event logs from the deployment</li><li>Delete the deployment</li></ul><h3>ADVANCED OBJECTIVES<strong>:</strong></h3><ul><li>Create the same deployment using a YAML file</li><li>Display the details of this deployment via the command line</li><li>Update the YAML file to scale the deployment to 4 nginx containers</li><li>Verify the change via the command line</li></ul><h3>COMPLEX OBJECTIVE:</h3><ul><li>Deploy a NodePort service using port 80 with our deployment</li></ul><h3>Pre-Requisites To Follow Along</h3><ul><li>Download these tools in the order presented:</li></ul><ol><li>Follow the instructions to install <a href="https://docs.docker.com/get-docker/"><strong>Docker Desktop</strong></a></li><li>Follow the instructions to install <a href="https://kubernetes.io/docs/tasks/tools/"><strong>kubectl</strong></a> based on your OS</li><li>Follow the instructions to install <a href="https://minikube.sigs.k8s.io/docs/start/"><strong>minikube</strong></a><strong> </strong>based on your: OS, Architecture, Release type, &amp; Installer type</li></ol><ul><li>The commands are different for each, so make sure to choose the right parameters</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*yKWc2pHX4WP46w-xr8Vsgw.png" /></figure><h3>Minikube Environment Setup:</h3><p>Before we get right into the demo, I want to answer the question, <strong>“What is Minikube?” </strong>Minikube works by setting up a Kubernetes cluster on a local machine. By default, it creates a one-node cluster, but you can create a multi-node cluster with a Minikube environment if desired. Minikube installation is very simple. You need to download the package. It is a single binary that is executable and that is all you need.</p><p>Tons of driver options can be found with instructions on the <a href="https://minikube.sigs.k8s.io/docs/drivers/">M<strong>inikube site</strong></a><strong>. </strong>In my case, I will run the following to start Minikube with Docker:</p><pre>minikube start --driver=docker</pre><p>To verify, execute the following status command.</p><pre>minikube status</pre><p>You should see the following output:</p><pre>minikube<br>type: Control Plane<br>host: Running<br>kubelet: Running<br>apiserver: Running<br>kubeconfig: Configured</pre><blockquote><strong><em>Important</em></strong><em> </em><strong><em>Note: </em></strong><em>Minikube has networking issues with Virtualbox version 7.x. If you want to use Minikube with Virtualbox, use a version lower than 7.x. If you are a MAC M1 user (like me 😔), you cannot use Virtual Box. Use Docker Desktop as the backend driver.</em></blockquote><h3>Ok, with the prep out of the way, let’s get started!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*-p-KlgUa0JfR9iYyn1c2uQ.gif" /></figure><h3>FOUNDATION:</h3><p>Use the command line to create a deployment that runs the nginx image.</p><pre>kubectl create deployment nginx-depl --image=nginx</pre><p>Display the basic details of this deployment by running <strong>kubectl get deployment</strong>With that, you’ll see a list with the names of all your deployments. If you want more information about just your particular deployment, add the deployment name to the same command <strong>kubectl get deployment nginx-depl -o wide . </strong>Below you’ll find the command and sample outputs.</p><p><strong>-o wide </strong><em>Output in the plain-text format with any additional information in expanded (aka “wide”) output</em></p><pre>$ kubectl get deployment<br><br><br>$ kubectl get deployment nginx-depl -o wide</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEwHdfGeZMDR0MQgkl77_w.png" /></figure><h3>Check the event logs from the deployment</h3><p>The kubectl log command is the command that displays information about the background activities or events completed or ongoing in your resources. It is used to view container logs for debugging. Since container applications are packed in pods, the next course of action whenever a container application fails or acts up is to check the logs of the container or containers in that pod to determine the problem.</p><pre><br>kubectl get pods #use this command to get your pods name<br><br><br>kubectl logs &lt;pod_name&gt; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVXIxtC6vnbMbjum_qccwQ.png" /></figure><h4>Quick Clean-Up:</h4><p>When learning Kubernetes, you’ll often want to launch and delete deployments. Deleting deployments is easy, thanks to the <strong>kubectl delete deployment &lt;deployment_name&gt; </strong>. In this scenario, we have one pod but if we had a more robust architecture, this is a situation where you’d want to run <strong>kubectl get deployments in advance </strong>to make sure you delete the right resource.</p><pre>kubectl delete deployment nginx-depl<br></pre><p>The <strong>kubectl delete deployments</strong> command deletes deployments that are present in the &quot;default&quot; namespace unless you provide a different namespace.</p><h4>What is a namespace in Kubernetes?</h4><p>Namespaces are designed to be used in settings where numerous users are dispersed across multiple teams or projects. In a Kubernetes cluster, it functions similarly to a standalone virtual cluster. For example, you can have separate namespaces to isolate your workloads for <strong>production, staging, and development environments. </strong>To delete a deployment that&#39;s not in the default namespace, you would need to run <strong>kubectl get deployments --all-namespaces</strong> which would list all the deployments from all namespaces.</p><pre>kubectl get deployments --all-namespaces<br><br>#output<br>NAMESPACE     NAME           READY   UP-TO-DATE   AVAILABLE   AGE<br>default       mongodb-depl   1/1     1            1           23m<br>kube-system   coredns        1/1     1            1           2d3h</pre><p>When you have the namespace and the deployment name, you can specify it to the kubectl delete deployment command.</p><pre>kubectl delete deployments --namespace=default mongodb-depl<br><br>#output <br>deployment.apps &quot;mongodb-depl&quot; deleted</pre><h3>ADVANCED: YAML Files Four Top Level Properties</h3><p>I’ve walked you through some basic kubectl CLI commands, but now it&#39;s time to introduce you to defining <strong>Kubernetes manifest</strong>. The manifest. yml file is a YAML-based schema definition for mapping external ports, directories, environment variables, and various configuration options for your custom image. YAML will allow you to design considerably more complicated structures than the command line can. You can also add YAML files to source control, such as a GitHub repository, to track changes over time.</p><p>We’ll start by creating our file with the following command:</p><pre>vim nginx-depl.yml</pre><p>Let’s unpack what is going in this file. Four required fields must be present when writing YAML files for Kubernetes: <strong>apiVersion, kind, metadata, and specifications (specs).</strong></p><p><strong>apiVersion </strong>This field refers to the API used to create the defined Kubernetes object. <strong>apiVersion: v1</strong>is regarded as Kubernetes’ initial stable release. However, we’re using, <strong>apiVersionapp/v1</strong>, which incorporates v1 objects and offers essential features like deployments and ReplicaSets.</p><p><strong>kind</strong> allows you to specify which type of Kubernetes object you aim to define. This could be pods, service, deployment, and DaemonSets to name a few.</p><p><strong>metadata</strong> is where you define specific properties for that particular object after defining the object type some options are name, uuid, and namespace</p><p><strong>specs </strong>allows you to define all the configurations you want to apply to the component. The attributes available to you are based on the <strong>kind</strong> of component you are creating. In our case, we’re deploying an Nginx container with port 80 exposed.</p><p><strong>labels </strong>can be used to organize and select subsets of objects. In short, labels let the deployment know which pod belongs to it. Labels can be attached to objects at creation time and subsequently added and modified at any time.</p><p>Copy and paste the syntax below into your newly created file. I know I said it would be easier and probably looks more complex than what you saw in the command earlier. However, take my word when I say that the deployment object will become your favorite tool as the architecture becomes more robust.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-depl<br>spec:<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest<br>        ports:<br>        - containerPort: 80</pre><p>Earlier, you saw me use <strong>kubectl create deployment </strong>Now I’ve shifted to <strong>kubectl apply deployment </strong>. The critical difference between the two is that <strong>apply</strong> creates Kubernetes objects through a <strong>declarative</strong> syntax, while the <strong>create</strong> command is <strong>imperative</strong>.</p><pre>kubectl apply -f nginx-depl.yml</pre><p>Meaning <strong>kubectl apply</strong> is used at a terminal’s command-line window to create or modify Kubernetes resources defined in a manifest file. Whereas the <strong>kubectl create</strong> is the command you use to create a Kubernetes resource directly at the command line. This is an imperative usage.</p><blockquote><em>You can also use kubectl create against a manifest file to create a new resource instance. However, if the resource already exists, you will get an error. In most cases </em><strong><em>apply </em></strong><em>will be your default.</em></blockquote><h4><strong>Let Check on our Deployment</strong></h4><p>Earlier, I showed how to get some basic info on your deployment by running <strong>kubectl get deployment -o wide</strong>.kubectl get deployment If you want a more in-depth output of pod data, then you should run kubectl get deployment</p><pre>kubectl describe deployment nginx-depl</pre><p><strong>kubectl describe deployment &lt;resource&gt; </strong>is a command that describes any resource in Kubernetes. It shows data on a single or even a collection of resources. This command combines several API calls to comprehensively describe a resource or set of resources. As you can see, there’s a lot of information here, but we’re most interested in the Events — specifically. This is where the warnings and errors start showing up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5PonsZ6E9ule2oMCx4dfw.png" /></figure><h4>Update the Manifest to Scale the Deployment to 4 Nginx Containers</h4><p>To execute this request, we’re going to navigate in our file again:</p><pre>vim nginx-depl.yml</pre><p>You will want to add the attribute <strong>replicas: 4 </strong>under the <strong>specs:</strong> section. This will tell the deployment to run 4 pods matching our defined <strong>template</strong>. Kubernetes is mainly coupled with Docker but Docker is not the only runtime it supports. The k8 pods act as an abstraction layer over the containers. Your system design will remain open and modular if the middleware, cloud-native services, and container orchestration layers are kept apart. In that same breath, you can think of deployments as an abstraction layer over the pod. What this means is whatever changes we make in the deployment file will cascade down to replicaSet and then our pods.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-depl<br>spec:<br>  replicas: 4 # tells deployment to run 4 pods matching the template<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest<br>        ports:<br>        - containerPort: 80 </pre><p>Take note of the output when I run <strong>kubectl apply -f nginx-depl.yml </strong>the system is aware that the file has been changed and is updating our cluster&#39;s current state to match the desired state of adding 3 replicas. Running <strong>kubectl get pods confirms </strong>that we achieved our outcome</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*6Uf9lAF3CcZiKQDcT7--Ug.png" /></figure><h3>COMPLEX</h3><p>We are asked to create a multi-container deployment and a NodePort service using port 80. A NodePort service is the most basic way to get external traffic directly to your service. NodePort, as the name implies, opens a specific port, and any traffic sent to this port is forwarded to the service. I could create a separate YAML file for this service. However, outside of this demo in a practical application, you would rarely have a deployment without a service so it makes sense to keep them together. We can do this by using three dashes---, which in Yaml is interpreted as the syntax for document separation.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: nginx-svc<br>spec:<br>  type: NodePort<br>  selector:<br>    app: nginx<br>  ports:<br>  - port: 80<br>    targetPort: 80<br><br>---<br><br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-depl<br>spec:<br>  replicas: 4<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest<br>        ports:<br>        - containerPort: 80<br></pre><p>I also changed the order in accordance with Kubernetes documentation which states,</p><blockquote><em>“The resources will be created in the order they appear in the file. Therefore, it’s best to specify the service first, since that will ensure the scheduler can spread the pods associated with the service as they are created by the controller(s), such as Deployment.” — </em>Kubernetes documentation</blockquote><p>We will run the kubectl apply command again.</p><pre>kubectl apply -f nginx-depl.yml </pre><p>To check our work, you can run individual kubectl get commands to list down each resource one by one, as seen below:</p><pre>kubectl get deployment <br>kubectl get service <br>kubectl get pods<br>kubectl get replicaset<br>kubectl get &lt;resource_type&gt;</pre><p><strong>Or </strong>you can list all the resources in a Kubernetes namespace by running a single command. Assuming you know the namespace you’re in, otherwise, run kubectl get namespace first since its part of the syntax for the kubectl get all command. When you are working with Kubernetes, if you want to list all the resources (Kubernetes objects) associated with a specific namespace, run the following:</p><pre>kubectl get all -n default</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*D_ZtWKlDzFIG_aQJ1sQ0Xg.png" /></figure><p>This last command is specific to the Minikube use case. So, in Minikube, we can assign an IP to an external service using the minikube service &lt;service_name&gt;command. With this command, we can access a Service exposed via a node port:</p><pre>minikube service nginx-svc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u6ydeUrr6hWouU2hyHs80w.png" /></figure><p>Usually, the Nodeport is an open port on every node of your cluster. Kubernetes transparently routes incoming traffic on the Nodeport to your service. For Minikube, however, a random port is generated and used with node ip, minikube-ip:port.</p><p>Take note of the port associated nginx-svc, and the comment below mentions opening a service in a default browser. If I navigate to my browser, we can confirm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*DRhPlu6ahKg1iqOhN8GAYw.png" /></figure><h3>EXTRA “CREDITS”</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*25Vu2_5lKDK3ESyyIsYnAA.gif" /></figure><p>While working on this objective, I came across the Minikube Dashboard. You can use a web-based UI to manage clusters and deploy applications. It can provide an overview of your cluster operations and make it easier to modify any running resources. You can also use it to monitor your cluster resources&#39; state or investigate errors.</p><p>The following command enables the dashboard add-on and opens a proxy for you:</p><pre>minikube dashboard</pre><p>After waiting a few minutes, you should have feedback in the terminal window showing the dashboard has started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HU4KiT-8pxEBYox_HNEcCQ.png" /></figure><p><strong>And there you have it! </strong>Your browser should also open to the dashboard, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6RqdPRPa2pCa52I2BJd7Q.png" /><figcaption><strong>Minikube Dashboard</strong></figcaption></figure><h3>Deletes a local Kubernetes cluster</h3><p>When you’re done testing or developing within Minikube, the cleanup is as simple as a single command. This command deletes the VM and removes all associated files.</p><pre>minikube delete</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*UxG7oWDC2aOlJczNGBuGkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*6VyNSPDpoBoeBmsOmOHXsw.gif" /></figure><p>Thank you for taking the time out of your day to read this article. I hope you were able to get some value from the content. If this content interests you, follow my page for more articles on DevOps tools and methodologies. Let’s also connect on <a href="https://www.linkedin.com/in/ray-sylverne/"><strong>LinkedIn</strong></a>, where we can continue the conversation.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d61947b9e091" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/kubernetes-minikube-101-d61947b9e091">Kubernetes &amp; MiniKube 101</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker, AWS Elastic Container Registry (ECR), DockerHub]]></title>
            <link>https://aws.plainenglish.io/docker-aws-elastic-container-registry-ecr-dockerhub-2731cfe47c59?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2731cfe47c59</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws-ecr]]></category>
            <category><![CDATA[dockerhub]]></category>
            <category><![CDATA[docker-registry]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 14:54:10 GMT</pubDate>
            <atom:updated>2023-03-01T17:15:08.895Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker, AWS Elastic Container Registry (ECR)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*JLhBzRk_WfM1j_qHHa2tOQ.png" /></figure><p>If you’re new to Docker Containers, you might ask yourself two questions.</p><h4>1. What is a container &amp; what problem does it solve?</h4><p>Virtual Machines are the predecessors to containers we can start with the premise that they share commonalities. For instance, they both provide isolated environments to run processes securely but differ in their specific purposes. The biggest difference is that a containerized application has more direct access to hardware than an application running in a VM, making containers lightweight. Containers only abstract the application layer, meaning you can expect the same performance as you move from one computing environment to another. This decoupling allows container-based applications to be deployed quickly and consistently, regardless of whether the target environment is a private data center, the public cloud, or even a developer’s personal laptop.</p><h4>2. What problem does it solve?</h4><p>Docker allows you to package entire applications, their libraries, dependencies, environment, and everything else the application needs to run into a portable container. Being certain that your application will run correctly when it is moved through a pipeline from Development to Test and, inevitably, Production environment is one of its greatest benefits. In an agile DevOps world, this has become more critical than ever. Agile methodologies are based on frequent and incremental code version changes, so frequent testing and deployments are required. With that out, let’s get some hands-on experience while going through some real-world use cases.</p><h3><strong>Skills and Tools Required to follow along:</strong></h3><ul><li><a href="https://www.docker.com/products/docker-desktop/"><strong>Docker Desktop Installed</strong></a></li><li><strong>AWS CLI: Installed and Credentials Configured</strong></li><li>Linux CLI familiarity</li><li><strong>Git/GitHub</strong></li><li><strong>IDE (Cloud9, VS Code, PyCharm…)</strong></li></ul><h3><strong>Objective:</strong></h3><p><strong>Your team needs you to deploy a custom image quickly and write a quick script in a file to accomplish a task.</strong></p><p>1. Create an image using Nginx. Include a customized index.html file that can be viewed from a local browser.</p><p>2. Deploy your container with port 8080 open</p><p>3. Save your container data to the AWS Elastic Container Registry (ECR), and your Docker Hub account.</p><h3>Step 1 Create A Custom Nginx Image</h3><p>We’ll get started by creating a directory to work within.</p><pre><br>mkdir &lt;directory name&gt;<br><br>cd &lt;directory name&gt;</pre><p>From within the directory, we will pull and NGINX the image from <a href="https://hub.docker.com/">docker.com </a>with the following command.</p><pre>docker pull nginx:latest</pre><p>As seen below in the yellow box, this command pulls the latest Nginx image from the docker hub. You’re also able to view all of your images by running.</p><pre>docker images  </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQObw8P0e_wvt8dGD9VwVg.png" /></figure><p>Now we need to create a customized index.html file and our Dockerfile. You can do this through an IDE like Cloud9 or VS Code but I will stay within the terminal using vim. Run <strong>vi index.html </strong>which will create your file and take you right into the editor.</p><pre><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;Docker Lab&lt;/title&gt;<br>    &lt;body&gt; style=&quot;background-color:purple;&quot;&gt;&lt;center&gt;<br>    &lt;/style&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;h1 style=&quot;color:purple;&quot;&gt;Docker Containers are here!&lt;/h1&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>A <strong>Dockerfile</strong> is a straightforward text file that contains a list of commands that the Docker client calls while creating an image. It’s a simple way to automate the image creation process. We’ll create these within the terminal using Vim.</p><pre>vi Dockerfile<br><br><br>FROM nginx<br>EXPOSE 8080<br>COPY index.html /usr/share/nginx/html</pre><p>Let&#39;s unpack some of the components within the file.</p><p><strong>FROM </strong>lets us specify which base image from Docker Hub we want to build from. In our case, we are using the latest version of the official <strong>nginx</strong> image. Note that if a version number is not provided after <strong>nginx </strong>docker will always default to <strong>nginx:latest</strong></p><p><strong>EXPOSE </strong>this will expose ports that the container will listen on.</p><p><strong>COPY </strong>is pretty straightforward and lets us copy files or a whole directory from a host to a destination. We are going to <strong>COPY</strong> the <strong>index.html </strong>file over to our working directory.</p><h4><strong>Build A Custom Image</strong></h4><p>We have everything we need to build the custom image we’ll use to start a container. Docker will try to find a file named <strong>Dockerfile</strong> inside the <strong>context_dir</strong> and create a Docker image using the <strong>Dockerfile</strong> file. It might be hard to see but the dot (.) indicates that the <strong>Dockerfile</strong> is in the current directory. In my actual command, I also added a tag at the end of my image to track versions. You’ll see why this is relevant when I push the image to an AWS ECR.</p><pre><br>docker build -t &lt;imageName&gt; &lt;context_dir&gt;<br><br>#What I actually ran <br>docker build -t nginxapp:1.0 .</pre><p>If we run <strong>docker images </strong>we should be able to identify our newly created custom image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQngj44GxP6QL3NvtTsRBQ.png" /></figure><h3>Step 2:Creating A Container With Port 8080</h3><p>Now that we have our image, we can create a container with the following command.</p><pre>docker run -d -p &lt;host_port&gt;:&lt;container_port&gt; \<br>--name &lt;container_name&gt; \<br>&lt;image_name&gt;:&lt;tag&gt;</pre><p><strong>-d </strong>this flag will run the container in the background mode and print the container ID</p><p><strong>-p </strong>this option sets the port mappings between the host and the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQVnOQkEC8Xfd4UqH-a7kw.png" /></figure><p>Running <strong>docker ps </strong>not only confirms that our container was successfully created and provides valuable information like contianerID, imagename:tag, ports, and containerName. We know our container is up but we’ll run <strong>curl localhost </strong>to test that we can access the internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPgwh7pisKMOPzFHvoNSwQ.png" /></figure><p>You could also run <strong>htttp://localhost:8080</strong> in your browser as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*B7XZalQF7P7rFuyEl2Ic7w.png" /></figure><h3>Step 3: Push Image To AWS ECR</h3><p>For this next phase, we will create a private repository for our image on AWS ECR. You’ll want to push your containerized image to a Docker Repository or Repo so other developers or testers can pull the most up-to-date image of the application. The first step will be to login into <strong>AWS Console </strong>&gt; type “<strong>ECR</strong>” in the search bar and select <strong>Get Started</strong> under Create Repository. There are several options on this screen, like visibility settings to make your application private or public or tag mutability which prevents image tags from being overwritten by subsequent image pushes. However, for this simple project, we’re only setting the name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-stoQRM_pZsvf6hCpwVY1Q.png" /></figure><p>Once created, it will naturally be empty if you go into the repo. However, something interesting is that AWS provides you with the commands needed to push your image to the repo. Which I think is pretty handy since the syntax isn’t as straightforward as you’d think. A<strong> </strong>Pre-Requisites to this step is to have AWS CLI needs to be installed and credentials configured otherwise, the commands won’t work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w5XGVkBqLB9GV0ZPsdQZJA.png" /></figure><p>Below is exactly what you’ll see after selecting V<strong>iew push commands.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*ydgqTJXG5QyZfNvlyEY49w.png" /></figure><ol><li>The first step is to authenticate your Docker Client and log in. If this image were built and pushed from Jenkins, you’d have to permit Jenkins to log into the repo.</li><li>We’ve already built our image so this can be skipped.</li><li>The purpose of this step is to prepare for the subsequent push command. When naming images in Docker registries, the registry domain should precede the imageName for example <strong>registryDomain</strong>/imageName:tag. The tag command will make a copy of our image and rename it to include the repo domain address. Without this precursor, the push command wouldn’t know which repo to push the image to; by default, it would send it to Docker Hub.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dssw4dw4jcLqcq24k7iV5A.png" /><figcaption><strong>NOTE: When you copy the command, don’t forget to update the tag from nginxapp:latest to nginxapp:1.0</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9WdHc5EnoD5ToKMyZtCQA.png" /><figcaption><strong>We have the original and our copy that prepped to be pushed</strong></figcaption></figure><p>4. The push command says I want to take the <strong>nginxapp:1.0</strong> and push it into the repo at the preceding address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*gr--Iy8fP9YbzSvbEJ0cPA.png" /></figure><p>Pulling, pushing, and tracking different versions of an app would be very useful if you wanted to test a previous version.</p><blockquote><strong><em>Fun Fact:</em>Amazon Elastic Container Registry (ECR) default limit has been increased to 10,000 repositories per region and 10,000 images per repository to better align with your requirements and growth.</strong></blockquote><h3>Step 4: Push The Image To Docker Hub</h3><p>The first thing we’ll need to do is make sure you’re logged into the repo.</p><pre>docker login</pre><p>Then you’ll want to tag and push your image with the following commands.</p><pre>docker tag &lt;image_id&gt; &lt;repositry&gt;/&lt;image_name&gt;:&lt;tag&gt;<br>docker push new-repo:tagname</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZ77ue3gZIOTF4ILVCmmvg.png" /></figure><p>We can check our work by navigating to dockerhub where our newly created repo and image can be found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q8fRoBpWouizfFO_ctGhdw.png" /></figure><h3>Wrap Up:</h3><p>If you’re done with this demo, clean up your environment by removing containers and images with the following commands.</p><pre>#You need to stop your container before you can remove it<br>docker stop &lt;container name or ID&gt;<br>#Remove containeer<br>docker rm &lt;container name or ID&gt;<br>#You cannot delete an image if a container is running on that image<br>docker rmi &lt;image name or ID&gt;</pre><p>Note: Technically, you can remove a container while running, but you have to use the <strong>-f</strong>flag to force it. You will also want to delete the repos we created in AWS ECR and Dockerhub.</p><p>Thank you for taking the time out of your day to read this article. I hope you were able to get some value from the content. If this content interests you, follow my page for more articles on DevOps tools and methodologies. Let’s also connect on <a href="https://www.linkedin.com/in/ray-sylverne/"><strong>LinkedIn</strong></a> where we can continue the conversation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*aPONL9Ru5gcB2B4R-wyvbw.gif" /></figure><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2731cfe47c59" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/docker-aws-elastic-container-registry-ecr-dockerhub-2731cfe47c59">Docker, AWS Elastic Container Registry (ECR), DockerHub</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Scalable, Resilient & Fault Tolerant 3-Tier Architecture]]></title>
            <link>https://aws.plainenglish.io/create-a-scalable-resilient-fault-tolerant-3-tier-architecture-9cdb3064b2de?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cdb3064b2de</guid>
            <category><![CDATA[3-tier-architecture]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[auto-scaling-groups]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Mon, 05 Dec 2022 19:18:03 GMT</pubDate>
            <atom:updated>2022-12-08T18:28:33.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6s2CUV65-9oKE5jiFwXa5w.jpeg" /></figure><h3>SITUATION</h3><p>You have been asked to design and create a highly available, scalable, fault-tolerant 3 Tier architecture for your company’s new web application. A 3 tier architecture is a client-server design with <strong>a presentation tier, a logic tier, and a data tier</strong> that is each developed and maintained as independent modules on separate platforms. A tier can be thought of as a layer. I will use the analogy of looking at movie times in your area using a web application to break down each layer.</p><ol><li>A <strong>Web Layer </strong>(presentation tier)<strong> </strong>transmits HTML/JS/CSS content to browsers. It’s the most visible layer and defines the application’s overall look and presentation to your end users. This layer displays your web page with fields to enter, like the movie (Black Panther: Wakanda Forever), dates, times, and zip code.</li><li>That information is then passed to the <strong>Application Layer </strong>(logic tier)<strong>. </strong>This layer uses an application server and processes the business logic for the application. This might be written in C#, Java, C++, Python, Ruby, etc.</li><li>A <strong>Data Layer </strong>is a database management system that provides access to application data. This could be MariaDB, MySQL, PostgreSQL, etc. The database system runs the query and returns the results (a list of showtimes within your geographic area) to the application layer, which formats it into a web page.</li><li>The page is then returned to the browser, where the Web layer displays it on a laptop, phone, or another device.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*iLIxVzHa1Q1V3xTNR56pBg.png" /><figcaption>M’Baku wasn’t the main character but my favorite and funniest 😂</figcaption></figure><h3>MISSION EXECUTABLES</h3><ol><li>Create a VPC, subnets, and Internet gateway, and edit route tables.</li><li>Configure Security Groups to only allow traffic from one tier to the next in succession, beginning with our Web-ALB and ending with the database tier</li><li>Create the database tier using RDS (free tier).</li><li>Create an Application load balancer for the web tier (Internet-facing) and application tier (Internal-facing).</li><li>Create EC2 Auto-scaling groups for the Web and Application tiers. Configure security groups, so the web tier only accepts traffic from the ALB (Application Load Balancer), and the application tier only accepts traffic from the web tier security group.</li><li>Verify that the web tier can be accessed from the Internet and ping the application tier.</li></ol><h3>STEP 1: Create a VPC, subnets, and Internet gateway</h3><p>Start off by navigating to your AWS console and typing VPC in the search bar, then select <strong>Create VPC.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGYm2H3pXsITWlqR3JIz8A.png" /></figure><p>Following the diagram, we’ve created a VPC with two availability zones. Each AZ has a Nat Gateway, public and private route tables, and subnets for each respective layer within our 3-Tier architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*NhEgad_0B3W_QqjkM29aVg.png" /></figure><h3>STEP 2: Web Tier Launch Templates &amp; AutoScaling Group</h3><p>In the left pane, under Instances, select Launch Templates &gt; Create Launch Templates. After providing a unique name for your template, check off the box labeled Auto Scaling guidance. Choose Amazon Linux AMI&gt; t.2micro instance type&gt; create new key pair (lab9).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*pjLrdPdkv2xGxmbDgJAxbg.png" /></figure><p>We will create a new Security Group (WEB_SG) and associate it with the Lab9-VPC we created. You will need to add rules to allow traffic through ports 80 (HTTP) and 22 (SSH).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*QyiTxjyjjcz0WH9cDGB7xg.png" /></figure><p>Under “Advanced network configuration,” I also selected “Auto-assign public IP”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*lgWaTb2oWlkBng7UsCDgsA.png" /></figure><p>To efficiently update all packages and install the “Apache” web server, I also added the following bootstrap under “User data” under “Advanced details” in the launch template before clicking “Create launch template.”</p><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd<br>EC2AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) <br>echo &#39;&lt;center&gt;&lt;h1&gt;This Amazon EC2 instance is located in Availability Zone: AZID &lt;/h1&gt;&lt;/center&gt;&#39; &gt; /var/www/html/index.txt<br>sed &quot;s/AZID/$EC2AZ/&quot; /var/www/html/index.txt &gt; /var/www/html/index.html</pre><h4><strong>2.1 Auto Scaling Group</strong></h4><p>After launching your template, you’ll be brought to the Launch template dashboard. From there, select your template to highlight it, and under <strong>Actions, </strong>select Create Auto Scaling Group (ASG). ASG creation involves about seven steps after providing a unique name, you will need to select your VPC and subnets to the association.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*PG9aiJl9MSMX7_4tVKIX_Q.png" /></figure><p>Choose a load balancer to distribute incoming traffic for your application across instances to make it more reliable and easily scalable. You can also set options that give you more control over health check replacements and monitoring. Our WEB-ALB will be <strong>internet-facing</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*rxL8L3gV1Qsci8tc2D72Tw.png" /></figure><p>We will opt to create a target group and check off ELB health checks. EC2 Auto Scaling automatically replaces instances that fail health checks. If you enable load balancing, you can enable ELB health checks and the EC2 health checks that are always enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*8EV8TArRL_1G6oyuegcC_Q.png" /></figure><p>The next phase involves choosing your group size by selecting desired, minimum and maximum capacity. I also enabled the Target tracking scale policy, which creates another instance when the average CPU reaches 50% or above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*0xGsuhnY7-K-1aZxHB-cEw.png" /></figure><p>There is an optional step to create a tag for your newly created instance. The last stage involves reviewing your configuration and, assuming no changes are needed, create your ASG and navigate to instances in the left pane to test your instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*MekFbh1vszRDKQNqsbLFHQ.png" /></figure><p>Head to your newly create ALB to test your application. Ensure that your ALB has the WEB-SG attached to it, allowing inbound traffic from HTTP. Copy your ALB DNS name and navigate to a browser for the final function check of our Auto Scaling Group and Load balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_1ysw18jxbOQUVu7ypZgA.png" /></figure><p>If I refresh the same page, our load balancer should switch to our alternate AZ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fLyDZR4gUsDTEtXHmBvA_Q.png" /></figure><h3>STEP 3: App-Tier Launch Templates &amp; AutoScaling Group</h3><p>Since I did not have any code to run a true application for this tier, I repeated the steps for the web tier but used the private subnets for the auto-scaling group. I created a new security group titled <strong>APP_SG </strong>that only allows traffic from the web tier’s security group <strong>WEB_SG </strong>as the <strong>source </strong>and<strong> </strong>SSH access to admins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uEmWNyuNMm1IMZ13a3W6Mw.png" /></figure><p>Instead of creating an entirely new launch template, I modified the WEB_LT with the configuration required for this layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*4IUS9IePD8jZ45wt3no73A.png" /></figure><p>Upon successful deployment, SSH into your Web_Tier_Instance and use the ping command on both of your App_Tier_instance to test connectivity across the board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*FOcT5UEuZGpVLrm1ayi-1Q.png" /></figure><h3>STEP 4: Database Tier</h3><p>Search for “RDS<strong>”</strong> in the AWS Management Console and choose Create database. We will use the standard instead of easy create, MySQL will be the engine option, and the free tier will be the template type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*cP-tvuCEGAVW1C2usB5vQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*IBHv6DjFzPaWoDSqHUOoLw.png" /></figure><p>Provide a name for the DB instance identifier and set your admin credentials. The instance type will be burstable class db.t3.micro</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*akYzaa15RCb9FldHGf5Y1g.png" /></figure><p>Choose “Don’t connect to an EC2 compute resource” This is not required since our data can only be accessed through the application tier. Select our current VPC, and we will create a subnet group. Ensure there is no public access to the database. Create a new Security Group that will allow traffic on port 3306 from the Application tier. Check your configurations and create your database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*3XPoXJ5MnC52ydVLmZUmkg.png" /></figure><p><em>Note: We did not enable “Multi-AZ deployment” of an “RDS</em><strong><em>”</em></strong><em> instance,however, you can always do this later by selecting a running RDS instance and clicking “Modify” &gt; “Enable Multi-AZ deployment.”</em></p><p>It will take a few minutes to create our database in the meantime, let&#39;s navigate to Security groups to modify our DB_SG to only allow traffic from APP_SG over port 3306.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dqte5iDB3WKaXeo9eJwltg.png" /></figure><p>The last step will be to check our database and validate our subnet associations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*Dv9R48du2aGT_iGObjrqlA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*HHNpnZln3pZ-mnyEFQ6z4Q.png" /></figure><p>The main focus of designing this architecture was ensuring there was no single point of failure within the design. Fault Tolerance refers to a system’s capacity to continue functioning even if some components fail -translation, zero downtime. We achieved this by using AWS Auto Scaling Groups to scale up compute resources (EC2 instances) as demanded by load, thereby safeguarding the machines from failures. Our Elastic Load Balancers can detect unhealthy instances within its pool of Amazon EC2 instances and automatically reroutes traffic to healthy instances. I used to get these two mixed up since a fault-tolerant system is considered highly available. The distinction comes in the form of redundancy. Simply put, high availability allows room for failure with a quick recovery, while fault-tolerant systems offer zero downtime at great cost.</p><p>The caveat for implementing a fault-tolerant system is its cost, as companies have to shoulder the capital and operating expenses for running its required numerous resources. I hope you found this tutorial to be useful. Please feel free to connect with me on <a href="https://www.linkedin.com/in/ray-sylverne/">Linkedin</a></p><p>I lied there is one more step. Make sure to tear down all the resources you deployed, so you don’t get charged for a lab environment. The resources deployed were:</p><ul><li>2 Auto Scaling Groups<br>-2 Launch Templates</li><li>2 Application Load Balancers<br>-2 Target Groups</li><li>2 Nat Gateways</li><li>VPC<br>-Internet Gateway<br>-2 Public Subnets<br>-4 Private Subnets<br>-Route Tables</li><li>Relation Database</li></ul><h4>Are you looking to scale awareness for your software startup? Check out <a href="https://circuit.ooo/?utm=publication-post-cta">Circuit</a>.</h4><p>We offer free expert advice and bespoke solutions to help you build awareness and adoption for your tech product or service.</p><h4>More content at <a href="https://plainenglish.io/">PlainEnglish.io</a>.</h4><p>Sign up for our <a href="http://newsletter.plainenglish.io/"><strong>free weekly newsletter</strong></a>. Follow us on <a href="https://twitter.com/inPlainEngHQ"><strong>Twitter</strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong>, and</strong> <a href="https://discord.gg/GtDtUAvyhW"><strong>Discord</strong></a><strong>.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cdb3064b2de" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/create-a-scalable-resilient-fault-tolerant-3-tier-architecture-9cdb3064b2de">Create a Scalable, Resilient &amp; Fault Tolerant 3-Tier Architecture</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attach An IAM Role To EC2 Instance To Access DynamoDB]]></title>
            <link>https://medium.com/@RaySylverne/attach-an-iam-role-to-ec2-instance-to-access-dynamodb-2d6706ebeb91?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d6706ebeb91</guid>
            <category><![CDATA[iam-roles]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[aws-cli]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Sat, 26 Nov 2022 21:51:35 GMT</pubDate>
            <atom:updated>2022-11-27T05:52:16.869Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*QrT8Wzjd-mCDASTPZJT-dg.jpeg" /><figcaption>Image by: Revathijoshi</figcaption></figure><h4>MISSION</h4><ol><li>Create a DynamoDB table for something of your choosing <br>(e.g. movies, food, games)</li><li>Add 10 or more items to the table</li><li>Create a t.2micro Ec2 instance via AWS CLI</li><li>Using an IAM role and the principle of least privilege, grant the EC2 instance read access to DynamoDB.</li><li>Use the AWS CLI in the EC2 instance to scan the DynamoDB table</li><li>Use the AWS CLI in the EC2 instance to validate you cannot write an item to the DynamoDB table</li></ol><h4>ADMIN &amp; LOGISTICS</h4><ul><li>AWS DynamoDB Fundamentals</li><li>AWS S3 Fundamentals</li><li>AWS CLI Fundamentals</li><li>Utilize Reference Section for AWS Documentation Assitance</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*71indesxYa5rDiYbe3qNjg.png" /><figcaption>Image by <a href="https://pixabay.com/users/jorono-1966666/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3579691">jorono</a> from <a href="https://pixabay.com//?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3579691">Pixabay</a></figcaption></figure><h4>EXECUTION</h4><p>While trying to decide what theme to create my table around, I came across <a href="https://champsorchumps.us/records/best-nfl-regular-season-records#tab-win-percentage">ChampsOrChumps.com</a>, which is home to some interesting stats about sports teams and their respective cities. For instance, they’ve kept track of NFL teams with the best regular season records by winning percentage and then tell you whether they won the super bowl or not that year. My chosen theme represents my passion as a die-hard Miami Dolphins fan. Even though we’ve had it rough the past couple of years, I’m clinging to our glory days. The Dolphins are the only team in NFL history to finish an entire season undefeated; their 1972 season ended without a loss and culminated in a victory in Super Bowl VII. Ok, now that we know why I chose this table, let’s return to our lab.</p><p>The table contains fifty items with four attributes per item ( Team, Record, Result, and Year). Manually adding each item and subsequent attributes into DynamodDB is feasible but not an ideal use of time. I will take advantage of a recently released AWS feature (August 2022) that <strong>imports data</strong> <strong>from Amazon S3 </strong>into a new DynamoDB table.</p><p>Before this feature was released, you had limited options for bulk importing data from S3 into DynamoDB. A popular workaround involved writing python code into a Lambda function, and like most ad-hoc fixes, your results varied. Bulk importing data can also require a custom data loader, which takes resources to build and operate. DynamoDB import from S3 helps you to bulk import terabytes of data from Amazon S3 into a new DynamoDB table with no code or servers required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*y2yY2lY2ClnJ9qsvcdhyMA.png" /></figure><h3>STEP 1: IMPORT DATA &amp; CREATE TABLE</h3><p>Begin by signing in to the AWS Management Console and opening DynamoDB at <a href="https://console.aws.amazon.com/dynamodb/">https://console.aws.amazon.com/dynamodb/</a>. In the console&#39;s navigation pane on the left side, choose Import from S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*pIIMn5D5eg_44ZyoNTUFTA.png" /></figure><p>On the page that appears, select Import from S3 again, and you will be brought to the request import wizard. If the bucket is owned by your account, you can find it by using the Browse S3 button. This is by far the simplest option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IPBhtsqKwTKeuL22HHiSRA.png" /></figure><p>After selecting the Browse S3 button, you can import an entire bucket or an individual object within that bucket. Before starting this lab, I downloaded the data from <a href="https://champsorchumps.us/records/best-nfl-regular-season-records#tab-win-percentage">ChampsOrChumps.com</a> and converted it into a CSV file I uploaded to S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*iYMXzZzCOVqneqpqAVVT6A.png" /></figure><p>Alternatively, you can enter the URL of the bucket in the s3://bucket/prefix format. This is a great option if you are importing data from a different AWS account than the one you’re currently logged into.</p><p>Next, you must specify if you are the S3 bucket owner. If the source bucket is owned by a different account, select <strong>A different AWS account</strong>. You will need to provide the account ID of the bucket owner. Select the appropriate Import file format. The options are <strong>DynamoDB JSON, Amazon Ion, </strong>or<strong> CSV</strong>. Choosing the wrong format will cause the import process to fail. If you select CSV, you will have two additional options: CSV header and delimiter character.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ee1WwKLNQtnYUQTY3cp1pA.png" /></figure><p>On the next screen, you will decide the parameters that will be associated with the new table that will be created to store your data. As you can see below, I’ve named my table and set the partition and sort key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZcOqPKDLmouMQdqC9I_Og.png" /></figure><p>We had to use a sort key because some teams appear on this list more than once. When a partition key and sort key are used together, they are referred to as a <em>composite primary key. </em>Multiple items can have the same partition key value in a table with a partition key and a sort key. However, those items must have different sort key values. 📝 Note: Primary Key and Sort Key must match the attributes in your file, or the import will fail. The attributes are case-sensitive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-ZpVbfySIakHNFhdZv2lw.png" /></figure><p>Select Next to review your import options, then click Import to begin the import task. Your new table is listed in the “Tables” with the status “Creating.” At this time, the table is not accessible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*nRcoHITrXrzRqb49hrpQvA.png" /></figure><p>Our data was successfully imported from S3, and a DynamoDB table has been created for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hdjZYCfVRvaGvWEV6QL1tg.png" /></figure><h3><strong>STEP 2: CREATE IAM ROLE WITH READ-ONLY ACCESS</strong></h3><p>The IAM service supports only one type of resource-based policy called a role <em>trust policy</em>, which is attached to an IAM role. Trust policies define which principal entities can assume the role. I am using Visual Studio Code to create my .json file. A template can be seen below.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>      {<br>          &quot;Sid&quot;: &quot;&quot;,<br>          &quot;Effect&quot;: &quot;Allow&quot;,<br>          &quot;Principal&quot;: {<br>              &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;<br>          },<br>          &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>      }<br>  ]</pre><p>The AWS CLI command to create the role and attach the trust policy</p><pre>aws iam create-role --role-name &lt;Name_Your_Role&gt; --assume-role-policy-document file://&lt;filelocation.json&gt;</pre><p>Attach the permissions policy to your role. Initially, I wanted to use an AWS-managed policy for my newly created role. The only requirement would be procuring the ARN for the AWS-managed AmazonDynamoDBReadOnlyAccess policy. However, upon reviewing the policy, I noticed that it grants access to other resources that our mission does not call for. I will need to create another .json file with permissions that meet our requirements while adhering to the principle of least privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqogbLqnLArI0EdkTU71rw.png" /></figure><p>The following permissions policy grants permissions for the GetItem, BatchGetItem, Scan, Query, and ConditionCheckItem DynamoDB actions only, and as a result, set read-only access on the BestNflRegularSeasonRecord table. You will need to paste your table ARN in the resource section of your policy to specify which table you&#39;re granting access to.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;ReadOnlyAPIActionsOnBooks&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;dynamodb:GetItem&quot;,<br>                &quot;dynamodb:BatchGetItem&quot;,<br>                &quot;dynamodb:Scan&quot;,<br>                &quot;dynamodb:Query&quot;,<br>                &quot;dynamodb:ConditionCheckItem&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;arn:aws:dynamodb:us-west-2:123456789012:table/BestNflRegularSeasonRecord&quot;<br>        }<br>    ]<br>}</pre><p>The command below embeds the inline policy to the role to specify what it can do.</p><pre>$ aws iam put-role-policy --role-name Test-Role-for-EC2 --policy-name Permissions-Policy-For-Ec2 --policy-document file://C:\policies\permissionspolicyforec2.json</pre><p>Create the instance profile required by EC2 to contain the role. You will need to provide a unique name for your instance profile.</p><pre>$ aws iam create-instance-profile --instance-profile-name &lt;TestEc2Profile&gt;</pre><p>Lastly, add the role to the instance profile</p><pre>$ aws iam add-role-to-instance-profile --instance-profile-name EC2-ListBucket-S3 --role-name Test-Role-for-EC2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Yfo5FR_X72OjKDg1C3XclA.png" /></figure><h3><strong>STEP 3: CREATE EC2 INSTANCE</strong></h3><p>Run the below command to create your EC2 instance. You will need to provide a value next to every parameter except for associate --associate-public-address</p><pre>aws ec2 run-instances \<br>    --image-id ami-0b0dcb5067f052a63 \<br>    --instance-type t2.micro \<br>    --subnet-id subnet-01b370d32254f5d0b \<br>    --security-group-ids sg-025ec04872b1c4e46 \<br>    --associate-public-ip-address \<br>    --key-name cli-dev-proj \<br>    --tag-specifications &quot;ResourceType=instance,Tags=[{Key=Name,Value=EC2-Wk8}]&quot; <br>    --iam-instance-profile &quot;Name&quot;=&quot;TestEc2Profile&quot;</pre><p>Upon successfully creating your instance, you will need to obtain your public IP address to SSH into the system. You can obtain this by running the following command. Don’t forget to add your instance profile to your EC2 instance.</p><pre>aws ec2 describe-instances \<br>--query &quot;Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key==&#39;Name&#39;]|[0].Value,Status:State.Name}&quot; --output table</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*qCz04zMoLpulQXCVC4HK6w.png" /></figure><h3>STEP 4: QUALITY ASSURANCE CHECK</h3><p>Now it&#39;s time to see if everything functions as expected or do we need to go back to the drawing board. Use the AWS CLI in the EC2 instance to scan the DynamoDB table</p><p>The following AWS CLI example reads an item from the BestNflRegularSeasonRecord table. You can do this through the DynamoDB API or PartiQL, a SQL-compatible query language for DynamoDB.</p><pre># DynamoDB API<br>aws dynamodb query \<br>    --table-name BestNflRegularSeasonRecord \<br>    --key-condition-expression &quot;Team = :name&quot; \<br>    --expression-attribute-values  &#39;{&quot;:name&quot;:{&quot;S&quot;:&quot;Miami Dolphins&quot;}}&#39; \<br>    --region us-east-1</pre><p>The output from the command shows that the 70s and 80s were the Miami Dolphins&#39; glory years, and I wasn’t even born yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*RiDa4TtslXhT3mpjHAHmmA.png" /></figure><p>The final step is to make sure our role cannot write</p><pre>aws dynamodb put-item \<br>    --table-name BestNflRegularSeasonRecord  --region us-east-1 \<br>    --item \<br>        &#39;{&quot;Team&quot;: {&quot;S&quot;: &quot;San Diego Chargers&quot;}, &quot;Year&quot;: {&quot;N&quot;: &quot;2006&quot;}, &quot;Record&quot;: {&quot;S&quot;: &quot;14-0&quot;}, &quot;Result&quot;: {&quot;S&quot;: &quot;Lost SB&quot;}}&#39;</pre><p>The portion highlighted in yellow confirms that our EC2 instance cannot write in the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*MK8qg1ZYUdrDRJa0szY7-A.png" /></figure><h3>TOUCHDOWN</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*BdB1DUC1j0DO_D98SAYxwA.png" /></figure><p>I had to reference many different resources to figure out the steps and develop the syntax needed for the different phases within this one lab. I’m posting the references below to help anyone working on a similar problem. The references are in a similar order to the steps of the lab.</p><h3>References &amp; Resources:</h3><ol><li><a href="https://aws.amazon.com/blogs/database/amazon-dynamodb-can-now-import-amazon-s3-data-into-a-new-table/">Import Amazon S3 data</a> into Amazon DynamoDB</li><li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CheatSheet.html">Cheat sheet</a> for DynamoDB</li><li>IAM policy to grant <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-only-permissions-on-table-items.html">read-only permissions</a> on items in a DynamoDB table</li><li><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html">Creating a role</a> for a service (AWS CLI)</li><li><a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html#examples">Create an EC2 </a>Instance via AWS CLI</li><li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/getting-started-step-5.html">Query data</a> in a table</li><li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/getting-started-step-2.html">Write data</a> in a table</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d6706ebeb91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto Scaling Group of EC2 Instances Running Apache Behind an Application Load Balancer]]></title>
            <link>https://aws.plainenglish.io/auto-scaling-group-of-ec2-instances-running-apache-behind-an-application-load-balancer-9a2a92248917?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a2a92248917</guid>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[auto-scaling-groups]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Mon, 21 Nov 2022 19:27:47 GMT</pubDate>
            <atom:updated>2022-11-22T03:57:53.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*P8sY-JoxSaFFvzco3Tz8aQ.png" /></figure><h3>Situation</h3><p>Amazon Web Services has taken the business world by storm and completely redefined how businesses, from start-ups to long-standing organizations, design and operate their infrastructures underlying tech stack. Your organization is late on the uptick and would like you to design a development environment to give them better insight into cloud technology. They’ve heard about the benefits ranging from increased speed and agility to being able to go global in minutes. And we can’t forget the cost savings 💰of not investing heavily in data centers and servers before you know how many you will need and how you will use them. It makes too much business sense not to come over to the Cloud side.</p><h3>Mission</h3><ol><li>Create a diagram of your AWS architecture using AWS Standards</li><li>Create a VPC with CIDR 10.10.0.0/16</li><li>Create three public subnets within that VPC</li><li>Create an autoscaling group using t2.micro instances. All instances should have Apache installed on each instance with the ability to check any random IP address and be able to produce a test page.</li><li>Create an Application Load Balancer to distribute traffic to the autoscaling group.</li><li>Perform a Quality Assurance test of your configuration</li></ol><p><strong>ADVANCED</strong></p><ol><li>Add a target policy for the ASG to scale after CPU utilization exceeds 50%.</li><li>Install and run a stress tool to push your instance above 50% to see if your scaling policy works.</li></ol><h3>ADMIN &amp; LOGISTICS</h3><p>To follow along, you’ll require the following:</p><p>🔲 AWS Account w/admin access<br>🔲 Basic understanding of Networking Fundamentals<br>🔲 Basic understanding of Linux Command Line Interface</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F20519545&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fthis-is-where-the-fun-begins-star-wars-fun-begins-this-is-where-this-is-gif-20519545&amp;image=https%3A%2F%2Fmedia.tenor.com%2F8MIIlktrDsUAAAAC%2Fthis-is-where-the-fun-begins-star-wars.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d7abf0a2245f1891cd449d581ae2974/href">https://medium.com/media/8d7abf0a2245f1891cd449d581ae2974/href</a></iframe><h3>EXECUTION</h3><p>We’ve all heard the saying, “If you fail to plan, you’re planning to fail.” So right out of the gate, the first thing you’ll want to do when embarking on a project like this is to design your architecture. Architecture diagrams are a great way to communicate your design, deployment, and topology. AWS provides some amazing tools to do just that. This <a href="https://aws.amazon.com/architecture/icons/"><strong>link</strong></a> will provide you with a slew of AWS-approved software to create your design. I chose <a href="https://www.lucidchart.com/pages/"><strong>Lucidcharts</strong></a> to create the diagram below, but there are many alternatives. You can use PowerPoint if you’re more comfortable with that platform. Now that we have a design to reference, let&#39;s get to the building. GadgetTools has a great video on his <a href="https://www.youtube.com/watch?v=tSqEljKKiU0"><strong>YouTube</strong></a> channel that breaks down the steps to create a diagram like this one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aD0KBoClW81ve3eaWQ341g.png" /></figure><h4>CREATE VPC</h4><p>From within your AWS Console, type VPC in the search bar and select create VPC option on the following page. A VPC is an isolated portion of the AWS Cloud that you can think of as your personal cloud data center. Within it, you can deploy AWS resources, such as Amazon EC2 instances, Load Balancers, Auto Scaling Groups, and much more. You must specify an IPv4 address range when you create a VPC. Specify the IPv4 address range as a Classless Inter-Domain Routing (CIDR) block; for example, 10.0.0.0/16. You cannot specify an IPv4 CIDR block larger than /16. Optionally, you can also associate an IPv6 CIDR block with the VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NtmalOnNxykOMnGD_DvELw.png" /></figure><p>Interestingly enough, AWS seems to have recently updated the VPC wizard. Previously, you’d have to create the VPC, subnet, and internet gateway on separate tabs. Now, all that can now be done on one screen. Another change I noticed is the interactive diagram to the right of the screen that changes as you select different options on the left. Essentially providing a <strong>preview</strong> of what your architecture will look like before deploying. The <strong>name tag auto-generation</strong> feature allows you to enter a value for the VPC name tag. This value will auto-generate prefix name tags for all resources within your VPC. Before this, you’d have to remember to manually name each resource with the same naming sequence as you subsequently created them on different screens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*OG-__zuOROnYNWiJht7gSA.png" /></figure><p>I want to take your attention to the far right section of the <strong>IPv4 CIDR </strong>field. AWS will calculate the total number of available IPs based on the CIDR you choose. This instant feedback lets you quickly determine if you have the right CIDR block or will need to adjust. As you can see above a /24 CIDR would provide 256 IPs that can be associated with hosts within our network.</p><h4>SUBNETS</h4><p>Our mission called for three public subnets will be spread across three availability zones with /24 CIDRs. This new process has logic that automates the creation of public route tables and an Internet Gateway (IGW) if public subnets are selected. In the image below, note that IGW is removed if you only select private subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKSYmJuOEPcmcuaJQWN0wQ.png" /><figcaption>Private Subnets without No IGW</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JR_9Cm0zv0UlfV4jIq9vaA.png" /><figcaption>Public Subnets w/IGW</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*S9p8t1TzPyeXpr6eHLg_Kw.png" /></figure><p>Since all of our subnets are public, there is no need for a NAT Gateway or VPC endpoint to be selected. A NAT gateway is a Network Address Translation (NAT) service. NAT gateways enable resources in private subnets to reach the internet. On the flip side, external resources cannot initiate a connection with the resources in the private subnets. Note that if you create a NAT gateway in your VPC, you are charged for each hour that your NAT gateway is provisioned and available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*0FuJoD9BMTggxjS9IJ3WLw.png" /></figure><p>The DNS hostnames attribute defines whether instances launched in the VPC receive public DNS hostnames that correspond to their public IP addresses. With that in place, select create VPC, and AWS will begin to provision your resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*Gztd8ozIrblclNFWLkJlxg.png" /></figure><p>I do not see the option to enable auto-assign IPv4 addresses within the workflow. The auto-assign IP settings determine whether a network interface created in this subnet is automatically assigned a public IPv4 address. This includes the primary network interface (eth0) created for an instance when you launch an instance in that subnet. You will want to navigate to the subnet setting and check this off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*9HKWCRYeDoIiBAdUmlnFhg.png" /></figure><p>The route table created for us has two paths based on our preferences. Everything within the /16 CIDR block will be routed locally by the VPC router, and everything that&#39;s not within that VPC CIDR block will go out to the internet via route 0.0.0.0/0. which is associated with Internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*deXiE8j8fuSRgrEJO9jf4g.png" /></figure><h4>SECURITY GROUP</h4><p>The path to creating your VPC can be seen below in red. Underneath that, there are fields to name and describe your SG. Make sure to select the correct VPC as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*C6fyBh0NBkzLK3C6oA94vQ.png" /></figure><p>We’ve created our route table to allow internet traffic to flow in and out of our subnets via the IGW however, no one will be able to reach our apache web servers if an SG is not attached to our EC2 instances. Security groups act as a firewall at the instance level. Adding an HTTP inbound rule on port 80 will allow Internet traffic to reach your instance. You will also add an inbound rule for SSH traffic (port 22), or you won’t be able to connect remotely to run commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*NizJA6QodLEcDQQ4dGGEAA.png" /></figure><h4>LAUNCH TEMPLATE</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*bIbFLB3SBeoIdBd1HSHlEA.png" /></figure><p>In the spirit of the holidays being around the corner, you can think of a launch template as a gingerbread cookie cutter. Sure, you could make the cut-outs by hand, but you could never guarantee that each cookie would be identical. However, using a cookie cutter would provide that consistency. In the same way, your launch template ensures that the configuration of each instance is consistent and free of human error. Begin by providing a distinguishable name and description for your template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*6pEpL5t-_DvqVVR4c_K49A.png" /></figure><p>Selecting an Amazon Machine Image is required when creating a launch template for an Auto Scaling Group. Our parameters will be Linux AMI with the t2.micro instance type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*LXm0kHqsuFv_ZsTEl0AoMQ.png" /></figure><p>After selecting our instance type, you’ll want to attach the Security group protect_7 that we created earlier. Navigate to the <strong>Advance details </strong>section and expand that option to reveal the <strong>user data </strong>field. This field allows you to provide commands or a script to run when you launch your instance. We will pass a bash script that installs apache on every instance this template launches. The script will also allow us to test our load balancer by displaying our availability zone after every refresh of our landing page. Once complete, select create launch template.</p><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd<br>EC2AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) <br>echo &#39;&lt;center&gt;&lt;h1&gt;This Amazon EC2 instance is located in Availability Zone: AZID &lt;/h1&gt;&lt;/center&gt;&#39; &gt; /var/www/html/index.txt<br>sed &quot;s/AZID/$EC2AZ/&quot; /var/www/html/index.txt &gt; /var/www/html/index.html</pre><h4><strong>AUTO SCALING GROUP</strong></h4><p>This Auto Scaling Group creation is broken down into seven steps. The first step is to name your ASG and select the launch template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*JkzlbVPB0z2UdU_jw39X7g.png" /></figure><h4>APPLICATION LOAD BALANCER</h4><p>The third step within the Auto Scaling Group wizard allows us to attach an existing load balancer or create a new one. We will create a new one. You will select an Application load balancer to distribute traffic among our three Apache webservers. The default scheme is internal make sure to change to internet facing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*hwjf-Qcvz5Y_2jl-1264qg.png" /></figure><p>Your new load balancer will be created using the same VPC, Availability Zones, and subnet selections as your Auto Scaling group. You will also want to create a new target group names “tg-project-7”. Your target group will listen on port 80 for traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*8uftR2s-LkEHGcXK8_gSbQ.png" /></figure><p>Our mission called for a scale in and out capacity with a minimum of 2 instances and a maximum of 5 at any given time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*NQZ19rmSRff0rnhhu3_yiQ.png" /></figure><p>Scaling policies are what truly makes ASG an invaluable resource. To create a target tracking scaling policy, you specify an Amazon CloudWatch metric and a target value representing your application&#39;s ideal utilization or throughput level. It works similarly to how your thermostat maintains your home&#39;s temperature — you select a temperature, and the thermostat adjusts up or down automatically. In our scenario, should the CPU utilization surpass 50%, we want ASG to launch an instance in our third availability zone to stay within the defined metric.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*49FOBC-IbEm--ZUABLLPoQ.png" /></figure><h4>QUALITY ASSURANCE CHECK</h4><p>Now that our ASG has been launched let&#39;s test the functionality of our configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsUwFfbYxcgqHcVkLYTw2g.png" /></figure><p>We have two instances that have been created per our desired minimum. Both are in the project_7 VPC, and each has been distributed across subnets us-east-1a &amp; us-east-1b. When creating our subnet, we selected auto-assign IPv4 address, which you can see has been provisioned. We’ll need to copy and paste our Application Load Balancers DNS name into our browser to test that our ALB balances traffic between subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*YFnukmOnrbSFKTqKhaBj7g.png" /></figure><p>Press play to observe that with each refresh, the ALB switches between us-east-1a &amp; us-east-1b.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQGXfGlCem-0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQGXfGlCem-0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQGXfGlCem-0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad6259d78dfc890d2ad457c7e58fd7e1/href">https://medium.com/media/ad6259d78dfc890d2ad457c7e58fd7e1/href</a></iframe><h3>That was our expected outcome!!!</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F24669440&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcongratulations-gif-24669440&amp;image=https%3A%2F%2Fmedia.tenor.com%2FmU6C8c8tmikAAAAC%2Fcongratulations.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/85f1721157bff172dbef5338a9c02e94/href">https://medium.com/media/85f1721157bff172dbef5338a9c02e94/href</a></iframe><h3>GENERATE CPU LOAD ABOVE 50%</h3><p>Pat yourself on the back now, let&#39;s install a stress test tool for the advanced portion of our mission. We aim to push CPU utilization beyond 50% to force the Auto Scaling Group to launch the third instance. We’ll need to SSH into our instance to install our stress test tool. Run the following commands</p><pre>sudo amazon-linux-extras install epel -y<br>sudo yum install stress -y<br>Complete!</pre><p>The cool thing about Linux is that if you’ve never run a command on a tool before, you can always get help by running $ stress --help</p><pre>[ec2-user@ip-10-0-2-214 ~]$ stress --help<br>`stress&#39; imposes certain types of compute stress on your system<br><br>Usage: stress [OPTION [ARG]] ...<br> -?, --help         show this help statement<br>     --version      show version statement<br> -v, --verbose      be verbose<br> -q, --quiet        be quiet<br> -n, --dry-run      show what would have been done<br> -t, --timeout N    timeout after N seconds<br>     --backoff N    wait factor of N microseconds before work starts<br> -c, --cpu N        spawn N workers spinning on sqrt()<br> -i, --io N         spawn N workers spinning on sync()<br> -m, --vm N         spawn N workers spinning on malloc()/free()<br>     --vm-bytes B   malloc B bytes per vm worker (default is 256MB)<br>     --vm-stride B  touch a byte every B bytes (default is 4096)<br>     --vm-hang N    sleep N secs before free (default none, 0 is inf)<br>     --vm-keep      redirty memory instead of freeing and reallocating<br> -d, --hdd N        spawn N workers spinning on write()/unlink()<br>     --hdd-bytes B  write B bytes per hdd worker (default is 1GB)<br><br>Example: stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s</pre><p>Using the output’s information, we can construct the following command. We’ll take advantage of the example provided with some slight modifications that will keep our test running for 180s or 3 minutes.</p><pre>stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 180s</pre><p>We can observe the outcome in the console by selecting the monitor tab on our instance. Due to our CPU utilization reaching 83.6%, the scaling policy has been triggered, which activates the deployment of a third instance in the us-east-1c subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*cRMjoRVDVOK7QmuFOxoMzQ.png" /></figure><h4>DEBRIEF</h4><p>Wow, that was exciting from beginning to end. In short, we created an ASG with a scaling policy to increase our instance count to a maximum of 5 should the CPU utilization exceed 50%. We’ve created a highly available and durable architecture that can withstand an outage or spike in traffic while also being cost-effective. On-demand computing allows you to scale out as needed to support your architecture and scale in as needed to save on costs related to idle resources during downtime.</p><h3>MISSION ACCOMPLISHED</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F21441837&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fstar-wars-poe-dameron-our-job-is-done-here-lets-go-home-our-job-here-is-done-gif-21441837&amp;image=https%3A%2F%2Fmedia.tenor.com%2FBlN4Ohn-fEkAAAAC%2Fstar-wars-poe-dameron.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac7d0ca7ff64ea8ed6ad328713413342/href">https://medium.com/media/ac7d0ca7ff64ea8ed6ad328713413342/href</a></iframe><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><em>. Interested in Growth Hacking? Check out </em><a href="https://circuit.ooo/"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a2a92248917" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/auto-scaling-group-of-ec2-instances-running-apache-behind-an-application-load-balancer-9a2a92248917">Auto Scaling Group of EC2 Instances Running Apache Behind an Application Load Balancer</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Push Local Bash Scripts To GitHub Repo]]></title>
            <link>https://medium.com/@RaySylverne/push-local-bash-scripts-to-github-repo-5ef1b16e8c98?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ef1b16e8c98</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 03:56:14 GMT</pubDate>
            <atom:updated>2022-11-14T03:56:14.426Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*jza9BaRazVcHAEfojmvv5Q.png" /></figure><h3>MISSION OBJECTIVES:</h3><ol><li>Create GitHub Repo titled BashScripts</li><li>Clone Repo</li><li>Move LUIT_Scripts Directory into Repo</li><li>Push Changes to Git</li></ol><h4>Prerequisites to following along:</h4><ul><li>Create a free GitHub Account <a href="https://github.com/"><em>https://github.com/</em></a></li><li>To install and Configure Git follow this <a href="https://medium.com/@RaySylverne/my-attempt-at-demystifying-git-ac912f28017f">link</a> for <br>instructions if new to Git</li></ul><h3><strong>STEP 1: CREATE A NEW REPOSITORY</strong></h3><p>Provide your repo with a unique name and brief description. As you can see, filling out the description field and adding a README file are optional. However, since the README file acts as the “front page” of your project, you’ll want to add a README file to a repository to communicate vital information about your project to potential contributors. “A README, along with a repository license, citation file, contribution guidelines, and a code of conduct, communicates expectations for your project and helps you manage contributions.” <a href="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes">-GitHub Docs</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*1qlI5Dm1CfOhrpf_-zlXog.png" /><figcaption><strong>Fig.1</strong></figcaption></figure><p>In our scenario, the changes we’re making will be adding our script to the upstream repo so it can be accessible to other developers on GitHub. If you refer to Fig.1, you’ll see that I made my repo public. Anyone with internet access and a GitHub account can download my repo. However, only those who have been added as collaborator access can push commits to the original file, also known as the origin. Here is the link for anyone interested in the scripts</p><p><a href="https://github.com/raysylverne/BashScripts">https://github.com/raysylverne/BashScript</a></p><h3><strong>STEP 2: CLONE REPO LOCALLY</strong></h3><p>From within your newly created repo, you want to clone the repository. Think of git clone as a Git command used to target an existing repository and create a clone or copy of the target repository. The workflow for git clone is usually a 3-step process :</p><ol><li>You start by identifying and cloning the upstream repository on GitHub that you want to work on locally.</li><li>Now that you have an exact copy locally, you can begin to make your desired changes to the file. You can apply single or multiple commits to the repository in this step. But the bottom line is everything happens on your local system.</li><li>Once the changes are done, the modifications can be pushed to your upstream repository.</li></ol><p>After opening the repo, you’ll want to select “code” and copy the path for the repo. Notice that I’m using the SSH option. This assumes you’ve already set up SSH keys between your device and GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*RkNTh9jgM_ZHp8g7WojvQQ.png" /></figure><p>Now head to your terminal, and run the following command to complete the cloning process.</p><pre>git clone &lt;your_SSH_URL_goes_here&gt;</pre><p>Now we have a copy of the BashScritps (empty) repo locally on our system. <br>This is because git clone is a combination of a few different commands. Here’s what happens when you clone a repo.</p><ol><li>git init (create the local repository)</li><li>git remote add (add the URL to that repository)</li><li>git fetch (fetch all branches from that URL to your local repository)</li><li>git checkout (create all the files of the main branch in your working tree)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2558Kc61g1ClEeQE9mY5WA.png" /></figure><p>Now, all that is left is the use the mv command to add the apache.sh file to the repo. Then run git commit -am &quot;DESCRIBE_WHAT_THE_COMMIT_IS_CHANGING&quot;<br>The -a flag in my command includes all currently changed files in this commit. Keep in mind, however, that untracked (new) files are not included. The -m flag sets the commit’s message. Provide a concise description that helps your teammates (or yourself) understand what happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUaq3-XvXMlX5a-h3GgBtg.png" /></figure><h3>STEP 3: GIT PUSH TO REMOTE</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lHD-m81EIpdvVw_HB6AAQ.png" /></figure><p>If I head back to GitHub, you’ll see the apache.s file is now in my upstream repo. Now I can clone this repo onto another system, using this same script to launch a webserver on EC2. No graphic user interface (GUI) it will all be provisioned through AWS CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1bJxn70NNkzHsFP6ms02Fg.png" /></figure><h3>DEBRIEF:</h3><ol><li>We created a GitHub Repo titled BashScripts</li><li>Cloned the Repo onto our local system</li><li>Added our apache.sh file to the BashScripts repo</li><li>Push Changes to Git</li><li>Now anyone with internet access and a GitHub account can download my repo.</li><li><a href="https://github.com/raysylverne/BashScripts">https://github.com/raysylverne/BashScript</a></li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FoCO02sFyanXFF68LHW%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FoCO02sFyanXFF68LHW%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FoCO02sFyanXFF68LHW%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/53fddfffec0777505e397ff5a5228dfa/href">https://medium.com/media/53fddfffec0777505e397ff5a5228dfa/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ef1b16e8c98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Provision Nginx On EC2 with AWS CLI]]></title>
            <link>https://medium.com/@RaySylverne/provision-nginx-on-ec2-with-aws-cli-2b483cdbf2dc?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b483cdbf2dc</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[aws-cli]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 03:47:33 GMT</pubDate>
            <atom:updated>2022-11-14T03:52:47.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qsj_G3XhhET13KPpaYGplQ.jpeg" /></figure><h3>Situation Report (SITREP)</h3><p>Using Only AWS CLI execute the following directives:</p><ol><li>Configure AWS CLI</li><li>Create Security Group <br>2.1 Security Group Rules<br>2.2 Key Pair</li><li>Bootstrap Script that updates all packages installs NGINX and starts the service.</li><li>Launch a t2.micro EC2 Instance using all the Resources you just built</li><li>Verify that the instance has the NGINX webserver downloaded and installed through the public IP.</li></ol><h3>PREREQUISITES:</h3><ul><li>AWS IAM User Account with Admin Level Access</li><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">AWS CLI has been installed on your system</a></li><li>Familiarity with Navigating your terminal</li><li>Experience with Bash Scripting</li></ul><h3>Let’s Get This Party Started!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BF7Gkt57_sFM2VdtPlEckg.jpeg" /></figure><p><strong>STEP 1: </strong><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"><strong>CONFIGURE AWS CLI</strong></a></p><p>I assume you’ve utilized the AWS documentation provided in the prerequisites section to install AWS CLI locally on your device. With that out of the way, let’s begin by configuring your basic settings. The command line is the fastest way to set up your AWS CLI configuration so you will run aws configure in your terminal to get things going. When you enter this command, the AWS CLI prompts you for four pieces of information:</p><ul><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds">Access key ID</a></li><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds">Secret access key</a></li><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-region">AWS Region</a></li><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-format">Output format</a></li></ul><p>I’ve provided links to the documentation that describes where to locate the four pieces of information within the AWS console. Make sure to take the time to understand the function of each. If the command was executed successfully, your output should resemble <strong>Fig-1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YctHJWgw1AhRZBEytkLaQ.png" /><figcaption><strong>Fig-1</strong></figcaption></figure><p><a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/create-security-group.html"><strong>STEP 2: CREATE A SECURITY GROUP</strong></a></p><p>We’ll kick off the project by creating a security group within a VPC association. Within AWS, Security groups act as a virtual firewall at the instance level. The command syntax to create can be seen below.</p><pre>  $ aws ec2 create-security-group --group-name &lt;Name_SG&gt; --description &lt;&quot;Describe Your SG&quot;&gt; --vpc-id &lt;vpc-1a2b3c4d&gt;</pre><p>Output:</p><pre>{<br>    &quot;GroupId&quot;: &quot;sg-903004f8&quot;<br>}</pre><p>You could double-check by navigating to your console and observing the newly created SG with the parameters you set, i.e. group name, description, and VPC association.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SqFxyKFqZA_2F3DdeF-dlg.png" /></figure><h4>STEP 2.1: <a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html">Describe-Security-Group-Rules</a></h4><p>The security group rules we set will dictate what network traffic can enter or leave. We want to add ingress traffic on TCP ports 80 and 22. The syntax for these commands are:</p><pre>aws ec2 authorize-security-group-ingress --group-id &lt;Your_SG_GroupID&gt; <br>--protocol tcp --port 80 --cidr 0.0.0.0/0</pre><p><strong>Port 80</strong> is the port number assigned to the commonly used internet communication protocol, <strong>Hypertext Transfer Protocol (HTTP)</strong></p><pre>aws ec2 authorize-security-group-ingress --group-id &lt;Your_SG_GroupID&gt; <br>--protocol tcp --port 22 --cidr 0.0.0.0/0</pre><p><strong>Port 22 </strong>is used for <strong>Secure Shell (SSH) communication </strong>and allows remote administration. In general, traffic is encrypted using password authentication</p><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*opqgoeg4ZY9Yk1xBiIqDxA.png" /></figure><p><strong>STEP 2.2: </strong><a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/create-key-pair.html"><strong>Key Pair</strong></a></p><p>“A key pair, consisting of a public key and a private key, is a set of security credentials that you use to prove your identity when connecting to an Amazon EC2 instance. Amazon EC2 stores the public key on your instance, and you store the private key. For Linux instances, the private key allows you to securely SSH into your instance.” — <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">AWS Documentation</a></p><pre>cd &lt;To secure location you save your key pairs&gt;<br>aws ec2 create-key-pair --key-name &lt;Your_KeyPair_Name&gt; --output text &gt; <br>my-key-pair.pem</pre><p>If you plan to use an SSH client on a macOS or Linux computer to connect to your Linux instance, use the following command to set the permissions of your private key file so that only you can read it.</p><pre>chmod 400 key-pair-name.pem</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GUiUnpwmkQXHy7MNYJ-oQ.png" /></figure><p><strong>STEP 3: BOOTSTRAP SCRIPT</strong></p><p>Don’t let the peculiar name throw you for a loop. Bootstrapping in AWS simply means adding commands or scripts to AWS EC2’s instance User Data section that can be executed when the instance launches. It is a useful automation technique that simplifies configuration tasks. You can use any text editor to create the script I will be working with vim.</p><pre>vim  nginx_awscli.sh</pre><p>This bash script will update the repository and follow up with installing, enabling, and starting Nginx.</p><pre>#!/bin/bash<br><br># Update OS<br>sudo yum update -y<br><br># Install NGINX<br>sudo yum install nginx -y<br>sudo systemctl enable nginx<br>sudo systemctl start nginx </pre><p><strong>STEP 4: </strong><a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html#examples"><strong>LAUNCH THE EC2 INSTANCE</strong></a></p><p>The last phase will be to create your EC2 instance. I’ve provided a hyperlink to the AWS documentation on the possible options and use cases for these commands in the title of this section. The actual command can be viewed below.</p><pre>aws ec2 run-instances — image-id &lt;yourimageid&gt; — count 1 — instance-type <br>t2.micro — key-name &lt;yourkeyname&gt; — security-group-ids <br>&lt;yoursecuritygroupname&gt; — user-data &lt;file://your_script_file.sh&gt;</pre><p>Navigate to the AWS console to determine the success of the command. After you have successfully installed <strong>NGINX</strong> and confirmed that it is running, open a web browser and enter the IP address of your Linux server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*y69A5ZZJ-7_Kheu3yxdHSg.png" /></figure><p><strong>STEP 5: VERIFY THE WEBSERVER</strong></p><p>You should see the test page for <strong>NGINX,</strong> as shown in the images below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2n70sxCBjDeeE20aX84xFw.png" /></figure><p>If you just read or followed, I appreciate going on this journey with me. We got a lot done along the way. To recap, using only the AWS CLI, we created a security group with rules, key pairs, and a bootstrap script that launched an Nginx web server.</p><h3>BONUS ROUND: MAKE AN AMAZON MACHINE IMAGE</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*YTNY9aglznqtCEkgLcsueg.png" /></figure><p>Specifically, you will make an Amazon Machine Image from the instance you created earlier. Then launch the instance and verify you can reach your web server from the newly created EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*DOYFNfHyLhi1xeM0sFvzRA.png" /></figure><p>Add your options</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGodw4i8SqPkZ6qL3_SJSQ.png" /></figure><p>After it is created, it will appear in the <strong>AMIs</strong> view in AWS Explorer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fGniQVf7GxI3a9jqbQ9LtQ.png" /></figure><p><strong>To launch an instance from your AMI</strong></p><ol><li>Open the Amazon EC2 console at <a href="https://console.aws.amazon.com/ec2/">https://console.aws.amazon.com/ec2/</a>.</li><li>In the navigation pane, under <strong>Images</strong>, choose <strong>AMIs</strong>.</li><li>Set the filter to <strong>Owned by me</strong> and select your AMI.</li><li>Choose <strong>Launch instance from AMI</strong></li><li>Accept the default values or specify custom values in the launch instance wizard.</li></ol><p>Once launched, check your results in the console and a web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*0naNmUaSx83TuH12lod_fg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*g7HdqQLsk6ooXIkCDWWEjA.png" /></figure><h3>VICTORY DANCE</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FKGeUk1F8HWMEOXVTYc%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FKGeUk1F8HWMEOXVTYc%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FKGeUk1F8HWMEOXVTYc%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/77447a615de9e8684a979efaca1bd2b5/href">https://medium.com/media/77447a615de9e8684a979efaca1bd2b5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b483cdbf2dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Apache on an EC2 Instance with a Bash Script]]></title>
            <link>https://medium.com/@RaySylverne/install-apache-on-an-ec2-instance-with-a-bash-script-336542338af8?source=rss-322c6aa4d97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/336542338af8</guid>
            <category><![CDATA[securitygroup]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[apache]]></category>
            <dc:creator><![CDATA[Ray Sylverne]]></dc:creator>
            <pubDate>Mon, 07 Nov 2022 19:25:00 GMT</pubDate>
            <atom:updated>2022-11-07T19:25:00.228Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NACRSewkY79CW88qMtjVA.jpeg" /></figure><h3>(SITREP) Situation Report</h3><p>Your company wants to start shifting from using on-premises servers to using servers in the cloud. They’ve heard about the advantages of using cloud services and would like to see it for themselves. There is a requirement to launch a web server. However, rather than purchasing all the infrastructure in a data center, they ask you to create an EC2 instance in AWS to host their new website.</p><h4><strong>Mission Objectives:</strong></h4><ol><li>Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet of your Default VPC.</li><li>Create a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from your IP address.</li><li>SSH into your EC2 instance and install Apache with a custom webpage using a BASH script.</li></ol><h4>Prerequisites</h4><ol><li>An AWS account (free tier)</li><li>Access to a terminal</li><li>GitHub Account</li><li>Linux Scripting Understanding</li></ol><h3><strong>1. Launch Your Instance</strong></h3><p><strong>Sign up and sign in to an </strong><a href="https://aws.amazon.com/free/?trk=78b916d7-7c94-4cab-98d9-0ce5e648dd5f&amp;sc_channel=ps&amp;s_kwcid=AL!4422!3!432339156165!e!!g!!create%20aws%20account&amp;ef_id=EAIaIQobChMIvtz86KOb-wIVsotaBR0OQAw1EAAYASAAEgIgUPD_BwE:G:s&amp;s_kwcid=AL!4422!3!432339156165!e!!g!!create%20aws%20account&amp;all-free-tier.sort-by=item.additionalFields.SortRank&amp;all-free-tier.sort-order=asc&amp;awsf.Free%20Tier%20Types=*all&amp;awsf.Free%20Tier%20Categories=*all"><strong>AWS free tier</strong></a><strong> account</strong>. The AWS Free Tier allows customers to explore and try out AWS services free of charge up to specified limits for each service. If you’re on the fence and want to know more about the free tier offerings, navigate to <a href="https://aws.amazon.com/free/free-tier-faqs/">AWS Free Tier FAQs</a> to gain more insights into the limitations and use cases.</p><p>Upon logging into your system for the first time, you’ll be at the dashboard with several services. Over time the most frequently accessed services will be pinned to the top of your home page. But since we’re just starting out, we can search by typing EC2 into the search bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SYZ2Z9nLm8J4xbOD6X2Esg.png" /></figure><blockquote>Note: Always be aware of what region you are currently located in. Your region selection will affect latency, cost, compliance, and any regulations you have to adhere to.</blockquote><p><strong>Step 1: Launch and Configure your EC2 Instance </strong>by selecting the orange “Launch Instance” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SYX0cA3za4T-PC-MN9d7Qg.png" /></figure><p><strong>Step 2: Name EC2 Instance &amp; Choose Operating System</strong></p><p>On the surface, this seems like a simple step, but you want to ensure you give your instance and unique and identifiable name. Your organization may very well have a preset naming convention that you’re required to follow. It would not be hard for a system administrator to write a script that rejects the launch of an instance not following the company naming convention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*zMYIWWgJC34dkqAQteF-ag.png" /></figure><p><strong>Step 3: Create Key Pair:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*iBFjRuWflCraLXRy4-mr1w.png" /></figure><p>Once you name your new key pair, it will be downloaded to your personal computer as a .pem file. When prompted, store the private key in a secure and accessible location on your computer.<strong> You will need it later to connect to your instance</strong></p><p><strong>Step 4: Networking &amp; Security Groups (SG)</strong></p><p>“A virtual private cloud (VPC) is <strong>a virtual network dedicated to your AWS account</strong>. It is logically isolated from other virtual networks in the AWS Cloud. You can specify an IP address range for the VPC, add subnets, add gateways, and associate security groups. A subnet is a range of IP addresses in your VPC.” — <a href="https://docs.aws.amazon.com/vpc/latest/userguide/how-it-works.html">How Amazon VPC works</a></p><p>Your Security Group (SG) controls both inbound and outbound traffic at the instance level. SG rules only apply to the instances that have been associated with it. The EC2 launch wizard performs the association for us. However, if we created this instance via a script, the SG association would need to be specified in your code. Lastly, I want to point out that Security Groups are stateful and support allows rules only. Return traffic is automatically allowed, regardless of any other rules. Thus why we will only edit our inbound rules</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*vORawfLkaNvelM1jfgzEWw.png" /></figure><p>Our second objective was creating a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and inbound traffic on SSH from your IP address. In AWS, the SG acts as a firewall for your EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*EKDo2LJX_r3zU_w12Rbyzw.png" /></figure><p>After you’re satisfied with your settings, navigate to the EC2 dashboard, where you will find your newly provisioned instance with your security group already associated. Now we’re ready for the next phase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJOwnuw0UzR7HT2Um2S0yw.png" /></figure><h3>SSH &amp; Scripting</h3><p>Right-click on the running instance, select connect, then navigate to the SSH client tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*3BQ1-Scf22ju4ha7Fct0VA.png" /></figure><p>Earlier I mentioned storing your key pair in a secure and accessible location because we would need it later. The time of need has come. Navigate to where you saved the file using the cd command. Follow the instructions and run the commands from the SSH client in your terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8cNfgGypeCnAmoFCNDpC4g.png" /></figure><p>Now that we’re in our EC2 instance. Now let’s make our script. I’ll be using vim, but you can utilize nano if you prefer. Take note of the sanity check I added within the script to cause it to fail if not run with elevated privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*cUv-JCgUv79L289qsGtxwg.png" /></figure><p>Next, let’s grant it executable permissions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*W66Ko6mvwPB70L6_KbalUA.png" /></figure><p>Anyone who attempts to run the script as a standard user will see an output letting them know they need to “run as sudo or root.” This is due to the logic I added at the top of my script to exit with a status code of 1 if certain parameters aren’t met.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*N5vrU19OSNz77XrHihHDPg.png" /></figure><p>The script has been executed. Let&#39;s check our work before reporting the mission as being completed.</p><pre>systemctl status httpd<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*oTJPTYnJHFM1lmfrLgbdcA.png" /></figure><p>🫡Things are looking good on the server let&#39;s check the Landing page. To make sure the last piece of our script was run successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cePN7mof5C1XPQQcAZ5hUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*EzuhWkzfTFYBXjVtCuEwfw.png" /></figure><ol><li>We successfully launched an EC2 Amazon Linux in a public subnet of our Default VPC.</li><li>Created a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from your IP address.</li><li>SSH into our EC2 instance and installed Apache with a custom webpage using a BASH script.</li></ol><p>In my next article, I will create a repo in GitHub for all my BASH scripts, and this script will be the first file I add, commit and push to that repo. If you’re new to Git and GitHub, check out my last <a href="https://medium.com/@RaySylverne/my-attempt-at-demystifying-git-ac912f28017f">article</a> for a quick introduction.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=336542338af8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>