<?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 Vikram Gopinath on Medium]]></title>
        <description><![CDATA[Stories by Vikram Gopinath on Medium]]></description>
        <link>https://medium.com/@markiv247?source=rss-fd35de0d6202------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Hnes5dpN5bvZcBax</url>
            <title>Stories by Vikram Gopinath on Medium</title>
            <link>https://medium.com/@markiv247?source=rss-fd35de0d6202------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:52:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@markiv247/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[Automate deployment of an E-Commerce application on AWS using Terraform and Ansible]]></title>
            <link>https://medium.com/@markiv247/automate-deployment-of-an-e-commerce-application-on-aws-using-terraform-and-ansible-d89bf04c6d92?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89bf04c6d92</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[magento]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Fri, 02 Dec 2022 16:56:11 GMT</pubDate>
            <atom:updated>2022-12-02T16:56:11.125Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZXPk281bcPqvsWn7JrKXQ.png" /></figure><p>In another exercise let’s create and implement an e-Commerce MVP (Minimum Viable Product) on AWS in less than 2 hours and automate the process using <a href="https://www.terraform.io/">Terraform </a>and <a href="https://www.ansible.com/">Ansible </a>(Infrastructure as Code — IaC).</p><p>We can provision the infrastructure using Terraform and use Ansible to automate the configuration management process, software installation, and package management of the EC2 instance. We shall use <a href="https://business.adobe.com/products/magento/magento-commerce.html">Magento</a>, <a href="https://www.php.net/">PHP</a>, <a href="https://www.mysql.com/">MySQL</a>, and <a href="https://redis.io/">Redis </a>to complete this exercise.</p><h4>Magento</h4><p>Navigate to this <a href="https://marketplace.magento.com/">link </a>and create a free Magento account using the single sign-on process (you can use Google or Facebook or Apple).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0bie24oyunuhY6gb0hPucA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3tSlUd3JGbPOmUHmyunjw.png" /></figure><p>In order for Ansible to download and install Magento an access key would be required. Click on the arrow next to your name and select <em>My Profile</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJ06pS0bx_HACndQ6_qKrQ.png" /></figure><p>On the next page navigate to <em>Access Keys → Create a New Access Key</em>. Give a name to your key, in my case, I named the key <em>magentoKey</em>. Click <em>OK</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*eIynMorzUoYZjL7qjCZRjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3F8wkn74Kc2T5Vdzh_ZlnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*HfkW0a54I4fG6-rjrE8mcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZoO3D1FIxt0PUXvJBbbvyg.png" /></figure><p>Copy the public and private keys to be used later during this exercise.</p><h4>Terraform</h4><p>Navigate to the cloud shell in your AWS management console and enter the following commands to install terraform</p><pre>sudo yum install -y yum-utils<br>sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo<br>sudo yum -y install terraform</pre><p>Once installed create a folder and move into that folder using the following commands</p><pre>mkdir final_project<br>cd final_project</pre><p>Upload the terraform files or download the same from your public storage bucket.</p><p>Once we have the terraform files uploaded they should look something like the below.</p><ul><li>sample main.tf</li></ul><pre>variable &quot;vpc_id&quot; {<br>    default = &quot;vpc-0f26f1f6cbf57ccf8&quot;<br>}<br><br>variable &quot;key_name&quot; {<br>    default = &quot;sshkey1&quot;<br>}<br><br>resource &quot;aws_instance&quot; &quot;ecommerce1&quot; {<br>  ami           = &quot;ami-032930428bf1abbff&quot;<br>  instance_type = &quot;t3a.large&quot;<br>  key_name = var.key_name<br>  vpc_security_group_ids = [aws_security_group.allow_ssh_http.id]<br>  associate_public_ip_address = true<br><br>  tags = {<br>    Name = &quot;ecommerce1&quot;<br>    ambiente = &quot;bootcamp&quot;<br>  }<br>}<br><br>resource &quot;aws_security_group&quot; &quot;allow_ssh_http&quot; {<br>  name        = &quot;allow_ssh_http&quot;<br>  description = &quot;Allow SSH and HTTP traffic on EC2 instance&quot;<br>  vpc_id      = var.vpc_id<br><br>  ingress {<br>    description = &quot;SSH to EC2&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;HTTP to EC2&quot;<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    Name = &quot;allow_ssh_http&quot;<br>  }<br>}<br><br></pre><p>- update the vpc_id in the above file with the default vpc associated with your AWS account. Navigate to <em>vpc → Your VPCs → select the vpc and copy the VPC ID</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3dEdSdyMwze4n_h1QLSgWQ.png" /></figure><p>- update the key_name in the above file with the name of your ssh-key. In my case it was terraformKey. You should find your keys at<em> ec2 → Key Pairs</em>. In case you need to see the process of how to create a new key please refer to my post <a href="https://medium.com/@markiv247/deployment-of-a-set-of-ec2-instances-using-terraform-and-aws-systems-manager-configuration-with-8dee2d82bf20">here</a>.<br>- For the ingress SSH rule CIDR block we should not use the Anywhere CIDR block 0.0.0.0/0 as its best practice to use a known IP address. For the purposes of this exercise, I have it opened to any IP address.</p><p>The file should now look like this</p><pre>variable &quot;vpc_id&quot; {<br>    default = &quot;vpc-0a253d099eb43babb&quot;<br>}<br><br>variable &quot;key_name&quot; {<br>    default = &quot;terraformkey&quot;<br>}<br><br>resource &quot;aws_instance&quot; &quot;ecommerce1&quot; {<br>  ami           = &quot;ami-032930428bf1abbff&quot;<br>  instance_type = &quot;t3a.large&quot;<br>  key_name = var.key_name<br>  vpc_security_group_ids = [aws_security_group.allow_ssh_http.id]<br>  associate_public_ip_address = true<br><br>  tags = {<br>    Name = &quot;ecommerce1&quot;<br>    ambiente = &quot;bootcamp&quot;<br>  }<br>}<br><br>resource &quot;aws_security_group&quot; &quot;allow_ssh_http&quot; {<br>  name        = &quot;allow_ssh_http&quot;<br>  description = &quot;Allow SSH and HTTP traffic on EC2 instance&quot;<br>  vpc_id      = var.vpc_id<br><br>  ingress {<br>    description = &quot;SSH to EC2&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;HTTP to EC2&quot;<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    Name = &quot;allow_ssh_http&quot;<br>  }<br>}<br><br></pre><ul><li>providers.tf</li></ul><pre>provider &quot;aws&quot; {<br>    region = &quot;us-east-1&quot;<br>    #access_key = &quot;XXXXXX&quot;<br>    #secret_key = &quot;XXXXXX&quot;<br>}</pre><p>Next, we can run the following commands to deploy the infrastructure with Terraform.</p><pre>cd terraform<br>terraform init<br>terraform plan<br>terraform apply</pre><p>Type yes at the prompt if asked.</p><p>After the commands are executed the EC2 instance should be created as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*fqr2ttwdXcqQOkVAKprfAg.png" /></figure><h4>Ansible</h4><p>Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is used for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything systems administrators do on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.</p><p>Because Ansible is all about automation, it requires instructions to accomplish each job. With everything written down in simple script form, it’s easy to do version control. The idea is that the maintenance of server and client infrastructure can and should be treated the same as software development, with repositories of self-documenting, proven, and executable solutions capable of running an organization regardless of staff changes. Infrastructure as a CODE!</p><p>While Ansible may be at the forefront of automation, systems administration, and DevOps, it’s also useful to everyday users. Ansible allows you to configure not just one computer, but potentially a whole network of computers at once, and using it requires no programming skills. Instructions written for Ansible are human-readable. Whether you’re entirely new to computers or an expert, Ansible files are easy to understand.</p><p>Next, we shall SSH into the EC2 instance using the public IP address with the following command</p><pre>ssh -i &quot;&lt;location of the ssh key&gt;&quot; ec2-user@ec2-3-236-202-211.compute-1.amazonaws.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*Rk5ayj3H1b2BNLjYltaQ4g.png" /></figure><p>Then install Ansible with the following commands</p><pre>sudo yum-config-manager --enable epel<br>sudo yum install ansible -y</pre><p>After the installation was complete, upload the ansible playbook to your instance and unzip the same. I copied my ansible playbook to an s3 bucket and made it public so I can access it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*dpSCbxiaYXGSImxSoDeIew.png" /></figure><p>Remember the Magento access keys that we saved earlier. We shall use them along with the public IP address of the EC2 instance in the Ansible yaml file. Change directory to <em>ansible-magento2/group_vars</em> folder with the command</p><pre>cd ansible-magento2/group_vars</pre><p>Open the <em>all.yml </em>file and update the</p><ul><li>magento_domain</li><li>server_hostname</li><li>repo_api_key</li><li>repo_secret_key</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*NpAg9c4_UqUdsO_7P_7laQ.png" /></figure><p>Moved back to the root folder <em>ansible-magento2</em> and run the following playbook command</p><pre>ansible-playbook -i hosts.yml ansible-magento2.yml -k -vvv --become</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*SxYRO5yFNyi9QXyJVRBwBw.png" /></figure><p>After the playbook is finished use the public IP of the EC2 instance in the browser to confirm Magento was installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vCNQXNSUaZQ1VNZ88o_MnQ.png" /></figure><p>Great!. Now go to the Magento admin page</p><pre>http://&lt;EC2_PUBLIC_IP&gt;/securelocation</pre><p>and log in to make some changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*LMptdQC9RIJSJpB2OnbVfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BUA-mCVMXTsXQoNX2z0AJg.png" /></figure><p>Use the left menu and navigate to <em>Content → Configuration</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*W8Lf4F3c-Gaj5IeXmAfgWA.png" /></figure><p>Click on <em>Edit </em>Action for <em>Default Store View</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Lo-Q5ymjTbIKBUb50GeXg.png" /></figure><p>Expand <em>HTML Head</em> and change the <em>Default page title</em> to <em>The Cloud Bootcamp Store</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkRJyp7QSIBsXKcxOZd9PQ.png" /></figure><p>Also, expand the <em>Header</em> section and upload The Cloud Bootcamp logo from my images and change the <em>Welcome text</em> to <em>Welcome to The Cloud Bootcamp Store! </em>and click on Save Configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOchbhJ21HfK2JEKT2L2sg.png" /></figure><p>Next, navigate to <em>Catalog → Products</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*uJXFCa6XN5zc0jb6xjVlwQ.png" /></figure><p>Click <em>Add product</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twY59iZHON21zDn6-LXteQ.png" /></figure><p>and add a product with the following attributes</p><ul><li>Product Name: <em>The Cloud Bootcamp T-Shirt</em></li><li>Price: <em>80</em></li><li>Quantity: <em>100</em></li></ul><p>Add images under <em>Images and Videos</em> and click <em>Save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l1qY8EgSLcpgjXqhmeRKAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RvSl66awbVwbfT9QK01J7w.png" /></figure><p>Lastly, navigate to <em>Content → Pages</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*ZxWZwpxSFlvY4FBKOvEqtA.png" /></figure><p>On the row <em>Home page</em> from the <em>Action </em>column click <em>Select → Edit</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53AFdj58KQNW-_K51tSWPw.png" /></figure><p>On the following page expand <em>Content</em> and erase the default content. Then select <em>Insert Widget</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpwwUG4sYdz7cs1UI_bTnA.png" /></figure><p>Select <em>Catalog New Products List → Insert Widget</em> and click <em>Save</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DXgikwWfymNMSVCFAGLrnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YG23s9e2ZpZ4uCMwEi12uw.png" /></figure><p>Click <em>Save</em>.</p><p>At the top right navigate to <em>Admin → Customer View</em> and verify your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*Oq9ewvOgpwgZAPOxV7alvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6wRnC7WApXop7TACzPDE2w.png" /></figure><p>Great, we were able to set up a basic e-commerce website that allows us to showcase our products and allow checkout, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOLolTFfhCtxQ3XUEhQX5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89bf04c6d92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Executive Presentation of Infrastructure costs for an SAP Migration project from On-Premises to AWS]]></title>
            <link>https://medium.com/@markiv247/executive-presentation-of-infrastructure-costs-for-an-sap-migration-project-from-on-premises-to-aws-26e548a8e4e2?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/26e548a8e4e2</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[pricing]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Thu, 01 Dec 2022 19:34:17 GMT</pubDate>
            <atom:updated>2022-12-01T19:34:17.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAHrxBb-MZNiFS1NuwIplw.png" /></figure><p>In this exercise based on a real-world scenario, I created an executive presentation of infrastructure costs for the migration of an SAP project from On-Premises to AWS.</p><p>SAP workloads were running in a corporate DataCenter with the environment divided into Production, Quality Assurance (QA), and Development/Test layers.</p><p>The exercise was to estimate the costs of migration to AWS, considering that this infrastructure would be running on AWS for at least the next 3 years. Also, in case SAP on-premises environments would go down, aggressive SLA support from AWS would be needed with less than 15 minutes of response time.</p><p>The very first task would be to create a spreadsheet and plan out the current on-premises infrastructure so that we can easily refer to the same while we create the estimate in AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlEvK8osEcSECDO1dk7bqw.png" /></figure><h4>AWS Pricing Calculator</h4><p>Amazon has a tool called the <a href="https://calculator.aws/">AWS Pricing Calculator</a> that estimates the cost of migrating an application to AWS using its services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqA9rRUcEH0TXJI3Op8mJw.png" /></figure><h4>Application Servers</h4><p>Let&#39;s estimate the cost of the EC2 servers that would be needed. Click on <em>Create Estimate, </em>select <em>Search all services, </em>and in <em>Find Service </em>search for EC2 and then click <em>Configure </em>under <em>Amazon EC2</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8mRWPMQRQTf8ZJ35jIMGQ.png" /></figure><p>On the next page select, the <em>Region</em> and <em>Quick estimate</em> as this is a quick ballpark estimate. Based on our spreadsheet let’s start with the production EC2 instances and input the necessary options and click <em>Save and add service</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ImoTJt4BBvj68snsVfEkQ.png" /></figure><p>Next for <em>Stage</em> and <em>Development/Testing</em> instances repeat the process above to finalize the EC2 pricing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiPdPgaQgvJAQs1it7Y2TA.png" /></figure><p>I repeated the process to add the other services for the application servers to the estimate</p><ul><li>Amazon Elastic File System (EFS) Storage</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSKhHF5qe0oT3rGBxKoImg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DrI2KLNZ2Yp_1q-zuwl7Bg.png" /></figure><ul><li>Elastic Load Balancers: 3<br>- Processed bytes = 2<br>- Average Number of Requests per second per ALB = 100<br>- Average Number of rule evaluations per request = 100</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJ4Lv53XtpABZ5uGubyBxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E_lQAGSb9bAviGzxk9tszQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KYHCyfpud74KltpmdE0Vjw.png" /></figure><h4>Databases</h4><p>For the Oracle databases, the AWS service we shall use is RDS. So in the calculator search for <em>RDS for oracle</em> and click <em>Configure</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVhbopkM8Dd6uiavi66nDA.png" /></figure><p>Since Production, Stage, and Development/Testing sizes are all different I did their estimations individually. One thing to note, if the instance sizing is not available it’s advisable to size up instead of down. I had to do that because vCPU of 38 was not available. The next size up was vCPU: 40 Memory 160 GB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lEhnhzFh15jD-rKkaOGLAw.png" /></figure><p>Click <em>Save and add service</em>. I repeated the process for <em>Staging</em> and <em>Development/Testing</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sU_fvtU2lqlYIBCJpqNe9g.png" /></figure><p>Now that the cost estimate is completed the last thing required is the AWS support level for the business critical environments, click on <em>Add support</em>.</p><p>Based on the required SLA,</p><ul><li>select <em>Multiple AWS Support associates can email or phone 24/7</em> under <em>Enhanced technical support</em></li><li>Select <em>15 minutes or less </em>under <em>High severity response times</em></li><li>Select <em>Enterprise support plan </em>under <em>Support recommendation</em></li></ul><p>then click <em>Add to my estimate</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-9hLMkw_XsTyP3n6nzFgGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6eou6i8RwqCWHxlFz08pQQ.png" /></figure><p>If required the above data can be represented to anyone in the form of a presentation or shared as a link and even exported in a PDF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RyCL4-KDF1TD69_KU03f3g.png" /></figure><p>A simple solution architecture for this exercise is below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08pqbUwgBcAOgQ8Fv9y2oA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26e548a8e4e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment of a set of EC2 instances using Terraform and AWS Systems Manager configuration with…]]></title>
            <link>https://medium.com/@markiv247/deployment-of-a-set-of-ec2-instances-using-terraform-and-aws-systems-manager-configuration-with-8dee2d82bf20?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dee2d82bf20</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws-sns]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Tue, 29 Nov 2022 22:52:36 GMT</pubDate>
            <atom:updated>2022-11-29T23:05:43.314Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deployment of a set of EC2 instances using Terraform and AWS Systems Manager configuration with Amazon Simple Notification Service for automated installation of security agents</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOLU0gXis-L_rhZyevoSLQ.png" /></figure><p>In this new exercise let’s assume I am a DevSecOps engineer and I have been tasked with deploying a set of EC2 instances and their infrastructure in an automated manner. How do I go about doing this? <a href="https://www.terraform.io/">Terraform </a>(<a href="https://www.terraform.io/use-cases/infrastructure-as-code">infrastructure as a code — IAAC</a>) would be the way to go.</p><p>What if I was also instructed to install a specific security agent on all the instances in an automated fashion? Once the infrastructure was provisioned, the <a href="https://aws.amazon.com/systems-manager/">AWS system manage</a>r and its component <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html">Command Run</a> could be used to install the security agents. To make this more informative I also used the <a href="https://aws.amazon.com/sns/">AWS Simple Notification Service — SNS</a> to send an email informing me of the whole process status.</p><h4>Terraform</h4><p>Terraform would be used to provision the EC2 instances. We would use Visual Studio Code (VSCode). You can download it from <a href="https://code.visualstudio.com/download">here</a>. VSCode is a free IDE, which combines the simplicity of a source code editor with powerful developer tooling, like IntelliSense code completion and debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Ik20VQupVdY33nmjhLXDg.png" /></figure><p>Once we have installed VSCode we would need to install the terraform extension. We can do so by opening VSCode and clicking on the <em>Extensions </em>icon on the left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8dIywEGyJk3UeaKDMpnlA.png" /></figure><p>At the top, search for the keyword <em>terraform </em>select <em>HashiCorp Terraform </em>post the search and click <em>Install</em>. The extension provides autocompletion and syntax highlighting for Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMcAFHAVyTr9Crtz1Pgerg.png" /></figure><p>Once the terraform extension is installed we can move forward with our code. Copy the below terraform files and add them to your VSCode project under a folder <em>terraform</em>.</p><ul><li><em>main.tf</em></li></ul><pre>data &quot;aws_ami&quot; &quot;ubuntu&quot; {<br>  most_recent = true<br><br>  filter {<br>    name   = &quot;name&quot;<br>    values = [&quot;ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*&quot;]<br>  }<br><br>  filter {<br>    name   = &quot;virtualization-type&quot;<br>    values = [&quot;hvm&quot;]<br>  }<br><br>  owners = [&quot;099720109477&quot;] # Canonical<br>}<br><br>variable &quot;vpc_id&quot; {<br>    default = &quot;vpc-0f26f1f6cbf57ccf8&quot;<br>}<br><br>variable &quot;subnet_id&quot; {<br>    default = &quot;subnet-024f4a19ca57886c3&quot;<br>}<br><br>variable &quot;key_name&quot; {<br>    default = &quot;sshkey1&quot;<br>}<br><br><br>resource &quot;aws_security_group&quot; &quot;allow_ssh&quot; {<br>  name        = &quot;allow_ssh&quot;<br>  description = &quot;Allow external SSH connectivity to EC2 instances&quot;<br>  vpc_id      = var.vpc_id<br><br>  ingress {<br>    description = &quot;SSH to EC2&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>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    Name = &quot;allow_ssh&quot;<br>  }<br>}<br><br>resource &quot;aws_instance&quot; &quot;webserver1&quot; {<br>  ami           = data.aws_ami.ubuntu.id<br>  instance_type = &quot;t2.micro&quot;<br>  key_name = var.key_name<br>  subnet_id = var.subnet_id<br>  vpc_security_group_ids = [aws_security_group.allow_ssh.id]<br>  associate_public_ip_address = true<br><br>  tags = {<br>    Name = &quot;webserver1&quot;<br>  }<br>}<br><br><br>resource &quot;aws_instance&quot; &quot;webserver2&quot; {<br>  ami           = data.aws_ami.ubuntu.id<br>  instance_type = &quot;t2.micro&quot;<br>  key_name = var.key_name<br>  subnet_id = var.subnet_id<br>  vpc_security_group_ids = [aws_security_group.allow_ssh.id]<br>  associate_public_ip_address = true<br><br>  tags = {<br>    Name = &quot;webserver2&quot;<br>  }<br>}</pre><p>Replace the <em>vpc_id</em> in the above file with your default VPC (<em>vpc → Your VPCs → select VPC that is the default</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*T1ivEVkBk8JjFIydaqwx8Q.png" /></figure><p>and <em>subnet_id in </em>the above file with any one of the available subnets (<em>vpc → Subnets → Select any one subnet</em>) from your AWS console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*089KgLhsv8dYR29TQqvb6Q.png" /></figure><p>During the provisioning of the infrastructure, Terraform will need an SSH key to remotely access the instances. We can create a new key pair by going to <em>ec2 → Key Pairs → </em>click on <em>Create key pair</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*FyPwvzo6lH7cv502ZIOQ1g.png" /></figure><p>I named the new key <em>terraformkey </em>and clicked on Create key pair and downloaded it. Also, I added this new name in the <em>main.tf </em>file under <em>key_name</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*i6o8Ld2d9c30GNHtToicPw.png" /></figure><p>My updated <em>main.tf </em>file now looks something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mI-YfjSoE89f-NL2nSBxxw.png" /></figure><ul><li>provider.tf</li></ul><pre>provider &quot;aws&quot; {<br>    region = &quot;us-east-1&quot;<br>    #access_key = &quot;XXXXXXXXX&quot;<br>    #secret_key = &quot;XXXXXXXXX&quot;<br>}</pre><p>I zipped the files in the folder called terraform and uploaded them to CloudShell. At the top of the console, I clicked the CloudShell icon to launch it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*9NIZtxUR-IkqG6wV-mtIxA.png" /></figure><p>Then i clicked on <em>Actions → Upload file</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*mjDgzWOnti7FR5kJnLRFUg.png" /></figure><p>Select the zipped folder and click <em>Upload</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*f__cyPxZ9TAHdwH_SjaUEA.png" /></figure><p>In CloudShell I unzipped the folder and moved into it with the commands:</p><pre>unzip terraform.zip<br>cd terraform</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*_Q3NV_AzG7BlrVVZ1PVmiQ.png" /></figure><p>Before we run any Terraform commands in CloudShell we would need to install it. Run the following commands to install Terraform</p><pre>sudo yum install -y yum-utils<br>sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo<br>sudo yum -y install terraform</pre><p>Next I initialized my working terraform directory containing the configuration,</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*e-AWk8WcxaaU3XngYWpNRQ.png" /></figure><p>ran the command to provide to provide human-readable output</p><pre>terraform plan</pre><p>and the command to execute the proposed plan</p><pre> terraform apply</pre><p>type <em>yes </em>if prompted. You should see the output on the console once the instances are created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*KiG6wzcze-fOw4FqfI0fRw.png" /></figure><p>We can verify the instances were created in the console. Go to the EC2 dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*qw4SI5SAjqDjJMJRZ0BCyQ.png" /></figure><h4><strong>Simple Notification Service (SNS)</strong></h4><p>In order for the AWS Systems Manager to send notification emails through the Simple Notification Service (SNS) we need an IAM Role for its authorization. I navigated to <em>IAM → Roles → </em>Click <em>Create role</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HTwUbXGoP48vHt7OnBBkrQ.png" /></figure><p>Select <em>AWS service </em>and Under <em>Use cases for other AWS services</em> select <em>Systems Manager</em> from the dropdown then the first option under that, <em>Allows SSM to call AWS services on your behalf</em> and then click <em>Next</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*uImxDMAG7ouW-374xAGh3A.png" /></figure><p>On the Add permissions page, search for <em>SNS </em>and select <em>AmazonSNSFullAccess</em> and click <em>Next</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*1MFQaNOg2u85pF1_LqSh2w.png" /></figure><p>Give the role name <em>SystemsManagerToSNS </em>and click <em>Create role.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*leWbimR2Snb_1Cv5y66bYg.png" /></figure><p>Now that we have the role created we’ll need to set up a notification, to do this we’ll search for notifications and you should see in the drop-down menu, <em>Simple Notification service, </em>click the link<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*jbCoR7ef96mfee1qDytWDw.png" /></figure><p>From the left menu, let’s select <em>Topics → Create topic</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lzOUBHSpei3wtXXuS8uMHg.png" /></figure><p>Select <em>Standard </em>and name it <em>DevOpsNotification</em> and leave everything else as default and further click <em>Create topic</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JroS3y3VQpe4TGIF62fpOw.png" /></figure><p>Copy the ARN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*DZdrAyMry7qMP3AGfLFh1g.png" /></figure><p>Now let&#39;s create a subscription for the topic we created. Under the <em>Subscriptions </em>tab, click on <em>Create subscriptions</em> and enter the copied ARN in the <em>Topic ARN</em> field. Select the protocol as <em>Email </em>and enter an email of your choice in the <em>Endpoint</em>. Please make sure you have access to this email as we will receive notifications on this email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*ZMP45qK-gVnejB0G8zayPQ.png" /></figure><p>Once you’ve placed your email hit Create subscription, you’ll then get an email,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*yxzFEOKqurmsXG0SFSmDjA.png" /></figure><p>you’ll just want to click C<em>onfirm subscription</em> on the email you receive and you’re good to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*hzv4cwkiOF8HzNnk4iQrOw.png" /></figure><h4><strong>AWS Systems Manager</strong></h4><p>Next, we shall install the <em>security agents. </em>Search for <em>Systems Manager </em>and click the link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*8f6UpMrP4dLTOn2KcoxSsA.png" /></figure><p>Click on<em> Quick Setup</em> and verify your home Region and click on <em>Get started</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ux_EJxgl9GSaaBtIRX1OKA.png" /></figure><p>Under <em>Host Management </em>click Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*LbjCOAmKSwcKInc5Brr9HQ.png" /></figure><p>The only change here was under <em>Targets</em> select <em>Manual</em> and choose the two EC2 instances to install the security agents and click <em>Create</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IkReOzCKt89xrJUbduCUyA.png" /></figure><p>Once the configuration is completed the status should be shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*_Krl2QErYP-3Ysq0A9nWEw.png" /></figure><p>Next under <em>Node Management</em> on the left select <em>Session Manager </em>and then click the <em>Start Session</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1H_Dokxm6qXTxwYIwSczNw.png" /></figure><p>We should be expected to see our EC2 Instances here but they weren’t. I rebooted both instances using the EC2 console to re-run the SSM-agent startup script and refreshed the target instances section in Session Manager and there they were. I also found <a href="https://aws.amazon.com/premiumsupport/knowledge-center/systems-manager-ec2-instance-not-appear/">this</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGuiPQ5xrW-V9nGr_UN48g.png" /></figure><p>Next under Session Manager on the left menu select <em>Run Command</em> so that we can install the security agent. Click on <em>Run command</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TBJj0DNc8_0Q9n4cIefbiA.png" /></figure><p>and filter by <em>Shell</em> and select <em>AWS-RunShellScript</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*2FHS53gbQVc5eDqFvfox3Q.png" /></figure><p>Under Commands parameters enter the following:</p><pre>sudo wget -q https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/install_security_agent.sh -P /tmp<br>sudo chmod +x /tmp/install_security_agent.sh<br>sudo /tmp/install_security_agent.sh<br>ls -ltr /usr/bin/security_agent</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*jfJqtlBOIE11rl7oUnk0cA.png" /></figure><p>Under <em>Target selection</em> select <em>Choose instances manually</em> and select both instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*7XAFAQNQUp1KAR2TlV_csA.png" /></figure><p>Uncheck <em>Enable an S3 bucket</em> under the <em>Output option</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*3CM_obLWx5eoHeJjPSMthw.png" /></figure><p>Under <em>SNS notifications</em> check <em>Enable SNS notifications, </em>then search and select the <em>SystemsManagerToSNS</em> ARN. For the SNS topic, use the ARN for the <em>DevOpsNotification,</em> and under <em>Change notifications</em> select <em>Command status on each instance changes</em> since it’s only two instances, and then click <em>Run</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*pTJ7imX9ZsqV5PgiuGjs5Q.png" /></figure><p>After a few minutes, the Run Command should show up as successful and we should receive email notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*ywR35gIDEl4BWAnEWAF03w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*XHogfwG1NQ_2g7Sb1xp5Tw.png" /></figure><p>I hope you find this article interesting. Below is the solution architecture for the above exercise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmfIgcR0uUlYr0AngWBHMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dee2d82bf20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment of a Scalable Web Application using AWS Elastic Beanstalk, DynamoDB, CloudFront, and…]]></title>
            <link>https://medium.com/@markiv247/deployment-of-a-scalable-web-application-using-aws-elastic-beanstalk-dynamodb-cloudfront-and-620caa6290f?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/620caa6290f</guid>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 19:30:15 GMT</pubDate>
            <atom:updated>2022-11-28T19:30:15.015Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deployment of a Scalable Web Application using AWS Elastic Beanstalk, DynamoDB, CloudFront, and Edge Location.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*MzVF5jZEGRiI6MEU5UaD4A.png" /></figure><p>How would we go about deploying an application that needs to support the high demands of a large number of users accessing it simultaneously? The application would be used in a large conference that has more than 10,000 people in person and online, with participants from all over the world.</p><p>What if 10 vouchers were drawn from 3 cloud certifications at this event? So that would mean more than 10,000 people in the audience registered their emails to guarantee their participation in the raffle.</p><p>We can achieve this by using <a href="https://aws.amazon.com/elasticbeanstalk/">AWS Elastic Beanstalk (EBS)</a> services to deploy the web application, <a href="https://aws.amazon.com/dynamodb/">DynamoDB </a>to store emails, <a href="https://aws.amazon.com/cloudfront/">CloudFront </a>to cache static and dynamic files in an <a href="https://wa.aws.amazon.com/wellarchitected/2020-07-02T19-33-23/wat.concept.edge-location.en.html">Edge Location</a> close to the user.</p><p>Let&#39;s start with the data side first. On the AWS console search for the keyword DynamoDB and click the link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*yFLIe-SVVFJ43V_c9NsJfg.png" /></figure><p>Once inside the DynamoDB dashboard click on the button <em>Create table.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*kVmESntZgUmxHuVHutBlQQ.png" /></figure><p>In the Create Table screen enter the following details for the table to be created</p><ul><li>Table Name: <em>users</em></li><li>Partition Key: <em>email</em></li></ul><p>Keep all the remaining details default and click <em>Create table </em>at the bottom right of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*6_jqRypHnKF4VCE95ISNNQ.png" /></figure><p>Once the table is created you should see the following screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4nhbxtzAIQnXmEypNLKyJw.png" /></figure><p>Now let&#39;s move to the AWS service that will deploy and scale the web application. I Searched for elastic beanstalk and clicked the link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*_mAQ6yrqsRtNC20cvkazBw.png" /></figure><p>Now click on <em>Create application</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*j8o3dBttF3o8r0gP6Zp2eg.png" /></figure><p>Enter the following details</p><ul><li>Application name:<em> bc-conference</em></li><li>Platform (runtime environment): <em>Python 3.7+</em></li><li>Application code: Upload your code → enter a public S3 bucket where you would have uploaded your code. In my case it was <em>https://&lt;url&gt;/&lt;bucketname&gt;/en/cb-conf-app-EN.zip</em></li></ul><p>Click on <em>Configure more options </em>at the bottom of the screen as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*3sdipCSGzNmUX5-h3H-AlA.png" /></figure><p>I selected <em>High availability</em> under <em>presets </em>as the changes to the configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*jWsERG4-a506v3JZqLBjRg.png" /></figure><p>Under <em>software</em>, I clicked on <em>edit, </em>and under environment properties added <em>AWS_REGION</em> with the value <em>us-east-1 </em>and clicked on <em>Save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*IVa5s3_aE-Uog01GGUGpiQ.png" /></figure><p>Next, Under instance, I clicked on <em>edit </em>and changed the root volume type to <em>General Purpose SSD,</em> and set the size to <em>8 GB. </em>Click<em> Save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*EdNew2_qL1DiSSTwpjJaZg.png" /></figure><p>Next, Under capacity, I clicked on <em>edit </em>and changed the</p><ul><li>Min Instances: <em>2</em></li><li>Max Instances: <em>4</em></li><li>Instance Type: <em>t2-micro</em></li><li>Scalling Triggers<br>- Metric: <em>CPUUtilization</em><br>- Unit: <em>Percent</em><br>- Period: <em>1 Min</em><br>- Breach duration: <em>1 Min</em><br>- Upper threshold: <em>50</em><br>- Lower threshold: <em>40</em></li></ul><p>Click <em>Save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*IrguYTzMxx6G5uhKSaBtlg.png" /></figure><p>Next, Under security, I clicked on <em>edit </em>and selected the <em>ssh-key </em>under EC2 key pair within the Virtual machine permissions section. Click <em>save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*Hx2uOgtEZN-lPDJYWWbk0A.png" /></figure><p>Lastly, under <em>Network</em>, I clicked on <em>edit </em>and let the VPC remain defaulted if not select the default VPC, selected all Load balancer subnets, checked <em>public IP address </em>under instance settings so that the EC2 instance can be accessed over the internet, and selected all instance subnets. Click <em>save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*io9CXli-yOOvjyNglndScQ.png" /></figure><p>Verify all the changes are correct and then click on <em>Create app</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*158VTnkFqE5T47qdAhP6_w.png" /></figure><p>During this process, ELB is going to provision all the resources needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*1KKtrTyZGRhEOSlSw7DXBg.png" /></figure><p>After the provisioning was completed I accessed the application via the URL below the environment name above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q92uj42BrEhAk-9f0t4Ezw.png" /></figure><p>Now let us try to enter an email and register a user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y8HSwC0xYGd3RoEGkVRmvA.png" /></figure><p>We get an error. Let&#39;s check the log files to see what the issue might be.</p><p>From the environment, menu go to Logs → Request Logs → Last 100 lines → Download</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1eLrN0oUKQXs59n_CfQQg.png" /></figure><p>I see an <em>AccessDeniedException </em>that states <em>ELB is not authorized to perform a PutItem action</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnv6StNgIFrZLRhLaJSV_g.png" /></figure><p>This means that an IAM role is needed for the EC2 instance web application to perform this action.</p><p>I navigated to <em>Elastic beanstalk → Environments → Bcconference-env → Configuration → Security</em> and copied the IAM instance profile role, <em>aws-elasticbeanstalk-ec2-role</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Zs7ALB2uQ-ULx_pu6Voaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2CRdb4YZUOPojp30TfJmQA.png" /></figure><p>I then navigated to<em> IAM -&gt; Roles</em> and searched for and selected <em>aws-elasticbeanstalk-ec2-role</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sbuWXconMl87TbV5O9WxZQ.png" /></figure><p>I checked the permissions for <em>aws-elasticbeanstalk-ec2-role </em>and noticed nothing associated to DynamoDB was present for this role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*YZIJ3Zrtm5z1EG4ZlwGKGQ.png" /></figure><p>So I clicked on <em>Add permissions → Attach policies</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*gceu7Wy1-ssLHOUJUc_WBQ.png" /></figure><p>and searched for <em>DynamoDB</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2SwUyDpRArMV7Za7l5LQA.png" /></figure><p>Selected <em>AmazonDynamoDBFullAccess </em>and clicked on <em>Attach policies</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mN5PzexPF1yJe2nMJ_GTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*NYsRcQD5Xs_E1QGC-d9eAg.png" /></figure><p>I then went back to the web application in the browser and tried to register the user letstrythisagain@gmail.com again and it was successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuETNCkP47IKnOALyTGHFQ.png" /></figure><p>I validated that the user was created in DynamoDB as well. Go to <em>DynamoDB → Tables → Explore items → Select table users</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tEH4l2NrP3XLjIrJ0Gqz3g.png" /></figure><h4>CloudFront</h4><p>Let&#39;s enable CloudFront which is a fast content delivery network service that allows application content to be delivered securely and globally with low latency and high transfer speeds.</p><p>Search for <em>CloudFront</em> on the AWS console and click the link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*FGEJFwIF1QQRUUZYPLVOFQ.png" /></figure><p>Click on <em>Create a CloudFront distribution</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*uozB2Zxx87FzcC9t6utsjQ.png" /></figure><p>Enter the <em>Origin domain</em> as the <em>EBS load balancer</em> under the section <em>Origin</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*NtqomlCkGDCpsRoA3-x2-A.png" /></figure><p>Under the section <em>Default cache behavior → Allow HTTP methods</em> select <em>GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*FsEDyxI8ygGmvI1MMiAHDA.png" /></figure><p>Click <em>Create distribution </em>and verify if the distribution is working as expected by accessing the application via the Distribution domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*mMpSNakeu-NeSf-bPwUuMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LVH8-7_AazmnokYu1i8q9w.png" /></figure><p><strong>Load testing</strong></p><p>I navigated to <em>EC2 -&gt; Instances</em> and selected one of the two instances and click on connect</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TeVcftbvhtHhbVQ4cgtb2Q.png" /></figure><p>and select SSH client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*JQhWAXwiKBJysFuLNaBh9A.png" /></figure><p>Copy the example command and replace the user root with ec2-user and run the command on your terminal from the navigated location of the ssh-key.pem file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*PhzmdyvJoctQ5crc_alOuw.png" /></figure><p>From there I installed the stress test tools in order to perform the load testing using the following commands</p><pre>sudo amazon-linux-extras install epel -y<br>sudo yum install stress -y</pre><p>Once installed I ran the command to apply the stress test on the system.</p><pre>stress -c 4</pre><p>I navigated to the EBS environment and the system was already under warning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*u8rrHvsj4_WydUhpqjaSpg.png" /></figure><p>CPU shows 100% utilization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*t8KQOq65MUMxNO9NKjG3gw.png" /></figure><p>Great the system scaled up and created a new instance once the CPU stress passes 50% as you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WjxcKriz6Fmkc22f9g_fw.png" /></figure><p>So we can see that the system was scaled automatically when the CPU utilization was increased based on the trigger we set for EBS. We can see the event overview for EBS showing us that a new instance was provisioned</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5N9wqiRFmmd-7DddEGJdTQ.png" /></figure><p>Once we shut down the stress test we can see the instance automatically being removed as we have no more high CPU utilization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*tVugEi8VOF72ydaEHQ5tLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2IiRCKJX-5lTauHynegzg.png" /></figure><p>Below is the solution architecture for what we implemented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PN26iR9C2nsoKUeKV4vPEg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=620caa6290f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migration of a Workload running in an On-Premise data center to AWS using Amazon EC2 and RDS…]]></title>
            <link>https://medium.com/@markiv247/migration-of-a-workload-running-in-an-on-premise-data-center-to-aws-using-amazon-ec2-and-rds-778f3776193?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/778f3776193</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[aws-rds]]></category>
            <category><![CDATA[mysq]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Fri, 25 Nov 2022 20:29:13 GMT</pubDate>
            <atom:updated>2022-11-25T20:29:13.941Z</atom:updated>
            <content:encoded><![CDATA[<h3>Migration of a Workload running in an On-Premise data center to AWS using Amazon EC2 and RDS service</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*VDHKFPKmLOUpVr03CQidRQ.png" /></figure><p>In another exercise based on a real-world scenario, we would be responsible for migrating a workload running in an On-Premise data center to AWS. The application and database would be migrated to AWS using the Lift &amp; Shift (rehost) model, moving both the application and database data.</p><p>I followed the following migration steps:</p><ol><li>Planning ( sizing, prerequisites, resource naming)</li><li>Execution (resource provisioning, best practices)</li><li>Go-Live (validation test — Dry-run, final migration — Cutover)</li><li>Post Go-live (ensure the operation of the application and user access)</li></ol><h4>Planning</h4><p>Before any major task, it&#39;s a very good idea to plan. With planning, we can asses what we would need eventually to accomplish the task at hand. In our case, we used the details of the current system (on-premise) so that we can come up with a sizing estimate for the AWS migration. The details we captured were</p><ol><li>Server Name</li><li>Server IP</li><li>Description of the resources</li><li>Total RAM (GB)</li><li>Total vCPU</li><li>Total Storage (GB)</li></ol><p>Using the AWS documentation available we can choose the right instances based on the data we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*MZb4010Msk5i9KiC" /></figure><p>To replicate the private network in the on-premise data center we will need to create a Virtual Private Cloud (VPC) within an AWS region, with an availability zone (AZ) and its associated subnets which can be private or public based on access criteria.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYgm-t23E-prFGbCSPU-8w.png" /></figure><p>We would also need to define the operating system, software, and libraries needed by the instances we would create on AWS. If needed we can also list the commands we would need to run on those instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sEzzqlll_fIlz6ffDJZufQ.png" /></figure><h4>Setting up the network (<a href="https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html">VPC</a>, <a href="https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html">Subnets, </a>and <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html">Internet Gateway</a>)</h4><p>On the AWS console page, I searched for the keyword VPC and then clicked on <em>VPC</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*aO8FamAKyxDzIGsAv568dw.png" /></figure><p>Then click on <em>Create VPC</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*dXKysPQMYrGsU3WaJ7DiQQ.png" /></figure><p>On the create VPC page you should see two options: <em>VPC Only</em> and <em>VPC and more. </em>Since we want to create all resources without any help from AWS we will use the option <em>VPC only. </em>Define a name for your VPC in my case I named it <em>vpc-prod-1</em>. Define a CIDR block for the IPv4, I used <em>10.0.0.0/16.</em> Make sure that the CIDR block (<em>10.0.0.0/16</em>) should not overlap with the on-premise environments or other cloud providers you may have. Click on <em>Create VPC</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*jCOgF7yPZSSzScNGmuqEdw.png" /></figure><p>Now that we have created the VPC we will go ahead and create the subnets within the VPC.</p><p>We will create a public subnet used by the application and two private subnets used by the database.</p><p>Click on <em>subnets</em> from the left-hand side menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*k-kwTF72aYkluW8hUNkXhg.png" /></figure><p>On the subnets page click on the button <em>Create subnet.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*PXvVQx8FEm4gaqJA4Ndj4Q.png" /></figure><p>On the create VPC page select the VPC we just created from the VPC ID drop-down.</p><p>First, we will create the public subnet. In my case, I named it <em>vpc-prod-1-public-1</em>. Select the <em>Availability Zone us-east-1a. </em>Define the <em>CIDR block </em>as<em> 10.0.0.0/24 </em>and click on <em>Create subnet</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*B47fDawpWR9Hv7vQY2jAGQ.png" /></figure><p>For the other two private subnets, I used the same process as above with some minor changes listed below.</p><p><em>Private Subnet 1</em></p><p><em>· Subnet name: vpc-prod-1-private-1 (Private)</em></p><p><em>· CIDR Block: 10.0.1.0/24</em></p><p><em>· Availability zone: same as the public subnet</em></p><p><em>Private Subnet 2</em></p><p><em>· Subnet name: vpc-prod-1-private-2 (Private)</em></p><p><em>· CIDR Block: 10.0.2.0/24</em></p><p><em>· Availability zone: us-east-1b</em></p><p>Your subnet list should now have three new subnets created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kwPG8pIrHWKRywhjIfd0tQ.png" /></figure><p>Now we shall create the Internet Gateway in order to get traffic to the public subnet. From the left menu select <em>Internet gateways</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*seKGXGPYcwJvlmqj_VCvng.png" /></figure><p>Now click on <em>Create internet gateway</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*GV7vTqn6EZDzLm4upWq9PA.png" /></figure><p>Enter a name for your gateway in my case I named it <em>prod-igw </em>and click on <em>Create internet gateway</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*_NJIFMWV2h1UMHlfi4IqGQ.png" /></figure><p>Once the gateway is created we will attach it to the VPC we created earlier using the drop-down menu under actions. I could have also clicked on the button on the green notification area at the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*PWPmlsHPzOOQt-WHyX3gAw.png" /></figure><p>Select the VPC and clicked on <em>Attach internet gateway</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*dqswzM5l34hY9MFP8WU75g.png" /></figure><p>VPC should now be attached to the internet gateway</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*iFwcJHWndQYGbfCWUrd_nw.png" /></figure><p>When traffic hits the Internet gateway it needs to be directed correctly so we created a route in the default route table of the VPC. From the left menu, I navigated to <em>Route tables → Filtered by vpc-prod-1 → Routes</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*KpsVraUdEeZA9gFs4O18bg.png" /></figure><p>Then click on <em>Edit routes → Add route </em>with anyway destination address and the Internet Gateway as the target and click on <em>Save changes</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*vshBg2KroiKy2sPYjm-AUQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*O3inygc88hBm9fUv4IWrEg.png" /></figure><h4>EC2 and RDS Provisioning</h4><p>In the AWS console we shall search for EC2 and click on the EC2 link, from there we should be taken to the EC2 dashboard page. Here click on the <em>Launch instance</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*s7E89mAxdqUP7XdbmF6nWw.png" /></figure><p>Enter the following details for the instance.</p><ul><li>Name and tags: <em>awsuse1app01</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*iLKpdUtI2ydEWl2jMnsv_w.png" /></figure><ul><li>Amazon Machine Image: <em>Ubuntu 18.04</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*S6V9kLB0IGO6l29MRYTOzg.png" /></figure><ul><li>Instance type:<em> t2.micro</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*uiohverNbThNYY1-dWf5Kg.png" /></figure><ul><li>Click on the link <em>Create new key pair → name: ssh-key -&gt; </em>click on <em>Create key pair (</em>Save the file to be used later when connecting to the instance with an ssh client)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*VMW_NQCfKZn-Ov6WmFEiLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*Eo5nD6-BvN1kpb0SPwhDsA.png" /></figure><ul><li><em>Network Settings-</em></li><li>VPC: <em>vpc-prod-1</em></li><li>Subnet:<em> vpc-prod-1-public-1</em></li><li>Assign public IP:<em> Enable</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*lIBOKOVSvyNWStCW1l1qSg.png" /></figure><ul><li>Configure security group</li><li>Select <em>Create security group</em></li><li>Security group name:<em> app-sg01</em></li><li>Port:<em> 22 — </em>Source:<em> 0.0.0.0/0</em></li><li>Click <em>add security group rule </em>and enter the following Port:<em> 8080 — </em>Source:<em> 0.0.0.0/0</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*JcvPGgZVJesgonR2DqRi0Q.png" /></figure><p>The screen should look like the following. Click on <em>Launch Instance</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*tPub93GgaZWhYxu7_gJYmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*EC99ta4n7zzBj9LkD1BrJg.png" /></figure><p>Now it&#39;s time to create our RDS instance. Search for RDS in the search bar and click the RDS link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*-kgJsDT-dgRHpi8LCdkuLA.png" /></figure><p>Now click on <em>create database </em>and enter the following details for the RDS database</p><ul><li>Database creation method: Standard create</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*RGyC1A05Df6XX_hgt71oZQ.png" /></figure><ul><li>Engine options: MySQL 5.7.33</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*GG8lWIbEHvt25sgNVMSEBg.png" /></figure><ul><li>Templates: Free Tier</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*RBEABhYWsmm7I8ijzs9FKQ.png" /></figure><ul><li>Settings:</li><li>DB Instance identifier: <em>awsuse1db01</em></li><li>Credential Settings → Master username: <em>admin →</em> Master password: admin123456</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*TSkApMwasYT4rT2jnafmmw.png" /></figure><ul><li>Instance configuration: <em>db.t2.micro</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*BYjA_sDx8FrhKXmydMCb_Q.png" /></figure><ul><li>Storage: <em>20 GB</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*z47CwA3lkAM8yoYKD56qiw.png" /></figure><ul><li>Connectivity → VPC: <em>vpc-prod-1</em> →Public access: <em>no → </em>VPC security group (firewall):<em> Create new</em> → New VPC security group name: <em>sec-group-db-01</em> → Availability Zone:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*QpHpWJo6KyAKyZsF4TEuTg.png" /></figure><p>Verify all the details and click on <em>Create Database</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*8NmjR7dSiOYSKenT_vkqgw.png" /></figure><h4>Prerequisites</h4><p>Now that we have set up our EC2 and RDS instances we need to access our Ec2 instance and finish some prerequisites for the movement of the client application and eventually make some changes to the RDS instance to finish the deployment.</p><p>Let&#39;s connect to the EC2 instance first while the RDS instance is getting ready. We shall connect to the ECS instance using an SSH client. I would be using PowerShell to login into my instance. We can do this by setting the ssh-key file downloaded during the creation of the EC2 instance in a folder and running the command that AWS provides us.</p><p>To get the command go to the EC2 dashboard and select the EC2 instance and click on <em>connect</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*JFykHxtDPktyA5xp8phazA.png" /></figure><p>on the next page select the SSH client and follow the instructions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*dY87H5mv_LGvN_DwA5cg7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*1mPLz7avFUpbkIt0RHEHuw.png" /></figure><p>Now, let&#39;s run the following commands to update the OS, install python, mysqlclient, unzip, and some required libraries.</p><pre>sudo apt-get update<br>sudo apt-get install python3-dev -y<br>sudo apt-get install libmysqlclient-dev -y<br>sudo apt-get install unzip -y<br>sudo apt-get install libpq-dev python-dev libxml2-dev libxslt1-dev  libldap2-dev -y<br>sudo apt-get install libsasl2-dev libffi-dev -y</pre><p>Next, I installed PIP for Python:</p><pre>curl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py ; python3 get-pip.py --user</pre><p>I got the following warning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*bSswiRROV23PHX5Q5i_vhw.png" /></figure><p>which meant I needed to add ‘/home/ubuntu/.local/bin’ to my PATH. I did so with the command:</p><pre>export PATH=$PATH:/home/ubuntu/.local/bin/</pre><p>I then continued to install the other prerequisites.</p><pre>pip3 install flask<br>pip3 install wtforms<br>pip3 install flask_mysqldb<br>pip3 install passlib</pre><p>I also installed the AWS CLI and MySQl Client with the commands:</p><pre>sudo apt install awscli -y<br>sudo apt-get install mysql-client -y</pre><p>If you remember we created a new security group when we made our RDS instance, we’ll now need to make sure that it’s set up correctly. Let&#39;s go back to our VPC page and make some changes to our new security group. Since we need the application server to connect to the RDS instance we need to change the <em>sec-group-db-01 </em>security groups inbound rule.</p><p>Go to <em>VPC → Security groups →sec-group-db-01 →Inbound rules →Edit inbound rules.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6-eWijC4WonTTzSRxRX9uA.png" /></figure><p>As you can see it only allowed access from one IP address,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBCWAgMkrNXs-p-coVGBbg.png" /></figure><p>but for the purpose of this project, which is NOT BEST PRACTICE, I allowed traffic from anywhere and changed it to 0.0.0.0/0 and clicked “Save rules”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbGyMOZ0Ko16JCsYAUuBUg.png" /></figure><p>The BEST PRACTICE would be from the IP address of the application server.</p><p>From here, we’ll need to remote back into our EC2 instance, moving over all the data our client gave us to it, and then we’ll connect to our RDS client using the following command.</p><pre>mysql -h &lt;RDS_ENDPOINT&gt; -P 3306 -u admin -p</pre><p>You can find the RDS endpoint within your RDS management console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e4rGsKUCjyQbKAQ3BaOBgg.png" /></figure><p>you’ll be typing that command in your EC2 instance and you’ll be prompted for the password you created earlier when you made your RDS instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*miVJ9W4X77_WAqy6ke2SQQ.png" /></figure><p>Once logged in we’ll be creating and moving all the data to our new RDS database using the following commands</p><pre>create database wikidb;<br>use wikidb;<br>source dump-en.sql;</pre><p>Now we’ll create a database user and give it the permissions it needs on our SQL server.</p><pre>CREATE USER wiki@&#39;%&#39; IDENTIFIED BY &#39;wiki123456&#39;;<br><br>GRANT ALL PRIVILEGES ON wikidb.* TO wiki@&#39;%&#39;;<br><br>FLUSH PRIVILEGES;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*gQS0qBFBsKvFu3Y1689Gig.png" /></figure><p>The database is ready and loaded with the required data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*cHiHn826JWyhXclUtpWS4g.png" /></figure><p>Now, let’s change the application configuration so that it can connect to the RDS instance. I unzipped the zip folder which contains the application files and moved into it with the commands:</p><pre>unzip wikiapp-en.zip<br>cd wikiapp</pre><p>I updated the wiki.py file configuration for the MYSQL_HOST from the on-premises server name “dbserver01” to the RDS endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*lzE6YePMLNxvBD98Pwi94Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*Re_L2gtKcSlentzrnzuYdg.png" /></figure><p>Save the file and exit and bring the application up by running the following command</p><pre>python3 wiki.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*ideG-bzsyPT2Adm4tB09RA.png" /></figure><p>And using the public IP address of the application EC2 instance in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQSGbcuO1zm6qrYGxOr8qw.png" /></figure><p>We’ll now want to verify that we can log in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASoz-HjIvGeGKXb6MUhVUg.png" /></figure><p>and we can create an article that should write to our RDS database. When logged in just click <em>Add article.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5DR_XFRYQTokrCqle46yzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ktU-E_915rd_GtkfWZYJPw.png" /></figure><p>The next step would be the <em>Final Migration (Cut-Over)</em> from the on-premises to AWS where we would take another database dump and replace all the data in RDS then decommission the on-premises servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*u9UWV531mp3-t8_py9L6OA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=778f3776193" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated user migration and management of AWS Identity and Access Management (IAM) resources]]></title>
            <link>https://medium.com/@markiv247/automated-user-migration-and-management-of-aws-identity-and-access-management-iam-resources-ee14728e9812?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee14728e9812</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[mfa]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[users]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Tue, 22 Nov 2022 04:39:02 GMT</pubDate>
            <atom:updated>2022-11-22T04:39:02.995Z</atom:updated>
            <content:encoded><![CDATA[<p>In this exercise based on a real-world scenario, we were tasked to migrate users in an automated way and manage AWS IAM (Identity and Access Management) resources.</p><p>There were 100 users that needed to be migrated and have MFA (Multi-factor authentication) enabled on their accounts, as this is a security best practice.</p><p>To avoid repetitive and manual tasks in the AWS console, we needed to think about automating the processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*q2tNSt8lRt_tWXPeGVfL6g.png" /></figure><h4>Prerequisites</h4><p>Before we start migrating users to AWS we would need to create a few groups. Groups allow us to organize users and manage policies for them as well.</p><p>We would use the IAM dashboard to create the groups and the respective policies associated with the groups.</p><p>You should be able to access the IAM dashboard from the AWS console by searching the keyword “IAM”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ct7UX1LvkcOxkc8ikDYUSg.png" /></figure><p>or look at the recently visited tab on your console dashboard if you have visited the same earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*FdqH5sxmfpwWHLAd0J1w6A.png" /></figure><p>Once inside the IAM dashboard click on the <em>User groups </em>menu under the <em>Access management </em>menu on the left-hand side of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FHXs_AUhXQsO5kHrlJqJiA.png" /></figure><p>Go ahead and create the following groups and the respective policies</p><ol><li>Cloud Admin — Policy: AdministratorAccess</li><li>DBA — Policy: AmazonRDSFullAccess</li><li>LinuxAdmin — Policy: AmazonEC2FullAccess</li><li>NetworkAdmin — Policy: AmazonVPSFullAccess</li><li>Trainees — Policy: ReadOnlyAccess</li></ol><p>You can follow the screen below on how to create them and then copy the same process for all the groups.</p><p>Click on the <em>Create Group </em>button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wraYtsHMMnaAyG6USwwnjw.png" /></figure><p>Enter the <em>User group name</em> and check the associated <em>permission policies</em> from the list under the menu <em>Attach permissions policies — Optional. </em>You can either scroll the list or search for the policy from the search box. Once completed click on the <em>Create group</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4n_V-OQkdNejBKWAH7eSjA.png" /></figure><p>Once the groups are created the User groups list should look something like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*do3IOfVAqDRrVSeaATGYUQ.png" /></figure><p>Since we are migrating a list of users we probably would get a list in the form of an excel. Let&#39;s assume the list we got is something like we see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*UvYQX5MMV2DtJeY4H7tBdw.png" /></figure><p>Now that we have the data we should align this data with the groups we have in AWS. We can repurpose the data from this file to create the usernames for the users and align the team with the user groups we just created. For the username, we can use the email address content. So once we make the changes the details should look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*FAjkuXFpKVbKbRQbVHYB8Q.png" /></figure><p>Now that we have created the users and associated the user groups to the user let’s add the passwords as well for the users. We shall set the same password for all users and make sure to set the password reset required to true as part of our script so the users are required to reset the password as soon as they log in. For the scripts to be able to read the content of the excel we shall export it into a CSV and before we do that we shall rename the <em>email </em>column to <em>user</em>, the <em>team </em>column to <em>group</em>, and create a new column <em>password </em>as the script would be able to identify these tags. The excel should look like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*NF_KKne98-5kKeciCCAOuw.png" /></figure><p>Go ahead and save the file as <em>users.csv. </em>Please find below the content of the users.csv file</p><pre>user,group,password<br>jane.doe,DBA,ChangeMe123456!<br>michael.scott,NetworkAdmin,ChangeMe123456!<br>barbara.brown,CloudAdmin,ChangeMe123456!<br>brian.garcia,LinuxAdmin,ChangeMe123456!<br>philip.jack,DBA,ChangeMe123456!<br>angelino.marinho,DBA,ChangeMe123456!<br>arachane.dinis,DBA,ChangeMe123456!<br>armando.pirassununga,DBA,ChangeMe123456!<br>astolfo.cerveira,DBA,ChangeMe123456!<br>augusta.gusmao,DBA,ChangeMe123456!<br>boaventura.trindade,DBA,ChangeMe123456!<br>bras.vides,DBA,ChangeMe123456!<br>bruna.muniz,DBA,ChangeMe123456!<br>capitolina.garrido,DBA,ChangeMe123456!<br>carina.salles,DBA,ChangeMe123456!<br>caua.setubal,DBA,ChangeMe123456!<br>celeste.moreira,DBA,ChangeMe123456!<br>celso.torres,DBA,ChangeMe123456!<br>cesar.matos,LinuxAdmin,ChangeMe123456!<br>cleiton.frois,DBA,ChangeMe123456!<br>cristiana.dornelles,DBA,ChangeMe123456!<br>debora.ferreyra,LinuxAdmin,ChangeMe123456!<br>deolindo.ourique,LinuxAdmin,ChangeMe123456!<br>diamantino.raposo,LinuxAdmin,ChangeMe123456!<br>donato.gama,LinuxAdmin,ChangeMe123456!<br>doroteia.robalo,LinuxAdmin,ChangeMe123456!<br>egas.malta,LinuxAdmin,ChangeMe123456!<br>emiliana.bicudo,LinuxAdmin,ChangeMe123456!<br>esperanca.carrasco,LinuxAdmin,ChangeMe123456!<br>eudes.bogado,LinuxAdmin,ChangeMe123456!<br>fausto.doutel,LinuxAdmin,ChangeMe123456!<br>filipa.holanda,LinuxAdmin,ChangeMe123456!<br>filipe.henriques,LinuxAdmin,ChangeMe123456!<br>gil.pinhal,LinuxAdmin,ChangeMe123456!<br>gilda.maior,LinuxAdmin,ChangeMe123456!<br>giovana.carballo,LinuxAdmin,ChangeMe123456!<br>glauber.feijo,LinuxAdmin,ChangeMe123456!<br>glaucia.pitangui,LinuxAdmin,ChangeMe123456!<br>godofredo.carvalhal,LinuxAdmin,ChangeMe123456!<br>goncalo.balladares,LinuxAdmin,ChangeMe123456!<br>graciano.vianna,LinuxAdmin,ChangeMe123456!<br>gui.maior,LinuxAdmin,ChangeMe123456!<br>guterre.milheiro,LinuxAdmin,ChangeMe123456!<br>guterre.pastana,LinuxAdmin,ChangeMe123456!<br>hedviges.velasquez,LinuxAdmin,ChangeMe123456!<br>helena.acatauacu,LinuxAdmin,ChangeMe123456!<br>hermigio.rosa,LinuxAdmin,ChangeMe123456!<br>ibijara.capiperibe,NetworkAdmin,ChangeMe123456!<br>ifigenia.homem,NetworkAdmin,ChangeMe123456!<br>iracema.bento,NetworkAdmin,ChangeMe123456!<br>jandaira.escobar,NetworkAdmin,ChangeMe123456!<br>jeremias.paula,NetworkAdmin,ChangeMe123456!<br>lavinia.delgado,NetworkAdmin,ChangeMe123456!<br>ligia.palhares,NetworkAdmin,ChangeMe123456!<br>lino.belmonte,NetworkAdmin,ChangeMe123456!<br>lopo.camacho,NetworkAdmin,ChangeMe123456!<br>luisa.ramirez,NetworkAdmin,ChangeMe123456!<br>mario.briao,NetworkAdmin,ChangeMe123456!<br>melissa.queiroz,NetworkAdmin,ChangeMe123456!<br>mem.regueira,NetworkAdmin,ChangeMe123456!<br>morgana.valgueiro,NetworkAdmin,ChangeMe123456!<br>natalia.terra,NetworkAdmin,ChangeMe123456!<br>nazare.verissimo,NetworkAdmin,ChangeMe123456!<br>noe.betancour,NetworkAdmin,ChangeMe123456!<br>noemia.sarmento,NetworkAdmin,ChangeMe123456!<br>olavo.borges,NetworkAdmin,ChangeMe123456!<br>oliveira.sobral,NetworkAdmin,ChangeMe123456!<br>oriana.viveiros,NetworkAdmin,ChangeMe123456!<br>paraguacu.ipanema,NetworkAdmin,ChangeMe123456!<br>placido.medeiros,NetworkAdmin,ChangeMe123456!<br>porfirio.azenha,NetworkAdmin,ChangeMe123456!<br>potira.ferraco,NetworkAdmin,ChangeMe123456!<br>quiteria.xavier,NetworkAdmin,ChangeMe123456!<br>raquel.paredes,Trainees,ChangeMe123456!<br>ruca.conde,Trainees,ChangeMe123456!<br>salvador.vasquez,Trainees,ChangeMe123456!<br>sancha.pino,Trainees,ChangeMe123456!<br>sandro.alvarenga,Trainees,ChangeMe123456!<br>sebastiana.peres,Trainees,ChangeMe123456!<br>sebastiao.vasconcelos,Trainees,ChangeMe123456!<br>severino.martins,Trainees,ChangeMe123456!<br>sidonio.ramirez,Trainees,ChangeMe123456!<br>simone.velasco,Trainees,ChangeMe123456!<br>socorro.brum,Trainees,ChangeMe123456!<br>sofia.siqueira,Trainees,ChangeMe123456!<br>sonas.modesto,Trainees,ChangeMe123456!<br>sonia.telles,Trainees,ChangeMe123456!<br>teodorico.guilheiro,Trainees,ChangeMe123456!<br>tobias.piraja,Trainees,ChangeMe123456!<br>trajano.santanna,Trainees,ChangeMe123456!<br>ubajara.guerreiro,Trainees,ChangeMe123456!<br>vania.paredes,CloudAdmin,ChangeMe123456!<br>vera.andrade,Trainees,ChangeMe123456!<br>viriato.albernaz,Trainees,ChangeMe123456!<br>xenia.peres,CloudAdmin,ChangeMe123456!<br>zelia.ferrao,CloudAdmin,ChangeMe123456!<br>zidane.espargosa,CloudAdmin,ChangeMe123456!<br>zilda.pastana,CloudAdmin,ChangeMe123456!<br>zulmira.paixao,CloudAdmin,ChangeMe123456!<br>zuriel.losada,CloudAdmin,ChangeMe123456!</pre><h4>AWS CloudShell / CLI</h4><p>From the AWS console click on the AWS CloudShell icon at the top of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wKIn67ox1Gs5b3DsihmLBQ.png" /></figure><p>The AWS CloudShell comes pre-configured with AWS CLI so we can dun the required commands to automate the process via a shell script.</p><p>First, we had to install the <em>dos2unix</em> with the following command</p><pre>sudo yum install dos2unix -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0CKOYHw7UH7ZctihgnQZQ.png" /></figure><p>Next, I clicked on <em>Actions → Upload file </em>and uploaded my shell scripts <em>aws-iam-create-user.sh </em>and the <em>users.csv</em> files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*rZWpkYU3y55L0ya62J57fg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*typAmAPSxt3TmeIhjwlVqg.png" /></figure><p>Please find below the content of the shell script for your reference.</p><pre>#!/bin/bash<br># Purpose: Automated user creation in the AWS<br># How to: ./aws-iam-create-user.sh &lt;entry file format .csv&gt;<br># Entry file column name: user, group, password<br># Author: Jean Rodrigues<br># ------------------------------------------<br><br>INPUT=$1<br>OLDIFS=$IFS<br>IFS=&#39;,;&#39;<br><br>[ ! -f $INPUT ] &amp;&amp; { echo &quot;$INPUT file not found&quot;; exit 99; }<br><br>command -v dos2unix &gt;/dev/null || { echo &quot;dos2unix tool not found. Please, install dos2unix tools before running the script.&quot;; exit 1; }<br><br>dos2unix $INPUT<br><br>while read -r user group password || [ -n &quot;$user&quot; ]<br>do<br>    if [ &quot;$user&quot; != &quot;user&quot; ]; then<br>     aws iam create-user --user-name $user<br>        aws iam create-login-profile --password-reset-required --user-name $user --password $password<br>        aws iam add-user-to-group --group-name $group --user-name $user<br> fi<br><br>done &lt; $INPUT<br><br>IFS=$OLDIFS</pre><p>Change the permissions of the script file so that it is executable using the following command</p><pre>chmod +x aws-iam-create-user.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*wAHOwViM_vJYs87hDozgNg.png" /></figure><p>Now let&#39;s pass the <em>users.csv</em> file as a parameter to the shell script using the following command</p><pre>./aws-iam-create-user.sh users.csv</pre><p>You should see the users getting created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*0VtRawSo49LW7NLlGrLXcg.png" /></figure><p>and if the script fully worked correctly you’ll see users populated within the User groups you created earlier, as well as seeing the correct users within the correct groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*ijvZSubTDE8VvcMtmoBWyw.png" /></figure><p>Now that the users are created let&#39;s go ahead and make one more change to the user groups which would be the ability to change their own passwords. We can do this by going to the <em>policies </em>section under <em>Access management</em> within the IAM dashboard and searching for <em>IAMUserChangePassword </em>policy and applying it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*zRy6PSE5-6UBEqDfesXJiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alyMpJaeacQJefUt3InHYg.png" /></figure><p>Then select the policy and click on <em>Actions → Attach</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*X8bXfnuuYhrX2wS21I-YdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WgBAUpUvYcIu2xR60bQ4GQ.png" /></figure><p>Filter by <em>groups </em>on the next screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cyuzT_HvrqgnIUSxCQhLqw.png" /></figure><p>Select all the groups you want to assign the policy to and click on <em>Attach policy</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*6BWRiNTrys38wU-qk7e4ZQ.png" /></figure><p>We should see the policy add to the user group if we see the details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uFkBy_S3BOraBzJA3PiPw.png" /></figure><p>Next, I tested if a user could log in and change their own password. From the IAM Dashboard, I used the Sign-in URL for IAM users in an Incognito Browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1dVurXiaHN3l7r1RrJNDQA.png" /></figure><p>Entered the username and password that was defined within the CSV file.</p><blockquote>IAM username: jane.doe</blockquote><blockquote>Password: ChangeMe123456!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*IHZViq26uF1zOMLFmfvijg.png" /></figure><p>On the next page, I reset the password with <em>ChangeMe12345!</em> And clicked <em>Confirm password change</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*0F8_ZJG7MhMZdLGtXOuFSA.png" /></figure><p>And successfully logged in as <em>jane.doe</em> user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*lbcn-ndyFhEF5Pl88CdD3A.png" /></figure><p>Verified the IAM policy was in effect by trying to access IAM and as expected I got the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mutbu19nBul60ZzCh0bChw.png" /></figure><p>I logged out and implemented security best practices for users.</p><p><strong>Security best practices</strong>:</p><p>It’s best practice to enable Multi-factor Authentication (MFA) for the root user of your AWS account. One requirement is a device or app that could generate a token number. I used the Google Authenticator App.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*5YFVe8ZLvAwHwe_k" /></figure><p>In the AWS Console, I navigated to <em>IAM → Add MFA → Activate MFA</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*gz8qAcrI2Q8WgG4O9VsYow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T6nmO_TQqcg6w_vwc-lfNg.png" /></figure><p>Then I entered a name selected <em>Virtual MFA device</em> and clicked <em>Continue</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*3RsJPFQKP-1KjAe3_FjMbQ.png" /></figure><p>I then used the Authenticator app on my phone to scan the QR code and entered two sets of MFA codes and clicked <em>Assign MFA</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*z_6rC_M9Bz3Yn_UFe2Lkdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*6h9UGe4swFrOWQGeoMvU_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CDUnlvIfVugbi6joE0biNA.png" /></figure><p>Second, it’s also best practice for each user to have MFA activated to protect the account from being compromised. I accomplished this by adding a customer-managed MFA policy to each group which would apply to every user.</p><p>I navigated to <em>Policies -&gt; Create policy -&gt; JSON </em>and added the following<em>:</em></p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;AllowViewAccountInfo&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: &quot;iam:ListVirtualMFADevices&quot;,<br>            &quot;Resource&quot;: &quot;*&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;AllowManageOwnVirtualMFADevice&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iam:CreateVirtualMFADevice&quot;,<br>                &quot;iam:DeleteVirtualMFADevice&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;arn:aws:iam::*:mfa/${aws:username}&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;AllowManageOwnUserMFA&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iam:DeactivateMFADevice&quot;,<br>                &quot;iam:EnableMFADevice&quot;,<br>                &quot;iam:GetUser&quot;,<br>                &quot;iam:ListMFADevices&quot;,<br>                &quot;iam:ResyncMFADevice&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;arn:aws:iam::*:user/${aws:username}&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;DenyAllExceptListedIfNoMFA&quot;,<br>            &quot;Effect&quot;: &quot;Deny&quot;,<br>            &quot;NotAction&quot;: [<br>                &quot;iam:ListUsers&quot;,<br>                &quot;iam:CreateVirtualMFADevice&quot;,<br>                &quot;iam:EnableMFADevice&quot;,<br>                &quot;iam:GetUser&quot;,<br>                &quot;iam:ListMFADevices&quot;,<br>                &quot;iam:ListVirtualMFADevices&quot;,<br>                &quot;iam:ResyncMFADevice&quot;,<br>                &quot;iam:ChangePassword&quot;,<br>                &quot;iam:CreateUser&quot;,<br>                &quot;iam:CreateLoginProfile&quot;,<br>                &quot;iam:AddUserToGroup&quot;,<br>                &quot;sts:GetSessionToken&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;,<br>            &quot;Condition&quot;: {<br>                &quot;BoolIfExists&quot;: {<br>                    &quot;aws:MultiFactorAuthPresent&quot;: &quot;false&quot;<br>                }<br>            }<br>        }<br>    ]<br>}</pre><p>then <em>Next: tags → Next: review</em> and entered the name for the policy as <em>EnforceMFAPolicy</em> and clicked <em>Create policy</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lv5RCZJsDmATphdVeZfE2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_q9eWQwBoLfCBgzIIyk5EQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzD9er3FcHxiGsYY6VlBAg.png" /></figure><p>From here I selected this policy and attached it to each group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iQOhj2kb5DRlS6ntUUl5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ro2NMkbCYzFx-223GUwBw.png" /></figure><p>Then selected all the groups and clicked <em>Attach policy</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zvef5ifdHu5JZcaVC9RMpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vj1Z1BKQhwo4XdNx4tJDDA.png" /></figure><p>From this point forward every user would NOT be allowed to create any resource(s) that they are allowed to until they have activated MFA. For example, DBA user jane.doe cannot create an RDS instance before MFA activation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_e3X_MSRE1s4V_UBkG6SBQ.png" /></figure><p>Also following best practice, I modified the password policy for the users.<em> IAM →Account settings → Change</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*BLKPicsom18Rcj4KtSIzcg.png" /></figure><p>Saving these changes, we’ll now be able to allow our employees to start logging in, setting up MFA, and changing their passwords.</p><p>Congratulations! We’ve successfully migrated an on-premises user dataset to AWS and ensured that we implemented security best practices, from least privileges, MFA, and even password policies.</p><p>Below is the solution architecture for this exercise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKYC4ASxZtvm01SHfRP0yA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee14728e9812" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automation of a talent onboarding web application using HTML/CSS/JS (frontend) with Python Flask…]]></title>
            <link>https://medium.com/@markiv247/automation-of-a-talent-onboarding-web-application-using-html-css-js-frontend-with-python-flask-5aa67f865c42?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/5aa67f865c42</guid>
            <category><![CDATA[python-flask]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 23:11:05 GMT</pubDate>
            <atom:updated>2022-11-19T23:11:05.627Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automation of a talent onboarding web application using HTML/CSS/JS (frontend) with Python Flask (backend) using Cloud Storage and Cloud Function showcasing serverless</h3><p>In this exercise based on a real-world scenario, I deployed a Web Application to automate the HR onboarding process. By filling out a form, the user is created in the Training Portal in a fully automated way.</p><p>To deploy this solution, I used a Moodle image available on GCP Marketplace, where the REST API had been enabled, running on Compute Engine, the front end on Cloud Storage, and the back-end on Cloud Run.</p><p>I deployed the backend using Python Flask using Cloud Functions, 100% Serverless. Then, I deployed the front end using HTML/CSS/JS on Cloud Storage to store the static files of the Web Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*y60gcTNj38dl8Y37TtWGYw.png" /></figure><h4>Prerequisite</h4><p>In my previous <a href="https://medium.com/@markiv247/deployment-of-a-corporate-training-portal-on-gcp-using-deployment-manager-google-compute-engine-6391f89e7da3">post</a> we set up the training portal on GCP. Please go through the same before taking on the following post.</p><h4>Web service plugin on Moodle</h4><p>In order for the Web Application and Moodle to communicate I had to enable the Web Service in Moodle. I logged in with the user, “admin” and password which I got from the Deployment Manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*NtDd3DD_fWhaZDij" /></figure><p>I navigated to <em>Site administration -&gt; Server</em> -&gt; <em>Web services</em> towards the bottom of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qa0u8p-m6LHuSMMJioi7vw.png" /></figure><p>From this page, a few services need to be enabled. I enabled <em>web services (Step 1)</em> and <em>protocols</em> <em>‘rest’</em> (Step 2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjg8DP9A42IfNSCEo2lHdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N8GvOjcS_TDPOPTSHkCzIQ.png" /></figure><p>Next, I selected <em>Select a service</em> (Step 5).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*2zOegdbPLREXF4V1YmYwYw.png" /></figure><p>On the next screen, I clicked on “Add” towards the bottom left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzdRcdtaUcZ7-ZeV92TnOg.png" /></figure><p>I filled out the fields and selected the checkboxes as seen below and clicked <em>Add service</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*TacMB1gERBiiUZofs77kwQ.png" /></figure><p>Once completed I went back to Web services and selected <em>Add functions (Step 6)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*PTvA8Qp1F0I5_BQ9hQpWSg.png" /></figure><p>Under <em>Custom services</em> I clicked on <em>Functions</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*GdOnU2v14NjMpkjvkXYGeQ.png" /></figure><p>In the search field, I searched for <em>core_user_create_users</em> and selected it then clicked <em>Add functions</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*I0h8WIGaEPhs0HZ4a8La-Q.png" /></figure><p>This will allow the function to be called from a web service.</p><p>Next in Web Services I selected <em>Select a specific user (Step 7)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*g4kEwvCSYlGpzbGHrZFiyw.png" /></figure><p>It’s good practice to create a specific user and only give privileges to that user, but for now, I used an existing user, <em>Admin</em>. On the next page, I selected Authorised users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*mysKDZzsvzUZpqDsXYf1Kw.png" /></figure><p>On the next page, I selected the <em>Admin</em> user under <em>Not authorized users</em> and clicked <em>Add</em> to move it to the <em>authorised users</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*bOW03DpLEUVuDsA-eCY11w.png" /></figure><p>When the Web Service is called from any external application a token is needed for an HTTP call to be authenticated in order to run Moodle successfully. Therefore, back in Web services, I selected “<em>Create a token for a user (Step 8)”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*cNFS461pe3Qmdepq6l-1SA.png" /></figure><p>On the Create a Token screen select:</p><ul><li>User: <em>Admin User</em></li><li>Service: <em>webservice</em></li></ul><p>Click on <em>Save Changes</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*5MJEh9WKboycE5a1omzxIA.png" /></figure><p>Token is generated as seen below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*nDS1rTbF6UHCR4xLEDN1Mg.png" /></figure><p>Now we shall validate the API was set up correctly with the CURL command and substitute the <em>&lt;moodle-ip-server&gt;</em> and <em>&lt;token-generated&gt;</em> placeholders with the Moodle server IP address and token respectively and run the following command in Cloud Shell.</p><pre>curl -g &quot;http://&lt;moodle-ip-server&gt;/webservice/rest/server.php?wstoken=&lt;token-generated&gt;&amp;moodlewsrestformat=json&amp;wsfunction=core_user_create_users&amp;users[0][username]=929316&amp;users[0][email]=jacksparrow@piratecaribbean.com&amp;users[0][lastname]=Sparrow&amp;users[0][firstname]=Jack&amp;users[0][password]=P!r@te123&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1fAy3JaddpDQwlbiO6PRQ.png" /></figure><p>Basically, the command made an API call to the Moodle web service and passed in the new user parameters. I verified the user was created in Moodle by navigating to <em>Site administrator -&gt; Users -&gt; Browse list of users</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdhCLvqZJKsSlQMANifohw.png" /></figure><p>We have successfully been able to call the API to create a new user. Now let&#39;s take care of the backend service cloud function.</p><p><strong>Deploying a Cloud Function:</strong></p><p>The Cloud Function we are creating would be responsible for executing the code that will create the new user. In GCP I navigated to <em>Cloud Functions</em> under the <em>Serverless </em>category. Click on create function and at this point if needed GCP may remind you that certain APIs may be required which we should be able to enable from the prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*dj0417yBMgPr4Zg6JxNwsQ.png" /></figure><p>Let&#39;s enter the following details in the various sections required.</p><p>Section Basics → Function Name: moodleUserCreate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*MMIjlyLK07IsqhEFKyeiqA.png" /></figure><p>Section Trigger</p><ol><li>Trigger Type: HTTP</li><li>Authentication: Allow unauthenticated invocations</li><li>Check Require HTTPS</li></ol><p>Click Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*ungfV0XnqXBbUWE4O26Ejg.png" /></figure><p>Section Runtime, build, connections, and security settings I added two environment variables</p><ol><li>Name: MOODLE_TOKEN Value: &lt;insert generated token&gt;</li><li>Name: MOODLE_SERVER Value: &lt;insert public IP for moodle server&gt;</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*j5cP_X_7CPoHpLHwev5bjg.png" /></figure><p>then clicked <em>Next</em> and set up the runtime <em>Python 3.8</em> and entry point with <em>receive_request </em>(Function name in the Main.py)</p><p>Update Main.py with the following code</p><pre>import requests<br>import json<br>import os<br>from flask import escape<br>from flask_cors import CORS, cross_origin<br><br>@cross_origin()<br>def receive_request(request):<br>    request_form = request.form<br><br>    if request_form and &#39;inputName&#39; and &#39;inputLastname&#39; and &#39;inputEmail&#39; in request_form:<br>        firstname = request_form[&#39;inputName&#39;]<br>        lastname = request_form[&#39;inputLastname&#39;]<br>        email = request_form[&#39;inputEmail&#39;]<br><br>        result = moodle_user_create(email,firstname,lastname)<br><br>        if result == &#39;success&#39;:<br>            return &#39;Request received successfully.&#39;<br>        else:<br>            print(&#39;RR:ERROR:USER_CREATION_FAILED&#39;)<br>            return &#39;Error, contact your system administrator!&#39;<br>    else:<br>        print(&#39;RR:ERROR:PARAMETER_NOT_FOUND&#39;)<br>        return &#39;Error, contact your system administrator!&#39;<br><br>def moodle_user_create(email,firstname,lastname):<br>    <br>    token = os.environ.get(&#39;MOODLE_TOKEN&#39;)<br>    server = os.environ.get(&#39;MOODLE_SERVER&#39;)<br><br>    function = &#39;core_user_create_users&#39;<br>    url = &#39;http://{0}/webservice/rest/server.php?wstoken={1}&amp;wsfunction={2}&amp;moodlewsrestformat=json&#39;.format(server,token,function)<br><br>    email = email<br>    username = email.split(&quot;@&quot;)[0]<br><br>    users = {&#39;users[0][username]&#39;: username,<br>            &#39;users[0][email]&#39;: email,<br>            &#39;users[0][lastname]&#39;: lastname,<br>            &#39;users[0][firstname]&#39;: firstname,<br>            &#39;users[0][password]&#39;: &#39;P@40ssword123&#39;}<br><br>    try:<br>        response = requests.post(url,data=users)<br>        if &#39;exception&#39; in json.loads(response.text):<br>            print(&#39;Result: &#39; + response.text)<br>            return &#39;error&#39;<br>        else:<br>            print(&#39;Result: &#39; + response.text)<br>            return &#39;success&#39;<br>    except Exception as e:<br>        print(e)<br>        return &#39;error&#39;<br><br></pre><p>And requirements.txt with the following</p><pre># Function dependencies, for example:<br># package&gt;=version<br><br>flask<br>flask-cors<br>requests</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRflLpe0aAq3Up8Jt9Bzqw.png" /></figure><p>Click “Deploy” and wait about 2 to 4 minutes for the code to be deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZdHg4DaemVexUSxAN0eJBQ.png" /></figure><p>Click on the function and then copy the trigger url in the trigger section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*MYCSJf0uVP-oV9GxHjJKzQ.png" /></figure><p>and then verify that the function works by running the following curl command in Cloud Shell to add a user (replace the url you copied)</p><pre>curl -X POST -F &#39;inputName=Vikram&#39; -F &#39;inputLastname=Gopinath&#39; -F &#39;inputEmail=vikramgopinath@mail.com&#39; &lt;insert-the-trigger-URL&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZcgiXfXFjgVKDdpbvK1ZGw.png" /></figure><p>and received “<em>Request received successfully</em>”<em>.</em> I checked the Logs to see what the result of the request was.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5UHX1CacQpAtvYuYjXr_2A.png" /></figure><p>Then browsed the list of users in Moodle and the test user was there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*ktLsbn4Oiiai34TmVl7ohg.png" /></figure><h4>Front End Set Up</h4><p>In my frontend code, I updated the form action attribute in the index.html file with the cloud function trigger URL.</p><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;utf-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;<br>    &lt;meta name=&quot;description&quot; content=&quot;&quot;&gt;<br>    &lt;meta name=&quot;author&quot; content=&quot;&quot;&gt;<br><br>    &lt;title&gt;Talent Management - Onboarding of New Employees&lt;/title&gt;<br><br>    &lt;!-- Bootstrap core CSS --&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css&quot; integrity=&quot;sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm&quot; crossorigin=&quot;anonymous&quot;&gt;<br><br>    &lt;!-- Custom styles for this template --&gt;<br>    &lt;link href=&quot;css.css&quot; rel=&quot;stylesheet&quot;&gt;<br><br>    &lt;script src=&quot;jquery.js&quot;&gt;&lt;/script&gt; <br>    &lt;script src=&quot;jquery.form.js&quot;&gt;&lt;/script&gt; <br> <br>    &lt;script&gt; <br>        $(document).ready(function() { <br>            $(&#39;#form-submit&#39;).ajaxForm(function(response) { <br>                alert(response); <br>                $(&quot;#form-submit&quot;).trigger(&quot;reset&quot;);<br>            }); <br><br>        }); <br>    &lt;/script&gt; <br><br>  &lt;/head&gt;<br><br>  &lt;body&gt;<br>    &lt;form id=&quot;form-submit&quot; class=&quot;form-submit&quot; action=&quot;https://us-central1-test-project-366716.cloudfunctions.net/moodleUserCreate&quot; method=&quot;POST&quot;&gt;<br>      &lt;div class=&quot;text-center mb-4&quot;&gt;<br>        &lt;img class=&quot;mb-4&quot; src=&quot;logo.png&quot; alt=&quot;&quot; width=&quot;72&quot; height=&quot;72&quot;&gt;<br>        &lt;h1 class=&quot;h3 mb-3 font-weight-normal&quot;&gt;Talent Management - Onboarding of New Employees&lt;/h1&gt;<br>        &lt;p&gt;Fill in the new employee&#39;s data to send onboarding information:&lt;/p&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;form-label-group&quot;&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;inputName&quot; name=&quot;inputName&quot; class=&quot;form-control&quot; placeholder=&quot;First name&quot; required autofocus&gt;<br>        &lt;label for=&quot;inputName&quot;&gt;First name&lt;/label&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;form-label-group&quot;&gt;<br>        &lt;input type=&quot;text&quot; id=&quot;inputLastname&quot; name=&quot;inputLastname&quot; class=&quot;form-control&quot; placeholder=&quot;Last name&quot; required autofocus&gt;<br>        &lt;label for=&quot;inputLastname&quot;&gt;Last name&lt;/label&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;form-label-group&quot;&gt;<br>        &lt;input type=&quot;text&quot; type=&quot;email&quot; name=&quot;inputEmail&quot; id=&quot;inputEmail&quot; class=&quot;form-control&quot; placeholder=&quot;E-mail address&quot; required autofocus&gt;<br>        &lt;label for=&quot;inputEmail&quot;&gt;E-mail address&lt;/label&gt;<br>      &lt;/div&gt;<br><br>      &lt;button class=&quot;btn btn-lg btn-primary btn-block&quot; style=&quot;background-color: #0F7FAA&quot; type=&quot;submit&quot;&gt;Sent&lt;/button&gt;<br>      &lt;p class=&quot;mt-5 mb-3 text-muted text-center&quot;&gt;&amp;copy; The Cloud Bootcamp. All rights reserved (Sample site - created for educational purposes only - not allowed to copy, reproduce or distribute.) &lt;/p&gt;<br>    &lt;/form&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Instead of using the console, I used Cloud Shell <em>gsutil</em> command to create my unique Bucket resource to store my web application static files.</p><pre>gsutil mb gs://gl-onb-vikramg</pre><p>and the bucket was created as shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*z2K9bD_uNnqvnKGMEnJV5g.png" /></figure><p>I moved into the frontend folder and uploaded the application static files with the commands:</p><pre>cd gcp-final-project/frontend/<br>gsutil cp * gs://gl-onb-vikramg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*qEreiUFzNbu8VFZecnhQkQ.png" /></figure><p>Files we can see now in the bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*gG9EYjYQi6JPW2TAYxxdEQ.png" /></figure><p>Next, I set the website configuration. It’s recommended to assign specialty pages so I used the <em>gsutil</em> command to set the index.html (MainPageSuffix property) with the -m flag and the 404.html (NotFoundPage) with the -e flag:</p><pre>gsutil web set -m index.html -e 404.html gs://gl-onb-vikramg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zSNGbHDnBraVlFeFsmLc-w.png" /></figure><p>Next I made the objects in the bucket readable and publicly available over the internet with the command:</p><pre>gsutil iam ch allUsers:objectViewer gs://tcb-gl-onb-vikramg</pre><p>I then tested the application Frontend by copying the index.html public URL and executed it in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhzPrg0qUFk0niQl6NP5Dw.png" /></figure><p>I created a new user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gW6QfOMJZTcSbaHHYcxhxQ.png" /></figure><p>And verified the user was added to Moodle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*51mO7oRVQlbJ3itTZLz5jg.png" /></figure><p>This exercise showed a successful implementation of the 100% Serverless web application as depicted in the architecture below. I hope you enjoyed reading it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*ef59wdAaoS-2Eu60adlVgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5aa67f865c42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment of a ‘Corporate Training Portal’ on GCP using Deployment Manager, Google Compute Engine…]]></title>
            <link>https://medium.com/@markiv247/deployment-of-a-corporate-training-portal-on-gcp-using-deployment-manager-google-compute-engine-6391f89e7da3?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/6391f89e7da3</guid>
            <category><![CDATA[deployment-manager]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[moodle]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[gce]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 21:25:52 GMT</pubDate>
            <atom:updated>2022-11-19T21:25:52.692Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deployment of a ‘Corporate Training Portal’ on GCP using Deployment Manager, Google Compute Engine (GCE) &amp; Cloud Storage — Part 1</h3><p>Let’s imagine that you are working as a Cloud Specialist and received the task to deploy a Corporate Training Portal for employees within your company: <strong>Moodle </strong>(the eLearning platform most used around the world).</p><p>For faster provisioning and file storage, we shall use the Deployment manager service. For high availability, we shall use the Cloud Storage service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*M_4X16TcZGhvUJmYMtOMAw.png" /></figure><h4>Moodle Deployment</h4><p>The very first this before we even start the deployment would be to enable the following APIs</p><ol><li>Cloud Deployment Manager V2</li><li>Runtime Configuration.</li></ol><p>Click on <em>API &amp; Services &gt; Enabled APIs &amp; Services</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*w5rMiMmRnivvT8O4dk4S6Q.png" /></figure><p>Click on <em>+ENABLE APIS AND SERVICES</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*1jaZHTc_5hMdvwbhdc36dA.png" /></figure><p>Search for the APIs and click on <em>enable</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tYBf5CbsYSecfYUfTuYBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*BT3u-15MdawzQDBfDCQ2dg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WfC-yJT-J7CpE6s2yLIQvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*lsaBhJUlzdftYA4pDgWhgQ.png" /></figure><p>Access the Deployment manager by clicking on <em>Deployment Manager </em>which should be under the <em>tools</em> menu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*f_Mnj5NTajd9UUDamVyypw.png" /></figure><p>Click on <em>+ DEPLOY MARKETPLACE SOLUTION</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*9jANjUlLyCPgacQnmp1SCw.png" /></figure><p>Search for solutions and type <em>moodle</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*UQiYcqNA0EojqzIau5YHfg.png" /></figure><p>Out of the list displayed once the search is complete go ahead and click on <strong>Moodle </strong>with the line <em>Google Click to Deploy</em> subheading</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*x-ZUHf6LjShZlx_SEW-3bw.png" /></figure><p>Go ahead and click <em>launch</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*Kz9M0AKthb_jPpb2rO98BQ.png" /></figure><p>If you don&#39;t have any required APIs enabled the console would prompt you to enable them. In my case, I did not have to do so. If you encounter the scenario you should be able to enable the required APIs with the click of the <em>enable</em> button on the screen.</p><p>Post this you should receive a screen to enter the details of the deployment. I left everything as default except that I changed the machine type E2-medium to save costs, added an administrator email address, accept the terms of service and click <em>Deploy.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hq4cey-E2LkVcpYsM2l6A.png" /></figure><p>After the deployment was fully provisioned the information about the Moodle site was shown as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlBVGmnt8mqTe3qe2JVKww.png" /></figure><p>The warnings can be seen by clicking on the <em>VIEW DETAILS </em>button. These can be ignored and are generated since the deployment has resources from the Runtime Conifurator service, which is in Bera.</p><p>We can click on the <em>Visit this Site</em> button and enter the admin credentials to login into the deployed application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BtbLPIHLZULlutLtV6pVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EXs7Ldhs8f-iFIKrVZPI7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hDq9-iEMzy7BsvwPvSvEUA.png" /></figure><h4>Cloud Storage</h4><p>We shall use Cloud storage to store all training files for the Moodle Site. Click on <em>Cloud Storage</em> from the console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*1rsxSlXZQVXkQnkjG2SPtw.png" /></figure><p>First, we shall create a bucket with the following details</p><blockquote>Name: moodle-&lt;your name&gt;</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*dIXRokpwYO51OLqGtv22bA.png" /></figure><blockquote>Location Type: Region (us-east4)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*ZmL1MbNseiMxUOcC186u4g.png" /></figure><blockquote>Storage class: Standard</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*JcfI3U-udcoxTWZzqqXxwA.png" /></figure><blockquote>Control access to objects: Uncheck -&gt; Enforce public access prevention on this bucket, Access Control -&gt; fine-grained</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*UT6TbXwqoAAf8_hYpTPcGA.png" /></figure><p>Then click on <em>create</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*bjdCKtczcZCV1cBNdukgXQ.png" /></figure><p>Once the bucket is created you should be shown the bucket details. Click on the <em>UPLOAD FILES</em> link to upload content to your bucket by selecting the files required</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*R1Wr_7aI_6GkkmmGcXvKZg.png" /></figure><p>Post uploading the files the screen should look as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*024bACiwaiByPWgbuXZtgg.png" /></figure><p>Remember when we set the access control to the bucket as fine-grained, therefore need to add permission entry for each object with the following so that they are accessed publicly. Select for each object in your bucket the option to edit access and enter the following</p><blockquote>Entity: Public</blockquote><blockquote>Name: AllUsers</blockquote><blockquote>Access: Reader</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X7ZIihoAGjQr1IdZBU8KLw.png" /></figure><p>Click on add entry and enter the details mentioned above to provide public access and click on <em>save</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*xMgJ5JQo990BA46_hcP3zQ.png" /><figcaption>Repeat the same permissions for all files in the bucket</figcaption></figure><h4>Moodel Administration</h4><p>Remember the moodle website that we logged into let&#39;s go back to that. In case you closed the window you would need to look for the IP address and login details under your Moodle instances in the deployment manager.</p><p>So on the Moodle site homepage click on <em>Site Home</em> -&gt; <em>Add a new course</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ULkB_I5E7plhSgfQXUnBBg.png" /></figure><p>Once you’ve selected that you’ll want to enter the following information, Course full name: <em>Onboarding training for new employees</em> and then the course short name which will be: <em>OTNE. </em>Save the changes you’ve made by clicking on <em>Save and return</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8pY_yUga7f7ifp2HJ_XEfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fmvwjYnRBSkQJ1Xfht7bUg.png" /></figure><p>Next the site logo needed to be changed, so I navigated to <em>Site administration -&gt; Appearance -&gt; Logos</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APFHoIY9cXexHmq35YCXRA.png" /></figure><p>I uploaded the iLearnLogo for both the logo and compact logo and clicked <em>Save changes</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6SoGEdFZXFNp21fEU5D8vQ.png" /></figure><h4>Moodle Customization</h4><p>Let&#39;s now work on the appearance of the site. To do that I went back to Site administration and scrolled down until I found <em>Front page</em> and then clicked on <em>Front Page settings</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*REjPr2tQlZBSh1xD.png" /></figure><blockquote>Full site name: Corporate Training Portal</blockquote><blockquote>Short name: iLearn</blockquote><blockquote>Front page summary: iLearn — Corporate Training Portal</blockquote><p>Then click on <em>Saved changes</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twTdR-X_8t-3Fj_DPkw3xw.png" /></figure><p>Now we just need to validate the changes we’ve made! We’ll do that by logging out and seeing the results and then logging back in for some final changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cc7myGw3wT9N6gj5D1x8TA.png" /></figure><p>I then logged back in to add a new activity page to the course.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*umnx1wqEDXS_Yy1h" /></figure><p>Once logged in I went to <em>Site home</em>, clicked the gear icon to the right, and selected <em>turn editing on</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6sAyg0JlRv4EIt5GOgHStw.png" /></figure><p>Then clicked <em>Add an activity or source</em> to the right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gz3GCj45yv4fFaWumNnWxg.png" /></figure><p>and select <em>Page</em> from the choices. Entered <em>Welcome!</em> for the name and for the page content I clicked on <em>insert or edit an audio/video file</em>, used the Public URL link of the video in the Storage Bucket as the video source URL, and clicked <em>Insert media</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*qpB4HZQZOZ7a3loX2UXC_Q.png" /></figure><p>I also added a <em>Download PDF</em> link at the bottom of the video and used the Public URL of the PDF file in the Storage bucket then clicked <em>Save and display</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZdYaatgHc3U44Lqd2KaYA.png" /></figure><p>You can see the details on the front page of the portal.</p><p>Stay tuned for part 2 of this project. Please see below the solution architecture for the above task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*vhdndkl0oRYWOuHFWw57Ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6391f89e7da3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migration of a stand-alone application and database in VM (Google Compute Engine to a modern…]]></title>
            <link>https://medium.com/@markiv247/migration-of-a-stand-alone-application-and-database-in-vm-google-compute-engine-to-a-modern-912f91e4bef7?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/912f91e4bef7</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cloud-sql]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 02:46:36 GMT</pubDate>
            <atom:updated>2022-11-08T02:46:36.667Z</atom:updated>
            <content:encoded><![CDATA[<h3>Migration of a stand-alone application and database in VM (Google Compute Engine to a modern containerized architecture using Google Kubernetes Engine managed services (APP) + Cloud SQL (DB) with HA</h3><p>If you remember one of my previous <a href="https://medium.com/@markiv247/migrate-a-virtual-machine-across-continents-using-storage-snapshot-through-gcps-internal-private-8f442cf5cbb1">posts </a>we migrated an application and database from one region to another. What if we were to do the same but modernize the same as well? How do we go about doing that? Let’s try that out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*lPH7H_U2PHi-iGDffAQ6gw.png" /></figure><p>So the very first thing we need to do is create the application and database VMs. Since the last time, we used the console to create the VMs let&#39;s try a different approach this time. We shall use the gcloud shell.</p><p>Run the following commands to create the application and database VMs. we will make sure to keep certain properties the same in the VMs. I have kept the differences between the two commands in <strong>BOLD</strong></p><ol><li>Zone: australia-southeast2-c</li><li>Machine Type: n1-standard-1</li><li>Image: debian-10-buster-v202220621</li><li>Boot Disk Size: 10 GB</li><li>Boot Disk Type: Standard</li></ol><pre>gcloud compute instances create <strong>aus-app01</strong> --project=$DEVSHELL_PROJECT_ID --zone=australia-southeast2-c --machine-type=n1-standard-1 --image=debian-10-buster-v20220621 --image-project=debian-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=<strong>aus-app01</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMSrjIEBBbLnILDPoMInrw.png" /></figure><pre>gcloud compute instances create <strong>aus-db01</strong> --project=$DEVSHELL_PROJECT_ID --zone=australia-southeast2-c --machine-type=n1-standard-1 --image=debian-10-buster-v20220621 --image-project=debian-cloud --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=<strong>aus-db01</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lj5LKLLPRXXie-Pgq2_14w.png" /></figure><p>Once the above commands have been run you should see both the VMs with the status running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXWM1dGtThkDxoaWUsCgVA.png" /></figure><p>Now we shall install and set up the database. We will use the SSH connection method for the <em>aus-db01</em> VM that you should be able to access within the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATMl-TNc-S45wbL5GuBjsw.png" /></figure><p>Once inside the SSH shell run the following command to update the OS</p><pre>sudo apt update</pre><p>next, we shall install <a href="https://www.gnu.org/software/wget/">wget</a>, these commands should be familiar as we have done this before in our previous posts.</p><pre>sudo apt-get -y install wget</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*YZ2CaHlMpDq-q8qscNSGVA.png" /></figure><p>now that we have wget installed we shall use the following command to download the MySQL package.</p><pre>wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*4D5-hQctqc67GWzOO5fTkA.png" /></figure><p>lets setup the MySQL package with the following command</p><pre>sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb</pre><p>Select the option <em>OK.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*ONl37Zt8CTl9Ao5vvDZpOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*HBIreoJDF1CsobAL56yyOA.png" /></figure><p>Next, we would like to set up the required keys for our MySQL server</p><pre>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*w8mTghyRtrOCEgqKG-heHQ.png" /></figure><p>Finally, let&#39;s update the OS again post the package updates.</p><pre>sudo apt update</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*ZIdrYUtu7wJKJM7MCJQMWQ.png" /></figure><h4>Installing MySQL</h4><p>We have downloaded the required MySQL package and now we can run the following command to install the same.</p><pre>sudo apt install mysql-server -y</pre><p>Post the installation we want to give our MySQL database a password. For the sake of this exercise, I am going to use <em>welcome1. </em>Feel free to use any password you see fit. You would be asked for the password a few times make sure to enter the one you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*pzVjf2kt1PYKaEEuVhkgmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*lHUpMjD8P4kje-jA91jO8A.png" /></figure><p>During the installation, you would be asked what authentication method you would like to use. Select the <strong>Use Legacy Authentication Method (Retain MySQL 5.x Compatibility)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*pEj8dtlGqHcZP2kGvyZZvQ.png" /></figure><p>Post the installation we will restart the MySQL server using the following command</p><pre>sudo systemctl restart mysql.service</pre><h4>Setting up MySQL</h4><p>After the installation, we will set up the server, import the data and create a user for our application.</p><p>Run the following command to start the setup for the server</p><pre>sudo mysql_secure_installation</pre><p>Make sure to enter N for all the required inputs. The above command would also ask you to enter the password you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*OgFJSPBvQWxBA4xwnBHObw.png" /></figure><p>We shall now import the data into the database. Previously we have used the import file mechanism into the shell this time we shall use the storage bucket to get the sql file. Make sure the path is accurate in your case for the storage bucket.</p><pre>wget https://storage.googleapis.com/&lt;storage-bucket-name&gt;/gcp-storage-db-en.sql</pre><p>Now that we have all we required to import the data let&#39;s connect to MySQL using the root user with the following command</p><pre>mysql -u root -p</pre><p>Enter the password we created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*l1oI6dcnazE0nAi0iOpvlw.png" /></figure><p>Post this we shall create the schema and the corresponding tables. Remember the file we downloaded we can import that file using the following command. Please make sure to replace the filename with the name of your file.</p><pre>source gcp-storage-db-en.sql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*7pFlJH_HxV-1xrUq-0LQog.png" /></figure><p>Now that we have created our schema let&#39;s go ahead and create the user that the application would use to access the schema and the tables. In my case, I have created the user <em>app. </em>Run the following commands to create the user. In your case, if you would like another name for the user or a different password please update the same in the script below and execute.</p><pre>CREATE USER <strong>app</strong>@&#39;%&#39; IDENTIFIED BY &#39;<strong>welcome1</strong>&#39;;<br>GRANT ALL PRIVILEGES ON clinic.* TO <strong>app</strong>@&#39;%&#39;;<br>FLUSH PRIVILEGES;<br>exit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*_Y53hPR5GZzU5r2Yofi2yA.png" /></figure><h4>Setting up the application VM</h4><p>With one side of the coin done let&#39;s start with the other end. Log into the application VM with the SSH</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FtiZMsg9DiBNOQictSQmrA.png" /></figure><p>and first, update the os and install the following packages</p><ol><li>npm</li><li>zip</li><li>wget</li></ol><pre>sudo apt-get update<br><br>sudo apt-get install -y npm<br><br>sudo apt-get install -y zip<br><br>sudo apt-get install -y wget</pre><p>Download the application Node.js source code and unzip the same. In my case, I used a storage bucket where the source was uploaded. One can use this approach or also upload the file into the shell.</p><pre>wget https://storage.googleapis.com/&lt;storage-bucket-name&gt;/gcp-storage-clinic-mid-app.zip<br>unzip gcp-storage-clinic-mid-app.zip</pre><p>From the folder, <em>gcp-storage-clinic-mid-app</em> go ahead and run the following command to edit the <em>index.js</em> file to update the connection details to connect to the database we just set up.</p><pre>nano src/index.js</pre><p>Replace the following details in the middlewares section of the file and save the file.</p><ol><li>host: to the private IP of the vm <em>aus-db01</em></li><li>user: to <em>app </em>(or the user you created with the script)</li><li>password: to <em>welcome1 </em>(or the password you created with the script)</li><li>database: to <em>clinic</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*h-QcUMcd9i2OdxaQvRydjg.png" /><figcaption>before update</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*p6R67UXSYdVx7ML0-XuWSg.png" /><figcaption>after the updates</figcaption></figure><p>From the folder,<em> gcp-storage-clinic-mid-app</em> run the following command to install NPM</p><pre>npm install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*ADjP7_EZoYAH7g1g_N6N1Q.png" /></figure><p>Run the below command to start the Node.js application</p><pre>node src/index.js</pre><p>Now that we have the application and database setup we also need to create a firewall rule to allow TCP connections on port 3000.</p><p>From the <em>Firewall</em> services, click on <em>Create Firewall Rule.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*2oE5DqD5iNBxWrL3TVLGhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*iq0Pr0nFyYLr6QHWG1ojvQ.png" /></figure><p>Use the details below to create the firewall rule</p><ol><li>Name: <em>allow-app-port-3000</em></li><li>Targets: All instances in the network</li><li>Source IP ranges: 0.0.0.0/0</li><li>Select TCP and enter value 3000 for port</li></ol><p>Click on create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LMlNO978_eeD_E0tpjMbQ.png" /></figure><h4>Load database with data</h4><p>For us to view the application we need to make sure we have some test data loaded into the database. Let&#39;s download the data file to the ssh terminal for the database VM <em>aus-db01 </em>using the following command.</p><pre>wget https://storage.googleapis.com/&lt;storage-bucket-name&gt;/gcp-module-db.zip</pre><p>Since we have uploaded a zip file we need to unzip the same. Install the unzip package and go ahead and unzip the file which was uploaded.</p><pre>sudo apt-get install unzip<br>unzip gcp-module-db.zip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*op8vmMU6_BWOhWYNvusuGA.png" /></figure><p>cd into the directory where the file was unzipped and load the SQL file to the database.</p><p>First, let&#39;s log into MySQL using the <em>root </em>user. When prompted enter the password for root which in our case is <em>welcome1</em></p><pre>cd gcp-module-db/database/<br>mysql -u root -p</pre><p>once we are at the MySQL prompt enter the following command to import the data to the database.</p><pre>source load_clinic.sql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*X_a5kdCojMbS54-OxSmwXQ.png" /></figure><h4>Access the application</h4><p>Copy the <strong>public IP</strong> of the instance <strong>aus-app01</strong> and paste it into the browser with port 3000 you should be able to see a set of records on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yTakx7OQXm_9AIaABLu5sA.png" /></figure><h4>Modernization</h4><p>To modernize the database let&#39;s create a Cloud SQL instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*MEaePnnexxvCm_jyj8Eu0Q.png" /></figure><p>Click on <em>+ create instance</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*eIZRbRwemQ9SrbL58OYoew.png" /></figure><p><em>Choose MySQL</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvwNWfprB0AStNpLNp2-fg.png" /></figure><p>Keep note of the following details when creating the instance.</p><ol><li>MySQL version: 5.7</li><li>Region: australia-southeast1</li><li>Enable HA for multiple zones. Primary: australia-southeast1-a Secondary: australia-southeast-b</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*8aOCybASXrSDCRFPv02tUw.png" /></figure><p>We’ll now want to customize the instance, we’re doing this for cost savings as well as to match our current Database VM.</p><p>Select the machine type as lightweight</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*rqZek__Ne-IBh963hQ2KCA.png" /></figure><p>Storage capacity at 10 GB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*QwnCp66SSf0NcXViIWMHqw.png" /></figure><p>We also want to change some settings in the connections tab, just unchecking public IP and checking the Private IP option, and setting our network to our default one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*_VDvcLBtLReA4xueSJ0Z-g.png" /></figure><p>After that click on <em>create instance</em>! Once the instance is created we’ll want to create a database in the instance. Click on the <em>database</em> tab and then click <em>create database</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*pmuf9zPLaVxoSiVu2LBdjA.png" /></figure><p>Enter the database name as <em>clinic </em>and click on <em>create</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*Gttg6P4IWonzV0ygIiq6TA.png" /></figure><p>You should see the database clinic created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*IJUauwpOjUz6zdPqMcipiA.png" /></figure><p>Next, we will create a user for our CloudSQL instance just like we did with our Database VM. Clicking on the user tab and then clicking <em>add user account.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*k9HUT_LJHZg2k28cWoTjiw.png" /></figure><p>Add a user account with the following details.</p><ol><li>User name: app</li><li>Password: welcome1</li><li>Host name: allow any host (%)</li></ol><p>Click Add</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*L7JEX82Xxie2iBAnXnAGbA.png" /></figure><p>New user should show up in the list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*yJbhwpSV0DLEIUL__a8K6w.png" /></figure><h4>Containerizing</h4><p>Now that we’ve gotten our CloudSQL, We’ll need to containerize the application. Let&#39;s first open the cloud shell and download the application files using the wget command as we did earlier and unzip the files.</p><pre>wget https://storage.googleapis.com/&lt;storage-bucket-name&gt;/gcp-module-db.zip<br>unzip gcp-module-db.zip</pre><p>cd into the new directory post the unzip</p><pre>cd gcp-module-db/app</pre><p>Now we shall create a new Docker Image using the following command.</p><pre>docker build -t clinic-app .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*8ZJVNSa0rtTQg-2igLSkSQ.png" /></figure><p>Let&#39;s tag the docker image and upload the same to the container registry with the following command</p><pre>docker tag clinic-app asia.gcr.io/$DEVSHELL_PROJECT_ID/clinic-app:latest</pre><pre>docker push asia.gcr.io/$DEVSHELL_PROJECT_ID/clinic-app:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e47o5RyPND_qV6DNFOi_vg.png" /></figure><p>Now that we have built the image and pushed it over to the registry let&#39;s go ahead and create the Kubernetes cluster. From the Kubernetes Engine services, click on [+] Create &gt; Autopilot cluster &gt; Configure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*dCszmEOXDYY3Iy0keJAzvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O7Nti-GMO16xbDxDowRjrA.png" /></figure><p>Set the Name as <em>autopilot-cluster-1</em> Region as <em>australia-southeast1</em> and Click on <em>Create</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pem5v8mYzZdIj7QihOCXzg.png" /></figure><p>While the cluster is getting created let&#39;s go ahead and download the YAML file that we will use for the deployment of the application using Kubernetes.</p><pre>wget https://storage.googleapis.com/&lt;storage-bucket-name&gt;/clinic.yaml</pre><p>Once we have the YAML file we need to update some details in the file. update the Private IP (DBHOST) of the cloud SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OiH1Va13QCNZgJNUQeQplw.png" /></figure><p>image path to point to the docker image we just created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2CoQJp1iRHf1PYOSpJxXTA.png" /></figure><p>The updated yaml should look something like below. Updated areas are highlighted in bold.</p><pre>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: clinic<br>spec:<br>  ports:<br>  - port: 3000<br>  selector:<br>    app: clinic<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: clinic<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: clinic<br>  strategy:<br>    rollingUpdate:<br>      maxSurge: 1<br>      maxUnavailable: 1<br>  minReadySeconds: 5 <br>  template:<br>    metadata:<br>      labels:<br>        app: clinic<br>    spec:<br>      containers:<br>      - name: clinic<br>        image: <strong>asia.gcr.io/test-project-366716/clinic-app:latest</strong><br>        ports:<br>        - containerPort: 3000<br>        resources:<br>          requests:<br>            cpu: 100m<br>            memory: 100Mi<br>        env:<br>        - name: DBHOST<br>          value: &quot;<strong>10.100.0.2</strong>&quot;<br>        - name: DBUSER<br>          value: &quot;app&quot;<br>        - name: DBPW<br>          value: &quot;welcome1&quot;<br>        - name: DBPORT<br>          value: &quot;3306&quot;<br>        - name: DBNAME<br>          value: &quot;clinic&quot;<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: clinic<br>spec:<br>  type: LoadBalancer<br>  ports:<br>  - protocol: TCP<br>    port: 80<br>    targetPort: 3000<br>  selector:<br>    app: clinic</pre><p>Let&#39;s connect to the cluster from the console. Go to Console &gt; GKE &gt; the created cluster &gt; Connect</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gm3Hz3Mt--dNcyZGkgLdfw.png" /></figure><p>Click run in cloud shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sscmspA_vYUB6rWurffekg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BTmapN9Cj5EQPUpKGL6JmA.png" /></figure><p>Let&#39;s deploy the application yaml we just edited. Run the following command</p><pre>kubectl apply -f clinic.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pa-oIw23DuG3dcV71QuibQ.png" /></figure><h4>Migrate database</h4><p>We’ve now modernized our application let&#39;s go ahead and turn off the GCE aus-app01. Before we shut down the Database VM we’ll need to dump the data into a <em>.sql</em> file. Access the aus-db-1 instance via SSH and run the following command. Enter the password when requested.</p><pre>mysqldump --add-drop-table -u root -p clinic &gt; clinic.sql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*qKP3UCBJH_RSgzmXE8XnZw.png" /></figure><p>Let&#39;s import the data into the Cloud SQL DB using the following command.</p><pre>mysql -u app -p -h &lt;PRIVATE_IP_CLOUDSQL&gt; clinic &lt; clinic.sql</pre><p>To ensure we have no errors with the unicode we’ll use this command.</p><pre>sed -e &#39;s/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g&#39; -i clinic.sql</pre><p>Let&#39;s try importing again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*KjL-wShLyrKM3QMzATAp2w.png" /></figure><p>Let&#39;s connect to Cloud SQL DB and check the imported data using the following command to connect</p><pre>mysql -u app -p -h &lt;PRIVATE_IP_CLOUDSQL&gt;<br>use clinic;<br>select * from patient;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*8PLAkEVpxl3FOoj1IY0o-g.png" /></figure><p>We can see that the data is migrated to the Cloud SQL database.</p><p>Now let&#39;s connect to the application with the external IP of the load balancer. Go to <em>GKE &gt; Services &amp; Ingress &gt; click</em> on the endpoint of your application to see the application loading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AmjZcNupN0omqUBIQeCzdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wL8MicgVW91lNcUzGLNoYg.png" /></figure><p>Great we are now accessing the application through our created cluster and not the GCE.</p><h4>Test Failover</h4><p>Now how do we go about testing the HA of the DB? Follow the steps below</p><ul><li>Access the Cloud SQL</li><li>Access the Cloud SQL instance</li><li>Click on Failover</li><li>Check the name of the instance;</li><li>Then, click on Trigger Failover.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CRVxQHUovQsMS4IdR6fvbg.png" /></figure><p>In the <strong>Configuration</strong> section, pay attention that the zone will be changed after the failover process finish!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFBm-G9SndS6l2cBsmIaDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*XwnZZAAdnOMvPqMo9WlFWQ.png" /></figure><p>During the <strong>failover</strong> process, try to access the application, by refreshing the browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNC9irLUcIS4lyfos_qqlA.png" /></figure><p>It means that the application is not able to connect to the DB. The failover process takes less than 2 minutes. Refresh until the connection is re-established after failover.</p><p>The above solution architecture is denoted below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VIiOsFV8mhoPVtfRW8Eiyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=912f91e4bef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment of Load Balancing between regions for HA and distribution of traffic based on…]]></title>
            <link>https://medium.com/@markiv247/deployment-of-load-balancing-between-regions-for-ha-and-distribution-of-traffic-based-on-56a8abb36f39?source=rss-fd35de0d6202------2</link>
            <guid isPermaLink="false">https://medium.com/p/56a8abb36f39</guid>
            <category><![CDATA[traffic-optimization]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[high-availability]]></category>
            <dc:creator><![CDATA[Vikram Gopinath]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 16:54:12 GMT</pubDate>
            <atom:updated>2022-11-04T16:19:30.824Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deployment of Load Balancing between regions for HA and distribution of traffic based on proximity/location</h3><p>How would one go about designing a solution to distribute the application access and inbound traffic between two regions?</p><p>Can we achieve this with a 100% serverless architecture with high global availability and split the application across two continents in case of failure?</p><p>In addition, can we also distribute the traffic intelligently based on the proximity and location of the end user?</p><p>The answer to the above problem is WE CAN!!! <a href="https://cloud.google.com/load-balancing">Load Balancing</a> is what we need to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*gvg5Ra3saMKUAs-uLKt-Bw.png" /></figure><p>Following are the pre-requisuites APIs we need to make sure are enabled in our GCP console.</p><blockquote>Compute Engine API</blockquote><blockquote>Cloud Build API</blockquote><blockquote>Cloud Run API</blockquote><p>I’m sure by now we are aware of how we can enable APIs in GCP. If not, please refer to one of the earlier posts where I have shown how we can enable specific APIs.</p><p>For the purposes of this exercise, I need to upload the applications for both specific regions to GCP. I can do this in numerous ways. Upload the zip files to the gcloud shell or upload the zip files to a storage bucket and use <em>wget </em>to pull them into my shell. For the purposes of this demo, I have used <em>wget.</em></p><p>The regions I have chosen for this exercise are Finland (Europe) and USA (Americas)</p><p>Following commands would pull the region-specific apps to the shell. I have hidden the storage bucket</p><pre>wget https://storage.googleapis.com/xxxx/gcp-module-lb-files-app-usa.zip<br>wget https://storage.googleapis.com/xxxx/gcp-module-lb-files-app-finland.zip</pre><p>Once the files are available in the shell let&#39;s go ahead and unzip the same.</p><pre>unzip gcp-module-lb-files-app-finland.zip<br>unzip gcp-module-lb-files-app-usa.zip</pre><h4>Create Containers</h4><p>We will first build the application container image for the Finland region.</p><p>I <em>cd </em>into the Finland region application folder. This folder contains the <em>Dockerfile </em>which we will use to build the container</p><pre>cd ~/gcp-module-lb-files-app-finland</pre><p>Run the below gcloud build command to create a new container image and further upload it to the google cloud registry</p><pre>gcloud builds submit --tag gcr.io/$DEVSHELL_PROJECT_ID/appfinland</pre><p>The <em>$DEVSHELL_PROJECT_ID </em>environment variable gets the current project ID. I authorize Cloud Shell to use the credentials for the gcloud command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*qWeU8M6aQ6Fcj6Vs" /></figure><p>After we see the <em>STATUS: SUCCESS</em> message on the shell we shall try and deploy the container using Google Cloud Run. Run the following command to deploy the application on port 5000</p><pre>gcloud run deploy --image gcr.io/$DEVSHELL_PROJECT_ID/appfinland --port 5000 --platform managed</pre><p>Press enter to confirm the default application name <em>appfinland, s</em>elect the region <em>europe-north1</em> by typing the number <em>13 </em>and allow unauthenticated requests by typing <em>y.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rj2twH8PRNNalwj7TH9kUA.png" /></figure><p>I verified the application using the service URL printed on the console. As you can see at the bottom of the page a Finland flag denotes the application is from the Finland region</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9d4scV_cHEcdCbv6QEf0Xw.png" /></figure><p>Repeat the same steps for the usa application with a few changes</p><ol><li>Image Name: <em>appusa</em></li><li>Deployment Region: <em>us-central1(#27)</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VQ-3tG3b-kl5wj_dbo0vw.png" /></figure><p>I verified the application using the service URL printed on the console. As you can see at the bottom of the page a USA flag denotes the application is from the USA region</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lpUw1RJsPLYJI6GKVoFndg.png" /></figure><h4>Load balancer</h4><p>Now that we have the two serverless applications up and running in the specific regions let&#39;s load balance the traffic to them. Since we are using serverless Cloud Run applications we shall create <a href="https://cloud.google.com/load-balancing/docs/negs/serverless-neg-concepts">serverless network endpoint groups</a> which specified a group of backend endpoints for a load balancer.</p><p>Run the following commands to create serverless network endpoint groups for each application</p><pre>gcloud compute network-endpoint-groups create sneg-appfinland --region=europe-north1 --network-endpoint-type=serverless --cloud-run-service=appfinland</pre><pre>gcloud compute network-endpoint-groups create sneg-appusa --region=us-central1 --network-endpoint-type=serverless --cloud-run-service=appusa</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuNGE7NCyKPEZGvjAO-PAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZD-FtgwQRh6pPhmetcKTgQ.png" /></figure><p>Next, we shall create a <a href="https://cloud.google.com/load-balancing/docs/backend-service">backend global service</a> (which receives traffic from the load balancer). Run the following command</p><pre>gcloud compute backend-services create app-backend-global --global</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n10DDJjQtK0bxAGsKKMuDQ.png" /></figure><p>Now we shall add the serverless network endpoint group created earlier to the backend global service. Run the following commands to do so.</p><pre>gcloud compute backend-services add-backend app-backend-global --global --network-endpoint-group=sneg-appfinland --network-endpoint-group-region=europe-north1</pre><pre>gcloud compute backend-services add-backend app-backend-global --global --network-endpoint-group=sneg-appusa --network-endpoint-group-region=us-central1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4QwomKX06QIixFD5qffzDA.png" /></figure><p>On the network endpoint group screen, you can see now that the SNEG is in use by the backend global service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YtNpEKz3JYZFHj_f7YxZzw.png" /></figure><p>Now we shall create a <a href="https://cloud.google.com/load-balancing/docs/url-map-concepts">URL map</a> to redirect the incoming requests to the backend global service.</p><pre>gcloud compute url-maps create lb-app-global --default-service app-backend-global</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecu2YJ_W7qseUO91ybuKQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QenPd_EFX35GX-Keai1_ww.png" /></figure><p>Create the <a href="https://cloud.google.com/load-balancing/docs/target-proxies#gcloud:-http">target HTTP(s) proxy</a> to redirect the requests to the URL map.</p><pre>gcloud compute target-http-proxies create lb-app-httpproxy --url-map=lb-app-global</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVWeTcMMljFlBc3moIxcQQ.png" /></figure><p>Reserve a global IP address for the external HTTP load balancer</p><pre>gcloud compute addresses create app-global-ip --ip-version=IPV4 --global</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ak4pLAVG9_kqoftzQcHE-g.png" /></figure><p>Use the below command to check the IP of the <em>app-global-ip</em></p><pre>gcloud compute addresses describe app-global-ip --format=&quot;get(address)&quot; --global</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NWykRNMwQHjkfAT5_Hiyzw.png" /></figure><p>Create a <a href="https://cloud.google.com/load-balancing/docs/forwarding-rule-concepts">global forwarding rule</a> to redirect the incoming requests to the Proxy (frontend)</p><pre>gcloud compute forwarding-rules create app-frontend-global --address=app-global-ip --target-http-proxy=lb-app-httpproxy --global --ports=80</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZRSNsejdE7HAjQOa4TcKqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*Lv16nJc0eC-H9gnfh5vIIA.png" /></figure><p>Now to simulate access from Europe since I am in the US we will use a VPN.</p><p>In the browser, I used the reserved global IP address <em>34.160.70.35</em> and since I’m in the USA the traffic was directed to the USA Serverless Network Endpoint Group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*oxR_9SRRb4O6Obl4UhFX1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*P2oh6W_g36dBdnKLcrWrtg.png" /></figure><p>With the vpn connected to a European country, I was directed to the Finland Serverless Network Endpoint Group when accessing the same global IP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*85yGoHsm08lFMd2CentPEg.png" /></figure><p>Below is a solution architecture of the above exercise for your reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-CRs_G2ODDMgGSUxMVvvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*DQYB6QcI2G_0g6gi0IkUvA.gif" /><figcaption>If you enjoyed reading the article don’t forget to applaud.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56a8abb36f39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>