<?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 Toluwase Makanjuola on Medium]]></title>
        <description><![CDATA[Stories by Toluwase Makanjuola on Medium]]></description>
        <link>https://medium.com/@toluwase2?source=rss-a6121db16f13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pjmdt-bh3uGmc5ehPiEw6w.jpeg</url>
            <title>Stories by Toluwase Makanjuola on Medium</title>
            <link>https://medium.com/@toluwase2?source=rss-a6121db16f13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:04:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@toluwase2/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[Building Elastic Kubernetes Service (EKS) With Terraform — Deploying and Packaging applications…]]></title>
            <link>https://awstip.com/building-elastic-kubernetes-service-eks-with-terraform-deploying-and-packaging-applications-68d7e20ef05f?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/68d7e20ef05f</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 09:15:14 GMT</pubDate>
            <atom:updated>2025-02-06T18:32:48.401Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Elastic Kubernetes Service (EKS) With Terraform — Deploying and Packaging applications with Helm</h3><p>This project seeks to solidify your skills by focusing more on the best practice setup.</p><ol><li>You will use Terraform to create a Kubernetes EKS cluster and dynamically add scalable worker nodes</li><li>You will deploy multiple applications using HELM</li><li>You will experience more Kubernetes objects and how to use them with Helm.</li><li>You will improve upon your CI/CD skills with Jenkins</li></ol><p>Cloud providers such as AWS have managed services for Kubernetes, they have done all the hard work, and with a few API calls to AWS, you can have a production-grade cluster ready to go in minutes. Therefore, in this project, you begin by focusing on <a href="https://aws.amazon.com/eks/">EKS</a>, and how to get it up and running using Terraform. Before moving on to other things.</p><h3>Building EKS with Terraform</h3><p><strong>Note:</strong> Use Terraform version v1.0.2</p><ol><li>Open up a new directory on your laptop, and name it eks</li><li>Use AWS CLI to create an S3 bucket</li><li>Create a file — backend.tf <em>Task for you, ensure the backend is configured for remote state in S3</em></li></ol><pre>terraform {<br>}</pre><ol><li>Create a file — network.tf and provision Elastic IP for Nat Gateway, VPC, Private and public subnets.</li></ol><pre># reserve Elastic IP to be used in our NAT gateway<br>resource &quot;aws_eip&quot; &quot;nat_gw_elastic_ip&quot; {<br>  vpc = true</pre><pre>  tags = {<br>    Name            = &quot;${var.cluster_name}-nat-eip&quot;<br>    iac_environment = var.iac_environment_tag<br>  }<br>}</pre><pre># create VPC using the official AWS module<br>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;</pre><pre>  name = &quot;${var.name_prefix}-vpc&quot;<br>  cidr = var.main_network_block<br>  azs  = data.aws_availability_zones.available_azs.names</pre><pre>  private_subnets = [<br>    # this loop will create a one-line list as [&quot;10.0.0.0/20&quot;, &quot;10.0.16.0/20&quot;, &quot;10.0.32.0/20&quot;, ...]<br>    # with a length depending on how many Zones are available<br>    for zone_id in data.aws_availability_zones.available_azs.zone_ids :<br>    cidrsubnet(var.main_network_block, var.subnet_prefix_extension, tonumber(substr(zone_id, length(zone_id) - 1, 1)) - 1)<br>  ]</pre><pre>  public_subnets = [<br>    # this loop will create a one-line list as [&quot;10.0.128.0/20&quot;, &quot;10.0.144.0/20&quot;, &quot;10.0.160.0/20&quot;, ...]<br>    # with a length depending on how many Zones are available<br>    # there is a zone Offset variable, to make sure no collisions are present with private subnet blocks<br>    for zone_id in data.aws_availability_zones.available_azs.zone_ids :<br>    cidrsubnet(var.main_network_block, var.subnet_prefix_extension, tonumber(substr(zone_id, length(zone_id) - 1, 1)) + var.zone_offset - 1)<br>  ]</pre><pre>  # enable single NAT Gateway to save some money<br>  # WARNING: this could create a single point of failure, since we are creating a NAT Gateway in one AZ only<br>  # feel free to change these options if you need to ensure full Availability without the need of running &#39;terraform apply&#39;<br>  # reference: <a href="https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/2.44.0#nat-gateway-scenarios">https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/2.44.0#nat-gateway-scenarios</a><br>  enable_nat_gateway     = true<br>  single_nat_gateway     = true<br>  one_nat_gateway_per_az = false<br>  enable_dns_hostnames   = true<br>  reuse_nat_ips          = true<br>  external_nat_ip_ids    = [aws_eip.nat_gw_elastic_ip.id]</pre><pre>  # add VPC/Subnet tags required by EKS<br>  tags = {<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot;<br>    iac_environment                             = var.iac_environment_tag<br>  }<br>  public_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/elb&quot;                    = &quot;1&quot;<br>    iac_environment                             = var.iac_environment_tag<br>  }<br>  private_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/internal-elb&quot;           = &quot;1&quot;<br>    iac_environment                             = var.iac_environment_tag<br>  }<br>}</pre><p><strong>Note:</strong> The tags added to the subnets are very important. The Kubernetes Cloud Controller Manager (cloud-controller-manager) and AWS Load Balancer Controller (aws-load-balancer-controller) must identify the clusters. To do that, it queries the cluster’s subnets by using the tags as a filter.</p><ul><li>For public and private subnets that use load balancer resources: each subnet must be tagged</li></ul><pre>Key: kubernetes.io/cluster/cluster-name<br>Value: shared</pre><ul><li>For private subnets that use internal load balancer resources: each subnet must be tagged</li></ul><pre>Key: kubernetes.io/role/internal-elb<br>Value: 1</pre><ul><li>For public subnets that use internal load balancer resources: each subnet must be tagged</li></ul><pre>Key: kubernetes.io/role/elb<br>Value: 1</pre><ol><li>Create a file — variables.tf</li></ol><pre># create some variables<br>variable &quot;cluster_name&quot; {<br>  type        = string<br>  description = &quot;EKS cluster name.&quot;<br>}<br>variable &quot;iac_environment_tag&quot; {<br>  type        = string<br>  description = &quot;AWS tag to indicate environment name of each infrastructure object.&quot;<br>}<br>variable &quot;name_prefix&quot; {<br>  type        = string<br>  description = &quot;Prefix to be used on each infrastructure object Name created in AWS.&quot;<br>}<br>variable &quot;main_network_block&quot; {<br>  type        = string<br>  description = &quot;Base CIDR block to be used in our VPC.&quot;<br>}<br>variable &quot;subnet_prefix_extension&quot; {<br>  type        = number<br>  description = &quot;CIDR block bits extension to calculate CIDR blocks of each subnetwork.&quot;<br>}<br>variable &quot;zone_offset&quot; {<br>  type        = number<br>  description = &quot;CIDR block bits extension offset to calculate Public subnets, avoiding collisions with Private subnets.&quot;<br>}</pre><ol><li>Create a file — data.tf - This will pull the available AZs for use.</li></ol><pre># get all available AZs in our region<br>data &quot;aws_availability_zones&quot; &quot;available_azs&quot; {<br>  state = &quot;available&quot;<br>}</pre><pre>data &quot;aws_caller_identity&quot; &quot;current&quot; {} # used for accesing Account ID and ARN</pre><ol><li>Create a file — eks.tf and provision EKS cluster (<em>Create the file only if you are not using your existing Terraform code. Otherwise you can simply append it to the main.tf from your existing code</em>) <a href="https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/17.1.0">Read more about this module from the official documentation here</a> - Reading it will help you understand more about the rich features of the module.</li></ol><pre>module &quot;eks-cluster&quot; {<br>  source           = &quot;terraform-aws-modules/eks/aws&quot;<br>  version          = &quot;17.1.0&quot;<br>  cluster_name     = &quot;${var.cluster_name}&quot;<br>  cluster_version  = &quot;1.20&quot;<br>  write_kubeconfig = true</pre><pre>  subnets = module.vpc.private_subnets<br>  vpc_id  = module.vpc.vpc_id</pre><pre> worker_groups_launch_template = local.worker_groups_launch_template</pre><pre>  # map developer &amp; admin ARNs as kubernetes Users<br>  map_users = concat(local.admin_user_map_users, local.developer_user_map_users)<br>}</pre><ol><li>Create a file — worker-nodes.tf - This is used to set the policies for autoscaling. To save as much as 90% of the cost we will use Spot Instances - <a href="https://aws.amazon.com/blogs/containers/cost-optimization-for-kubernetes-on-aws/">Read more here</a></li></ol><pre># add spot fleet Autoscaling policy<br>resource &quot;aws_autoscaling_policy&quot; &quot;eks_autoscaling_policy&quot; {<br>  count = length(local.worker_groups_launch_template)</pre><pre>  name                   = &quot;${module.eks-cluster.workers_asg_names[count.index]}-autoscaling-policy&quot;<br>  autoscaling_group_name = module.eks-cluster.workers_asg_names[count.index]<br>  policy_type            = &quot;TargetTrackingScaling&quot;</pre><pre>  target_tracking_configuration {<br>    predefined_metric_specification {<br>      predefined_metric_type = &quot;ASGAverageCPUUtilization&quot;<br>    }<br>    target_value = var.autoscaling_average_cpu<br>  }<br>}</pre><ol><li>Create a file — locals.tf to create local variables. Terraform does not allow assigning variable to variables. There are good reasons for that to avoid repeating your code unnecessarily. So a terraform way to achieve this would be to use locals so that your code can be kept <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a></li></ol><pre># render Admin &amp; Developer users list with the structure required by EKS module<br>locals {<br>  admin_user_map_users = [<br>    for admin_user in var.admin_users :<br>    {<br>      userarn  = &quot;arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/${admin_user}&quot;<br>      username = admin_user<br>      groups   = [&quot;system:masters&quot;]<br>    }<br>  ]<br>  developer_user_map_users = [<br>    for developer_user in var.developer_users :<br>    {<br>      userarn  = &quot;arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/${developer_user}&quot;<br>      username = developer_user<br>      groups   = [&quot;${var.name_prefix}-developers&quot;]<br>    }<br>  ]<br>  worker_groups_launch_template = [<br>    {<br>      override_instance_types = var.asg_instance_types<br>      asg_desired_capacity    = var.autoscaling_minimum_size_by_az * length(data.aws_availability_zones.available_azs.zone_ids)<br>      asg_min_size            = var.autoscaling_minimum_size_by_az * length(data.aws_availability_zones.available_azs.zone_ids)<br>      asg_max_size            = var.autoscaling_maximum_size_by_az * length(data.aws_availability_zones.available_azs.zone_ids)<br>      kubelet_extra_args      = &quot;--node-labels=node.kubernetes.io/lifecycle=spot&quot; # Using Spot instances means we can save a lot of money and scale to have even more instances.<br>      public_ip               = true<br>    },<br>  ]<br>}</pre><ol><li>Add more variables to the variables.tf file</li></ol><pre># create some variables<br>variable &quot;admin_users&quot; {<br>  type        = list(string)<br>  description = &quot;List of Kubernetes admins.&quot;<br>}<br>variable &quot;developer_users&quot; {<br>  type        = list(string)<br>  description = &quot;List of Kubernetes developers.&quot;<br>}<br>variable &quot;asg_instance_types&quot; {<br>  type        = list(string)<br>  description = &quot;List of EC2 instance machine types to be used in EKS.&quot;<br>}<br>variable &quot;autoscaling_minimum_size_by_az&quot; {<br>  type        = number<br>  description = &quot;Minimum number of EC2 instances to autoscale our EKS cluster on each AZ.&quot;<br>}<br>variable &quot;autoscaling_maximum_size_by_az&quot; {<br>  type        = number<br>  description = &quot;Maximum number of EC2 instances to autoscale our EKS cluster on each AZ.&quot;<br>}<br>variable &quot;autoscaling_average_cpu&quot; {<br>  type        = number<br>  description = &quot;Average CPU threshold to autoscale EKS EC2 instances.&quot;<br>}</pre><ol><li>Create a file — variables.tfvars to set values for variables.</li></ol><pre>cluster_name            = &quot;tooling-app-eks&quot;<br>iac_environment_tag     = &quot;development&quot;<br>name_prefix             = &quot;darey-io-eks&quot;<br>main_network_block      = &quot;10.0.0.0/16&quot;<br>subnet_prefix_extension = 4<br>zone_offset             = 8</pre><pre># Ensure that these users already exist in AWS IAM. Another approach is that you can introduce an iam.tf file to manage users separately, get the data source and interpolate their ARN.<br>admin_users                              = [&quot;dare&quot;, &quot;solomon&quot;]<br>developer_users                          = [&quot;leke&quot;, &quot;david&quot;]<br>asg_instance_types                       = [&quot;t3.small&quot;, &quot;t2.small&quot;]<br>autoscaling_minimum_size_by_az           = 1<br>autoscaling_maximum_size_by_az           = 10<br>autoscaling_average_cpu                  = 30</pre><ol><li>Create file — provider.tf</li></ol><pre>provider &quot;aws&quot; {<br>  region = &quot;us-west-1&quot;<br>}</pre><pre>provider &quot;random&quot; {<br>}</pre><ol><li>Run terraform init</li><li>Run Terraform plan — Your plan should have an output</li></ol><pre>Plan: 41 to add, 0 to change, 0 to destroy.</pre><ol><li>Run Terraform apply</li></ol><p>This will begin to create cloud resources, and fail at some point with the error</p><pre>╷<br>│ Error: Post &quot;http://localhost/api/v1/namespaces/kube-system/configmaps&quot;: dial tcp [::1]:80: connect: connection refused<br>│ <br>│   with module.eks-cluster.kubernetes_config_map.aws_auth[0],<br>│   on .terraform/modules/eks-cluster/aws_auth.tf line 63, in resource &quot;kubernetes_config_map&quot; &quot;aws_auth&quot;:<br>│   63: resource &quot;kubernetes_config_map&quot; &quot;aws_auth&quot; {</pre><p>That is because for us to connect to the cluster using the kubeconfig, Terraform needs to be able to connect and set the credentials correctly.</p><p>To fix this problem</p><ul><li>Append to the file data.tf</li></ul><pre># get EKS cluster info to configure Kubernetes and Helm providers<br>data &quot;aws_eks_cluster&quot; &quot;cluster&quot; {<br>  name = module.eks-cluster.cluster_id<br>}<br>data &quot;aws_eks_cluster_auth&quot; &quot;cluster&quot; {<br>  name = module.eks-cluster.cluster_id<br>}</pre><ul><li>Append to the file provider.tf</li></ul><pre># get EKS authentication for being able to manage k8s objects from terraform<br>provider &quot;kubernetes&quot; {<br>  host                   = data.aws_eks_cluster.cluster.endpoint<br>  cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)<br>  token                  = data.aws_eks_cluster_auth.cluster.token<br>}</pre><ul><li>Rerun the init and plan — This time you will see</li></ul><pre># module.eks-cluster.kubernetes_config_map.aws_auth[0] will be created<br>  + resource &quot;kubernetes_config_map&quot; &quot;aws_auth&quot; {<br>      + data = {<br>          + &quot;mapAccounts&quot; = jsonencode([])<br>          + &quot;mapRoles&quot;    = &lt;&lt;-EOT<br>                - &quot;groups&quot;:<br>                  - &quot;system:bootstrappers&quot;<br>                  - &quot;system:nodes&quot;<br>                  &quot;rolearn&quot;: &quot;arn:aws:iam::696742900004:role/tooling-app-eks20210718113602300300000009&quot;<br>                  &quot;username&quot;: &quot;system:node:{{EC2PrivateDNSName}}&quot;<br>            EOT<br>          + &quot;mapUsers&quot;    = &lt;&lt;-EOT<br>                - &quot;groups&quot;:<br>                  - &quot;system:masters&quot;<br>                  &quot;userarn&quot;: &quot;arn:aws:iam::696742900004:user/dare&quot;<br>                  &quot;username&quot;: &quot;dare&quot;<br>                - &quot;groups&quot;:<br>                  - &quot;system:masters&quot;<br>                  &quot;userarn&quot;: &quot;arn:aws:iam::696742900004:user/solomon&quot;<br>                  &quot;username&quot;: &quot;solomon&quot;<br>                - &quot;groups&quot;:<br>                  - &quot;darey-io-eks-developers&quot;<br>                  &quot;userarn&quot;: &quot;arn:aws:iam::696742900004:user/leke&quot;<br>                  &quot;username&quot;: &quot;leke&quot;<br>                - &quot;groups&quot;:<br>                  - &quot;darey-io-eks-developers&quot;<br>                  &quot;userarn&quot;: &quot;arn:aws:iam::696742900004:user/david&quot;<br>                  &quot;username&quot;: &quot;david&quot;<br>            EOT<br>        }<br>      + id   = (known after apply)</pre><pre>      + metadata {<br>          + generation       = (known after apply)<br>          + labels           = {<br>              + &quot;app.kubernetes.io/managed-by&quot; = &quot;Terraform&quot;<br>              + &quot;terraform.io/module&quot;          = &quot;terraform-aws-modules.eks.aws&quot;<br>            }<br>          + name             = &quot;aws-auth&quot;<br>          + namespace        = &quot;kube-system&quot;<br>          + resource_version = (known after apply)<br>          + uid              = (known after apply)<br>        }<br>    }</pre><pre>Plan: 1 to add, 0 to change, 0 to destroy.</pre><h3>Deploy applications with Helm</h3><p>Earlier on, you experienced the use of manifest files to define and deploy resources like pods, deployments, and services into the Kubernetes cluster. Here, you will do the same thing except that it will not be passed through kubectl. In the real world, Helm is one of the most popular tools to deploy resources into Kubernetes. That is because it has a rich set of features that allows deployments to be packaged as a unit. Rather than have multiple YAML files managed individually - which can quickly become messy.</p><p>A Helm chart is a definition of the resources that are required to run an application in Kubernetes. Instead of having to think about all of the various deployments/services/volumes/configmaps/ etc that make up your application, you can use a command like</p><pre>helm install stable/mysql</pre><p>Helm will make sure all the required resources are installed. In addition, you will be able to tweak the helm configuration by setting a single variable to a particular value and more or less resources will be deployed. For example, enabling slave for MySQL so that it can have read-only replicas.</p><p>Behind the scenes, a helm chart is essentially a bunch of YAML manifests that define all the resources required by the application. Helm takes care of creating the resources in Kubernetes (where they don’t exist) and removing old resources.</p><h4>Lets begin to gradually walk through how to use Helm</h4><ol><li>Parameterizing YAML manifests using Helm templates</li></ol><p>Let’s consider that our Tooling app has been Dockerised into an image tooling-appand that you wish to deploy with Kubernetes. Without helm, you would create the YAML manifests defining the deployment, service, and ingress, and apply them to your Kubernetes cluster using kubectl apply. Initially, your application is version 1, and so the Docker image is tagged as tooling-app:1.0.0. A simple deployment manifest might look something like the following:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: tooling-app-deployment<br>  labels:<br>    app: tooling-app<br>spec:<br>  replicas: 3<br>  strategy: <br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxUnavailable: 1<br>  selector:<br>    matchLabels:<br>      app: tooling-app<br>  template:<br>    metadata:<br>      labels:<br>        app: tooling-app<br>    spec:<br>      containers:<br>      - name: tooling-app<br>        image: &quot;tooling-app:1.0.0&quot;<br>        ports:<br>        - containerPort: 80</pre><p>Now let&#39;s imagine that the developers develop another version of the toolin app, version 1.1.0. How do you deploy that? Assuming nothing needs to be changed with the service or other Kubernetes objects, it may be as simple as copying the deployment manifest and replacing the image defined in the spec section. You would then re-apply this manifest to the cluster, and the deployment would be updated, performing a <a href="https://kubernetes.io/docs/tutorials/kubernetes-basics/update/update-intro/">rolling-update</a>.</p><p>The main problem with this is that all of the values specific to the tooling app — the labels and the image names etc — are mixed up with the entire definition of the manifest.</p><p>Helm tackles this by splitting the configuration of a chart out from its basic definition. For example, instead of hard coding the name of your app or the specific container image into the manifest, you can provide those when you install the “chart” (More on this later) into the cluster.</p><p>For example, a simple templated version of the tooling app deployment might look like the following:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: {{ .Release.Name }}-deployment<br>  labels:<br>    app: &quot;{{ template &quot;name&quot; . }}&quot;<br>spec:<br>  replicas: 3<br>  strategy: <br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxUnavailable: 1<br>  selector:<br>    matchLabels:<br>      app: &quot;{{ template &quot;name&quot; . }}&quot;<br>  template:<br>    metadata:<br>      labels:<br>        app: &quot;{{ template &quot;name&quot; . }}&quot;<br>    spec:<br>      containers:<br>      - name: &quot;{{ template &quot;name&quot; . }}&quot;<br>        image: &quot;{{ .Values.image.name }}:{{ .Values.image.tag }}&quot;<br>        ports:<br>        - containerPort: 80</pre><p>This example demonstrates several features of Helm templates:</p><p>The template is based on YAML, with {{ }} mustache syntax defining dynamic sections. Helm provides various variables that are populated at install time. For example, the {{.Release.Name}} allows you to change the name of the resource at runtime by using the release name. Installing a Helm chart creates a release (this is a Helm concept rather than a Kubernetes concept). You can define helper methods in external files. The {{template “name”}} call gets a safe name for the app, given the name of the Helm chart (but which can be overridden). By using helper functions, you can reduce the duplication of static values (like tooling-app), and hopefully reduce the risk of typos.</p><p>You can manually provide configuration at runtime. The {{.Values.image.name}} value, for example, is taken from a set of default values, or from values provided when you call helm install. There are many different ways to provide the configuration values needed to install a chart using Helm. Typically, you would use two approaches:</p><p>A values.yaml file that is part of the chart itself. This typically provides default values for the configuration, as well as serves as documentation for the various configuration values.</p><p>When providing configuration on the command line, you can either supply a file of configuration values using the -f flag. We will see a lot more on this later on.</p><p><strong>Now let&#39;s setup Helm and begin to use it.</strong></p><p>According to the official documentation <a href="https://helm.sh/docs/intro/install/">here</a>, there are different options for installing Helm. But we will build the source code to create the binary.</p><ol><li><a href="https://github.com/helm/helm/releases">Download the </a><a href="https://github.com/helm/helm/releases">tar.gz file from the project&#39;s Github release page</a>. Or simply use wget to download version 3.6.3 directly</li></ol><pre>wget https://github.com/helm/helm/archive/refs/tags/v3.6.3.tar.gz</pre><ol><li>Unpack the tar.gz file</li></ol><pre>tar -zxvf v3.6.3.tar.gz</pre><ol><li>cd into the unpacked directory</li></ol><pre>cd helm-3.6.3</pre><ol><li>Build the source code using make utility</li></ol><pre>make build</pre><p>If you do not have make installed or for any other reason, you cannot install the tool, simply use the official documentation <a href="https://helm.sh/docs/intro/install/">here</a> for other options.</p><ol><li>Helm binary will be in the bin folder. Simply move it to the bin directory on your system. You can check other tools to know where that is. For example, check where pwd utility is being called from by running which pwd. Assuming the output is /usr/local/bin. You can move the helm binary there.</li></ol><pre>sudo mv bin/helm /usr/local/bin/</pre><ol><li>Check that Helm is installed</li></ol><p>helm version</p><pre>version.BuildInfo{Version:&quot;v3.6+unreleased&quot;, GitCommit:&quot;13f07e8adbc57b0e3f96b42340d6f44bdc8d5016&quot;, GitTreeState:&quot;dirty&quot;, GoVersion:&quot;go1.15.5&quot;}</pre><h4>Deploy Jenkins with Helm</h4><p>Before we begin to develop our helm charts, lets make use of publicly available charts to deploy all the tools that we need.</p><p>One of the amazing things about Helm is the fact that you can deploy applications that are already packaged from a public Helm repository directly with very minimal configuration. An example is <strong>Jenkins</strong>.</p><ol><li>Visit <a href="https://artifacthub.io/packages/search">Artifact Hub</a> to find packaged applications as Helm Charts</li><li>Search for Jenkins</li><li>Add the repository to the helm so that you can easily download and deploy</li></ol><pre>helm repo add jenkins https://charts.jenkins.io</pre><ol><li>Update helm repo</li></ol><pre>helm repo update</pre><ol><li>Install the chart</li></ol><pre>helm install [RELEASE_NAME] jenkins/jenkins --kubeconfig [kubeconfig file]</pre><p>You should see an output like this</p><pre>NAME: jenkins<br>LAST DEPLOYED: Sun Aug  1 12:38:53 2021<br>NAMESPACE: default<br>STATUS: deployed<br>REVISION: 1<br>NOTES:<br>1. Get your &#39;admin&#39; user password by running:<br>  kubectl exec --namespace default -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password &amp;&amp; echo<br>2. Get the Jenkins URL to visit by running these commands in the same shell:<br>  echo http://127.0.0.1:8080<br>  kubectl --namespace default port-forward svc/jenkins 8080:8080</pre><pre>3. Login with the password from step 1 and the username: admin<br>4. Configure security realm and authorization strategy<br>5. Use Jenkins Configuration as Code by specifying configScripts in your values.yaml file, see documentation: <a href="http://configuration-as-code/">http:///configuration-as-code</a> and examples: <a href="https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos">https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos</a></pre><pre>For more information on running Jenkins on Kubernetes, visit:<br>https://cloud.google.com/solutions/jenkins-on-container-engine</pre><pre>For more information about Jenkins Configuration as Code, visit:<br>https://jenkins.io/projects/jcasc/<br></pre><pre>NOTE: Consider using a custom image with pre-installed plugins</pre><ol><li>Check the Helm deployment</li></ol><pre>helm ls --kubeconfig [kubeconfig file]</pre><p>Output:</p><pre>NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION<br>jenkins default         1               2021-08-01 12:38:53.429471 +0100 BST    deployed        jenkins-3.5.9   2.289.3</pre><ol><li>Check the pods</li></ol><pre>kubectl get pods --kubeconfig [kubeconfig file]</pre><p>Output:</p><pre>NAME        READY   STATUS    RESTARTS   AGE<br>jenkins-0   2/2     Running   0          6m14s</pre><ol><li>Describe the running pod (review the output and try to understand what you see)</li></ol><pre>kubectl describe pod jenkins-0 --kubeconfig [kubeconfig file]</pre><ol><li>Check the logs of the running pod</li></ol><pre>kubectl logs jenkins-0 --kubeconfig [kubeconfig file]</pre><p>You will notice an output with an error</p><pre>error: a container name must be specified for pod jenkins-0, choose one of: [jenkins config-reload] or one of the init containers: [init]</pre><p>This is because the pod has a <a href="https://www.magalix.com/blog/the-sidecar-pattern">Sidecar container</a> alongside the Jenkins container. As you can see from the error output, there is a list of containers inside the pod [jenkins config-reload] i.e jenkins and config-reload containers. The job of the config-reload is mainly to help Jenkins reload its configuration without recreating the pod.</p><p>Therefore we need to let kubectl know, which pod we are interested in to see its log. Hence, the command will be updated like:</p><pre>kubectl logs jenkins-0 -c jenkins --kubeconfig [kubeconfig file]</pre><ol><li>Now let&#39;s avoid calling the [kubeconfig file] every time. Kubectl expects to find the default kubeconfig file in the location ~/.kube/config. But what if you already have another cluster using that same file? It doesn&#39;t make sense to overwrite it. What you will do is merge all the kubeconfig files using a Kubectl plugin called [konfig](https://github.com/corneliusweig/konfig) and select whichever one you need to be active.</li><li>Install a package manager for Kubectl called <a href="https://krew.sigs.k8s.io/docs/user-guide/setup/install/">krew</a> so that it will enable you to install plugins to extend the functionality of Kubectl. Read more about it [Here](https://github.com/kubernetes-sigs/krew)</li><li>Install the [konfig plugin](https://github.com/corneliusweig/konfig)</li></ol><ul><li>kubectl krew install konfig</li></ul><ol><li>Import the kubeconfig into the default kubeconfig file. Ensure to accept the prompt to overide.</li></ol><ul><li>sudo kubectl konfig import --save [kubeconfig file]</li></ul><ol><li>Show all the contexts — Meaning all the clusters configured in your kubeconfig. If you have more than 1 Kubernetes cluster configured, you will see them all in the output.</li></ol><ul><li>kubectl config get-contexts</li></ul><ol><li>Set the current context to use for all kubectl and helm commands</li></ol><ul><li>kubectl config use-context [name of EKS cluster]</li></ul><ol><li>Test that it is working without specifying the --kubeconfig flag</li></ol><ul><li>kubectl get po</li></ul><ol><li>Output:</li></ol><ul><li>NAME READY STATUS RESTARTS AGE jenkins-0 2/2 Running 0 84m</li></ul><ol><li>Display the current context. This will let you know the context in which you are using to interact with Kubernetes.</li></ol><ul><li>kubectl config current-context</li></ul><ol><li>Now that we can use it kubectl without the --kubeconfig flag, Let&#39;s get access to the Jenkins UI. (<em>In later projects we will further configure Jenkins. For now, it is to set up all the tools we nee</em>d)</li><li>Some commands were provided on the screen when Jenkins was installed with Helm. See number 5 above. Get the password to the admin user</li></ol><ul><li>kubectl exec --namespace default -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password &amp;&amp; echo</li></ul><ol><li>Use port forwarding to access Jenkins from the UI</li></ol><ul><li>kubectl --namespace default port-forward svc/jenkins 8080:8080</li></ul><ol><li>Go to the browser localhost:8080 and authenticate with the username and password from number 1 above</li></ol><h4>Now setup the following tools using Helm</h4><p>This section will be quite challenging for you because you will need to spend some time researching the charts, reading their documentation, and understanding how to get an application running in your cluster by simply running a helm install command.</p><ol><li>Artifactory</li><li>Hashicorp Vault</li><li>Prometheus</li><li>Grafana</li><li>Elasticsearch ELK using <a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-install-helm.html">ECK</a></li></ol><p>Successfully installing all these 5 tools is a great experience to have.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68d7e20ef05f" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/building-elastic-kubernetes-service-eks-with-terraform-deploying-and-packaging-applications-68d7e20ef05f">Building Elastic Kubernetes Service (EKS) With Terraform — Deploying and Packaging applications…</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring-AWS-Cloud-Solution-For-2-Company-Websites-Using-A-Reverse-Proxy-Technology]]></title>
            <link>https://awstip.com/configuring-aws-cloud-solution-for-2-company-websites-using-a-reverse-proxy-technology-d382857b3c41?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/d382857b3c41</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Sat, 18 Jan 2025 12:10:42 GMT</pubDate>
            <atom:updated>2025-01-19T17:45:38.198Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>NB: This infrastructure setup is not included in the AWS free tier. Therefore, delete all resources created immediately after completing the project. If resources are not deleted, monthly costs may be unexpectedly high. Also, setting up a budget and configuring notifications for when our spending reaches a set limit is highly recommended.</em></blockquote><h3>What is a reverse proxy technology?</h3><p>A reverse proxy is a server, application, or cloud service that intermediates one or more web servers. It intercepts and examines incoming client requests before passing them on to the web server, and then returns the web server’s response to the client.</p><h3>Features of a reverse proxy technology?</h3><ol><li>Intercepts Requests: A reverse proxy catches requests from a user’s browser and relays them to the web server.</li><li>Returns Responses: The reverse proxy gets a response from the web server and sends it back to the user.</li><li>Provides Security: A reverse proxy can shield users from harmful content and prevent malware and ransomware attacks.</li><li>Balances Load: A reverse proxy can spread incoming traffic across multiple servers to avoid overloading any single server.</li><li>Monitors Traffic: A reverse proxy can track and log traffic to web servers, aiding in the detection and prevention of security threats.</li><li>Provides Analytics: A reverse proxy can offer detailed insights into website traffic and usage patterns.</li><li>Manages IP Addresses: A reverse proxy can forward or mask a client’s IP address, enhancing privacy and improving traffic routing.</li><li>Directs Requests: A reverse proxy can route requests based on various parameters, such as the user’s device, location, or network condition.</li></ol><p>In this project, we are building a secure infrastructure inside AWS VPC (Virtual Private Cloud) network for a company (funmi’s Ink) that uses WordPress CMS for its main business website, and a Tooling Website for its DevOps team. As part of the company’s desire for improved security and performance, a decision has been made to use NGINX&#39;s reverse proxy technology to achieve this. Cost, Security, and Scalability are the major requirements for this project. Hence, implementing the architecture designed below, ensures that infrastructure for both websites, WordPress and Tooling, is resilient to Web Server’s failures, can accommodate increased traffic, and, at the same time, has a reasonable cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*XBZDT4uSRBW5VYFbxJcITA.jpeg" /></figure><h3>Starting our AWS Cloud Project</h3><p>A few requirements must be met before we begin: properly configuring our AWS account and Organization Unit. <a href="https://www.youtube.com/watch?v=9PQYCc_20-Q">Watch How To Do This Here</a></p><ol><li>We Created an <a href="https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&amp;all-free-tier.sort-order=asc&amp;awsf.Free%20Tier%20Types=*all&amp;awsf.Free%20Tier%20Categories=*all">AWS Master account</a>. (Also known as Root Account) *Within the Root account, we created a sub-account and named it DevOps. (we used another email address to complete this) *Within the Root account, we created an AWS Organization Unit (OU). and named it Dev. (We will launch Dev resources in there) *We moved the DevOps account into the Dev OU. *We logged into the newly created AWS account using the new email address.</li><li>We created a free domain name for our company at the Freenom domain registrar <a href="https://www.freenom.com/en/index.html?lang=en">here</a>.</li><li>We created a hosted zone in AWS and mapped it to our free domain from Freenom. <a href="https://www.youtube.com/watch?v=IjcHp94Hq8A">Watch how to do that here</a></li></ol><h3>Setting Up a Virtual Private Network (VPC)</h3><h3>We always refer to the architectural diagram and ensure that our configuration is aligned with it.</h3><ol><li>We created a <a href="https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html">VPC</a></li><li>We created subnets as shown in the architecture</li><li>We created a route table and associated it with public subnets</li><li>We created a route table and associated it with private subnets</li><li>We created an <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html">Internet Gateway</a></li><li>We edited a route in the public route table and associated it with the Internet Gateway. (This is what allows a public subnet to be accessible from the Internet)</li><li>We created 3 <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html">Elastic IPs</a></li><li>We created a <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html">Nat Gateway</a> and assign one of the Elastic IPs (*The other 2 will be used by <a href="https://aws.amazon.com/quickstart/architecture/linux-bastion/">Bastion hosts</a>)</li><li>We created a <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#CreatingSecurityGroups">Security Group</a> for:</li></ol><ul><li>Nginx Servers: Access to Nginx should only be allowed from a <a href="https://aws.amazon.com/elasticloadbalancing/application-load-balancer/">Application Load balancer (ALB)</a>. At this point, we have not created a load balancer, therefore we will update the rules later. For now, we just created it and put some dummy records as a placeholder.</li><li>Bastion Servers: Access to the Bastion servers should be allowed only from workstations that need SSH into the Bastion servers. Hence, you can use your workstation public IP address. To get this information, simply go to your terminal and type curl <a href="http://www.canhazip.com/">www.canhazip.com</a></li><li>Application Load Balancer: ALB will be available on the Internet</li><li>Webservers: Access to Webservers should only be allowed from the Nginx servers. Since we do not have the servers created yet, just put some dummy records as a placeholder, we will update it later.</li><li>Data Layer: Access to the Data layer, which is comprised of <a href="https://aws.amazon.com/rds/">Amazon Relational Database Service (RDS)</a> and <a href="https://aws.amazon.com/efs/">Amazon Elastic File System (EFS)</a> must be carefully designed - only webservers should be able to connect to <strong>RDS</strong>, while Nginx and Webservers will have access to <strong>EFS Mountpoint</strong>.</li></ul><h4>Proceed With Compute Resources</h4><p>We need to set up and configure compute resources inside our VPC. The resources related to compute are:</p><ul><li><a href="https://www.amazonaws.cn/en/ec2/instance-types/">EC2 Instances</a></li><li><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/LaunchTemplates.html">Launch Templates</a></li><li><a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html">Target Groups</a></li><li><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html">Autoscaling Groups</a></li><li><a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">TLS Certificates</a></li><li><a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html">Application Load Balancers (ALB)</a></li></ul><h4>Setting Up Compute Resources for Nginx</h4><p>Provision EC2 Instances for Nginx</p><h4>Proceed With Compute Resources</h4><p>You will need to set up and configure compute resources inside your VPC. The resources related to compute are:</p><ul><li><a href="https://www.amazonaws.cn/en/ec2/instance-types/">EC2 Instances</a></li><li><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/LaunchTemplates.html">Launch Templates</a></li><li><a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html">Target Groups</a></li><li><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html">Autoscaling Groups</a></li><li><a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">TLS Certificates</a></li><li><a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html">Application Load Balancers (ALB)</a></li></ul><h4>Set Up Compute Resources for Nginx</h4><p>Provision EC2 Instances for Nginx</p><ol><li>We created an EC2 Instance based on CentOS <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html">Amazon Machine Image (AMI)</a> in any 2 <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html">Availability Zones (AZ) in any AWS Region</a> (<a href="https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/RegionsAndAZs.html">it is recommended to use the Region that is closest to your customers</a>). Use EC2 instance of <a href="https://aws.amazon.com/ec2/instance-types/t2/">T2 family</a> (e.g. t2.micro or similar)</li><li>We ensured that it has the following software installed:</li></ol><ul><li>python</li><li>ntp</li><li>net-tools</li><li>vim</li><li>wget</li><li>telnet</li><li>epel-release</li><li>htop</li></ul><ol><li>We created<a href="https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/tkv-create-ami-from-instance.html"> an </a><a href="https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/tkv-create-ami-from-instance.html">AMI</a> out of the EC2 instance</li></ol><p>Preparing Launch Template For Nginx (One Per Subnet)</p><ol><li>We make use of the AMI to set up a launch template</li><li>We ensured the Instances were launched into a public subnet</li><li>We assigned the appropriate security group</li><li>We configured <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html">Userdata</a> to update yum package repository and install nginx</li></ol><p>Configuring Target Groups</p><ol><li>Select Instances as the target type</li><li>We ensured the protocol HTTPS on secure TLS port 443</li><li>We ensured that the health check path is /healthstatus</li><li>We registered Nginx Instances as targets</li><li>We ensured that health check passes for the target group</li></ol><p>Configuring Autoscaling For Nginx</p><ol><li>We selected the right launch template</li><li>We selected the VPC</li><li>We selected both public subnets</li><li>We enabled Application Load Balancer for the AutoScalingGroup (ASG)</li><li>We selected the target group we created before</li><li>We ensured that we have health checks for both EC2 and ALB</li><li>The desired capacity is 2</li><li>Minimum capacity is 2</li><li>Maximum capacity is 4</li><li>We set <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroupLifecycle.html">scale out</a> if CPU utilization reaches 90%</li><li>We ensured there is an <a href="https://docs.aws.amazon.com/sns/latest/dg/welcome.html">SNS</a> topic to send scaling notifications</li></ol><h4>Setting Up Compute Resources for Bastion</h4><p>We provision the EC2 Instances for Bastion</p><ol><li>We created an EC2 Instance based on CentOS Amazon Machine Image (AMI) per each Availability Zone in the same Region and same AZ where we created the Nginx server</li><li>We ensured that it has the following software installed</li></ol><ul><li>python</li><li>ntp</li><li>net-tools</li><li>vim</li><li>wget</li><li>telnet</li><li>epel-release</li><li>htop</li></ul><ol><li>We a<a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html#using-instance-addressing-eips-associating">ssociated an Elastic IP</a> with each of the Bastion EC2 Instances</li><li>We created an AMI out of the EC2 instance</li></ol><p>Preparing Launch Template For Bastion (One per subnet)</p><ol><li>We Made use of the AMI to set up a launch template</li><li>We ensured the Instances were launched into a public subnet</li><li>We Assigned the appropriate security group</li><li>We configured Userdata to update yum package repository and install Ansible and git</li></ol><p>Configuring Target Groups</p><ol><li>We select Instances as the target type</li><li>We ensured the protocol is TCP on port 22</li><li>We register Bastion Instances as targets</li><li>We ensured that health check passes for the target group.</li></ol><p>Configuring Autoscaling For Bastion</p><ol><li>We selected the right launch template</li><li>We selected the VPC</li><li>We selected both public subnets</li><li>We enabled Application Load Balancer for the AutoScalingGroup (ASG)</li><li>We select the target group we created before</li><li>We ensured that we have health checks for both EC2 and ALB</li><li>The desired capacity is 2</li><li>Minimum capacity is 2</li><li>Maximum capacity is 4</li><li>We set scale out if CPU utilization reaches 90%</li><li>We ensured there is an SNS topic to send scaling notifications</li></ol><h4>Setting Up Compute Resources for Webservers</h4><p>Provisioning the EC2 Instances for Webservers</p><p>Now, we need to create 2 separate launch templates for both the WordPress and Tooling websites</p><ol><li>We created an EC2 Instance (Centos) each for WordPress and Tooling websites per Availability Zone (in the same Region).</li><li>We ensured that it has the following software installed</li></ol><ul><li>python</li><li>ntp</li><li>net-tools</li><li>vim</li><li>wget</li><li>telnet</li><li>epel-release</li><li>htop</li><li>php</li></ul><ol><li>We created an AMI out of the EC2 instance</li></ol><p>Preparing Launch Template For Webservers (One per subnet)</p><ol><li>We made use of the AMI to set up a launch template</li><li>We ensured the Instances are launched into a public subnet</li><li>We assigned the appropriate security group</li><li>Configure Userdata to update yum package repository and install wordpress (<em>Only required on the WordPress launch template</em>)</li></ol><h4>TLS Certificates From <a href="https://aws.amazon.com/certificate-manager/">Amazon Certificate Manager (ACM)</a></h4><p>We need TLS certificates to handle secured connectivity to our Application Load Balancers (ALB).</p><ol><li>We navigate to AWS ACM</li><li>We requested a public wildcard certificate for the domain name we registered in Freenom</li><li>We Used DNS to validate the domain name</li><li>And we tagged the resource</li></ol><h4>Configuring Application Load Balancer (ALB)</h4><p>Application Load Balancer To Route Traffic To NGINX</p><p>Nginx EC2 Instances will have configurations that accept incoming traffic only from Load Balancers. No request should go directly to Nginx servers. With this kind of setup, we will benefit from intelligent routing of requests from the <strong>ALB</strong> to Nginx servers across the 2 Availability Zones. We will also be able to <a href="https://avinetworks.com/glossary/ssl-offload/">offload</a> SSL/TLS certificates on the <strong>ALB</strong> instead of Nginx. Therefore, Nginx will be able to perform faster since it will not require extra compute resources to validate certificates for every request.</p><ol><li>We created an Internet-facing ALB</li><li>We ensured that it listens on HTTPS protocol (TCP port 443)</li><li>We ensured the ALB was created within the appropriate VPC | AZ | Subnets</li><li>We chose the Certificate from ACM</li><li>We selected the Security Group</li><li>We selected Nginx Instances as the target group</li></ol><p>Application Load Balancer To Route Traffic To Web Servers</p><p>Since the webservers are configured for auto-scaling, there is going to be a problem if servers get dynamically scaled out or in. Nginx will not know about the new IP addresses or the ones that get removed. Hence, Nginx will not know where to direct the traffic.</p><p>To solve this problem, we use a load balancer. But this time, it was an internal load balancer. Not Internet facing since the web servers are within a private subnet, and we do not want direct access to them.</p><ol><li>We created an Internal ALB</li><li>We ensured that it listens on HTTPS protocol (TCP port 443)</li><li>We ensured the ALB was created within the appropriate VPC | AZ | Subnets</li><li>We chose the Certificate from ACM</li><li>We selected the Security Group</li><li>We selected webserver Instances as the target group</li><li>We ensured that health check passes for the target group</li></ol><p><strong><em>NOTE:</em></strong> This process was repeated for both WordPress and Tooling websites.</p><h4>Setting up EFS</h4><p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEFS.html">Amazon Elastic File System (Amazon EFS)</a> provides a simple, scalable, fully managed elastic <a href="https://en.wikipedia.org/wiki/Network_File_System">Network File System (NFS)</a> for use with AWS Cloud services and on-premises resources. In this project, we will utilize EFS service and mount filesystems on both Nginx and Webservers to store data.</p><ol><li>We created an EFS filesystem</li><li>We created an EFS mount target per AZ in the VPC, associated it with both subnets dedicated for data layer</li><li>We associate the Security groups created earlier for data layer.</li><li>We created an EFS access point. (Giving it a name and leave all other settings as default)</li></ol><h4>Setting up RDS</h4><p><strong><em>Pre-requisite</em></strong>: We created a KMS key from <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html">Key Management Service (KMS)</a> to be used to encrypt the database instance.</p><p><a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html">Amazon Relational Database Service (Amazon RDS)</a> is a managed distributed relational database service by Amazon Web Services. This web service running in the cloud is designed to simplify the setup, operations, maintenance &amp; scaling of relational databases. <em>Without RDS, Database Administrators (DBA) have more work to do, due to RDS, some DBAs have become jobless</em></p><p>To ensure that our databases are highly available and also have failover support in case one availability zone fails, we configure a <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZ.html">multi-AZ</a> setup of <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html">RDS MySQL database</a> instance. In our case, since we are only using 2 AZs, we can only failover to one, but the same concept applies to 3 Availability Zones. We will not consider possible failure of the whole Region.</p><p>To configure RDS,</p><ol><li>We created a subnet group and added 2 private subnets (data Layer)</li><li>We created an RDS Instance for mysql 8.*.*</li><li>To satisfy our architectural diagram, we will need to select either <strong>Dev/Test</strong> or <strong>Production</strong> Sample Template. But to minimize AWS cost, we select the <strong>Do not create a standby instance</strong> option under <strong>Availability &amp; durability</strong> sample template (<em>The production template will enable Multi-AZ deployment</em>)</li><li>Configuring other settings accordingly (<em>For test purposes, most of the default settings are good to go</em>). In the real world, you will need to size the database appropriately. You will need to get some information about the usage. If it is a highly transactional database that grows at 10GB weekly, you must bear that in mind while configuring the initial storage allocation, storage autoscaling, and maximum storage threshold.</li><li>We configured VPC and security (ensuring the database is not available from the Internet)</li><li>We configured backups and retention</li><li>We encrypt the database using the KMS key created earlier</li><li>We enabled <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/monitoring-cloudwatch.html">CloudWatch</a> monitoring and export Error and Slow Query logs (for production, also include Audit)</li></ol><p><strong>Note</strong> This service is an expensive one. Ensure to review the monthly cost before creating. (<strong><em>DO NOT LEAVE ANY SERVICE RUNNING FOR LONG</em></strong>)</p><h4>Configuring DNS with Route53</h4><p>Earlier in this project, we registered a free domain with Freenom and configured a hosted zone in <a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html"><strong>Route53</strong></a>. But that is not all that needs to be done as far as DNS configuration is concerned.</p><p>We need to ensure that the main domain for the WordPress website can be reached, and the subdomain for the Tooling website can also be reached using a browser.</p><p>Creating other records such as <a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/route-53-concepts.html">CNAME, </a><a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/route-53-concepts.html">alias and </a><a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/route-53-concepts.html">A records</a>.</p><p><strong><em>NOTE</em></strong>: We can use either CNAME or alias records to achieve the same thing. But alias record has better functionality because it is faster to resolve DNS record, and can coexist with other records on that name. You can read <a href="https://support.dnsimple.com/articles/differences-between-a-cname-alias-url/#:~:text=The%20A%20record%20maps%20a,a%20name%20to%20another%20name.&amp;text=The%20ALIAS%20record%20maps%20a,the%20HTTP%20301%20status%20code">here</a> to get to know more about the differences.</p><ul><li>We created an alias record for the root domain and direct its traffic to the ALB DNS name.</li><li>We Created an alias record for tooling.&lt;ourdomain&gt;.com and direct its traffic to the ALB DNS name.</li></ul><h4>Congratulations!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FKh5nvnEteIslKmm" /></figure><p>We have just created a secured, scalable, and cost-effective infrastructure to host 2 enterprise websites using various Cloud services from AWS. At this point, our infrastructure is ready to host real website loads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d382857b3c41" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/configuring-aws-cloud-solution-for-2-company-websites-using-a-reverse-proxy-technology-d382857b3c41">Configuring-AWS-Cloud-Solution-For-2-Company-Websites-Using-A-Reverse-Proxy-Technology</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DEPLOYING A THREE-TIER ARCHITECTURE WEB SOLUTION WITH WORDPRESS ON AWS]]></title>
            <link>https://awstip.com/deploying-a-three-tier-architecture-web-solution-with-wordpress-on-aws-bc04497269a2?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc04497269a2</guid>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[three-tier-architecture]]></category>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Tue, 12 Sep 2023 10:39:57 GMT</pubDate>
            <atom:updated>2023-09-12T18:11:05.477Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Three-tier Architecture?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*fkVvnzgyGAl7PQ-W.jpg" /></figure><p>A three-tier architecture is a client-server architecture in which the functional process logic, data access, computer data storage, and user interface are developed and maintained as independent modules on separate platforms. The three-tier architecture is the most popular implementation of a multi-tier architecture and consists of a single presentation tier, logic tier, and data tier. The following illustration shows an example of a simple, generic three-tier application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*bzJ3MpHd6wkOpP38.png" /></figure><p>*1. Presentation Layer (PL): The user interface, such as the client-server or browser on your laptop.</p><p>*2. Business Layer (BL): This is the backend program that implements business logic. Application or Webserver</p><p>*3. Data Access or Management Layer (DAL): This is the layer for computer data storage and data access. Database Server or File System Server such as FTP server or NFS Server</p><p>In this project, we will have the hands-on experience that showcases Three-tier Architecture while also ensuring that the disks used to store files on the Linux servers are adequately partitioned and managed through programs such as gdisk and LVM respectively.</p><h3>Our 3-Tier Setup</h3><ol><li>A Laptop or PC to serve as a client</li><li>An EC2 Linux Server as a web server (This is where we will install WordPress)</li><li>An EC2 Linux server as a database (DB) server.</li></ol><p>We will work with several storage and disk management concepts; this <a href="https://www.youtube.com/watch?v=2Z6ouBYfZr8">Video</a> provides more insights.</p><blockquote><em>NB: For this project, we are using the RedHat OS to give us a deeper understanding of different Linux distros.</em></blockquote><h3>Launching an EC2 Instance that will serve as a “web server”</h3><p>We Launched an EC2 instance that will serve as a “Web Server.” And create three volumes in the same AZ (Availability Zone) as our Web Server EC2, each of 10 GiB. This <a href="https://www.youtube.com/watch?v=HPXnXkBzIHw">Video</a> shows us How to Add EBS Volume to an EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0gNJRbmPLTsbn1PK.png" /></figure><p>Then we attach all three volumes one by one to our Web Server EC2 instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gfpU_F9LOtnbcacV.png" /></figure><p>After creating our EC2 server and adding the volumes, we connect to the instance using:</p><p>ssh -i &quot;mykey.pem&quot; ec2-user@ec2-34-230-24-179.compute-1.amazonaws.com</p><p>We use lsblk Command to inspect what block devices are attached to the server. We notice the names of our newly created devices. All devices in Linux reside in /dev/ directory. We inspect it with ls /dev/ and make sure we see all three newly created block devices there – their names are xvdf, xvdg, &amp; xvdh as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*tNZ1nCB-vmt3cbQ3.JPG" /></figure><p>Then, we used the df -h command to see all mounts and free space on our server, then we used gdisk utility to create a single partition on each of the three disks with the command:</p><p>sudo gdisk /dev/xvdf</p><p>We follow the utility gdisk utility commands like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/0*s0dOe6LHMt17hzsd.JPG" /></figure><p>Then, we repeat the same steps to create a single partition for the other two drives.</p><p>After successfully creating the partition, we can run the lsblk command again to be sure the partitions were created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*9V8ClUR1Ae7a7WwW.JPG" /></figure><p>This shows that our partitions were successfully created.</p><p>We now proceed to Install lvm2 package using sudo yum install lvm2, then we Run sudo lvmdiskscan command to check for available partitions.</p><blockquote><em>NB: Previously, in Ubuntu we used apt command to install packages, in RedHat/CentOS a different package manager is used, so we used yum command instead.</em></blockquote><p>We used pvcreate utility to mark each of 3 disks as physical volumes (PVs) to be used by LVM</p><pre>sudo pvcreate /dev/xvdf1<br>sudo pvcreate /dev/xvdg1<br>sudo pvcreate /dev/xvdh1</pre><p>To verify that our Physical volume has been created successfully, we run the following:</p><p>sudo pvs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*bP2eJA6j0JqZhCgb.JPG" /></figure><p>We used vgcreate utility to add all 3 PVs to a volume group (VG). And named the VG webdata-vg</p><p>sudo vgcreate webdata-vg /dev/xvdh1 /dev/xvdg1 /dev/xvdf1</p><p>To verify that our volume group is created, we run the following:</p><p>sudo vgs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*NWC26Zm4rVD6ePQc.JPG" /></figure><p>We used lvcreate utility to create 2 logical volumes. apps-lv (using half of the PV size), and logs-lv using the remaining space of the PV size.</p><blockquote><em>NOTE: apps-lv will be used to store data for the Website while, logs-lv will be used to store data for logs.</em></blockquote><pre>sudo lvcreate -n apps-lv -L 14G webdata-vg<br>sudo lvcreate -n logs-lv -L 14G webdata-vg</pre><p>To verify that our Logical Volume has been created successfully, we run the following:</p><p>sudo lvs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/0*8kLQSy7KQlnLrDYR.JPG" /></figure><p>To verify the entire setup, we run the following:</p><pre>sudo vgdisplay -v #view complete setup - VG, PV, and LV<br>sudo lsblk</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*lGROqWr0m7U1nciR.JPG" /></figure><p>We used mkfs.ext4 to format the logical volumes with ext4 filesystem</p><pre>sudo mkfs -t ext4 /dev/webdata-vg/apps-lv<br>sudo mkfs -t ext4 /dev/webdata-vg/logs-lv</pre><p>We created /var/www/html directory to store website files and /home/recovery/logs to store the backup of log data. We then mount /var/www/html on apps-lv logical volume.</p><pre>sudo mkdir -p /var/www/html<br>sudo mkdir -p /home/recovery/logs<br>sudo mount /dev/webdata-vg/apps-lv /var/www/html/</pre><p>We used rsync utility to backup all the files in the log directory /var/log into /home/recovery/logs (This is required before mounting the file system)</p><p>sudo rsync -av /var/log/. /home/recovery/logs/</p><p>We mount /var/log on logs-lv logical volume. (Note that all the existing data on /var/log will be deleted. That is why backing the log files before we mount is important.)</p><p>sudo mount /dev/webdata-vg/logs-lv /var/log</p><p>We then restored our log files into /var/log directory</p><p>sudo rsync -av /home/recovery/logs/log/. /var/log</p><p>We updated the /etc/fstab file so that the mount configuration will persist after restart of the server. The UUID of the device will be used to update the /etc/fstab file;</p><p>sudo blkid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2-P79ifv6wEMBhT2.JPG" /></figure><p>We updated /etc/fstab in the format below using our UUID and we removed the leading and ending quotes.</p><p>sudo vi /etc/fstab</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*PaN-pq0gRhDD8dwK.JPG" /></figure><p>To test the configuration and reload the daemon, we run the following:</p><pre>sudo mount -a<br>sudo systemctl daemon-reload</pre><p>We then verify our setup by running df -h</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*-XUMR1S649dCLzzg.JPG" /></figure><h3>Preparing the Database Server</h3><p>We launched a second RedHat EC2 instance with the role “DB server,” and we repeated the same steps as for the Web Server, but instead of apps-lv, we created db-lv and mounted it to /db directory instead of /var/www/html/.</p><h3>Installing WordPress on our Web Server EC2</h3><p>Firstly, we update the repository by running;</p><p>sudo yum -y update</p><p>We install wget, Apache, and its dependencies;</p><p>sudo yum -y install wget httpd php php-mysqlnd php-fpm php-json</p><p>We started the Apache service with</p><pre>sudo systemctl enable httpd<br>sudo systemctl start httpd</pre><p>To install PHP and its dependencies, we run the following codes:</p><pre>sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm<br>sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm<br>sudo yum module list php<br>sudo yum module reset php<br>sudo yum module enable php:remi-7.4<br>sudo yum install php php-opcache php-gd php-curl php-mysqlnd<br>sudo systemctl start php-fpm<br>sudo systemctl enable php-fpm<br>setsebool -P httpd_execmem 1</pre><p>We then restarted Apache with;</p><p>sudo systemctl restart httpd</p><p>To download WordPress and copy Wordpress to var/www/html we used these commands;</p><pre>mkdir wordpress<br> cd   wordpress<br> sudo wget http://wordpress.org/latest.tar.gz<br> sudo tar xzvf latest.tar.gz<br> sudo rm -rf latest.tar.gz<br> cp wordpress/wp-config-sample.php wordpress/wp-config.php<br> cp -R wordpress /var/www/html/</pre><p>Lastly, we configured SELinux Policies with the command;</p><pre>sudo chown -R apache:apache /var/www/html/wordpress<br>sudo chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R<br>sudo setsebool -P httpd_can_network_connect=1</pre><h3>Installing MySQL on our DB Server EC2</h3><p>Firstly, we update the repository by running;</p><p>sudo yum -y update</p><p>Then we install MySQL server with the command;</p><p>sudo yum install mysql-server</p><p>To verify that the service is up and running, we use</p><p>sudo systemctl status mysqld</p><p>It shows that the service is not yet active and running. To make it active, we use the following commands;</p><pre>sudo systemctl restart mysqld<br>sudo systemctl enable mysqld<br>sudo systemctl status mysqld</pre><p>The image below shows that the service is now up and running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w8Xb3cr0IUVYusIG.JPG" /></figure><h3>Configuring DB to work with WordPress</h3><p>To Create A Database;</p><pre>sudo mysql<br>CREATE DATABASE Wordpress;</pre><p>We then create a user and grant the user all privileges to our DB.</p><pre>CREATE USER `myuser`@`&lt;Web-Server-Private-IP-Address&gt;` IDENTIFIED BY &#39;mypass&#39;;<br>GRANT ALL ON wordpress.* TO &#39;myuser&#39;@&#39;&lt;Web-Server-Private-IP-Address&gt;&#39;;<br>FLUSH PRIVILEGES;<br>SHOW DATABASES;<br>exit</pre><h3>Configuring WordPress to connect to remote database</h3><p>we opened MySQL port 3306 on DB Server EC2. For extra security, we allow access to the DB server ONLY from our Web Server’s IP address, so in the Inbound Rule configuration, we specify the source as /32</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8OhZlsEk5fi8ay2a.JPG" /></figure><p>On our web server EC2 Instance, we installed MYSQL Client to test if we can connect successfully to Wordpress DB on the DB server.</p><pre>sudo yum install mysql<br>sudo mysql -u admin -p -h &lt;DB-Server-Private-IP-address&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*W5NNGGeEJ2PRrw0N.JPG" /></figure><p>To change permissions and configuration so Apache could use WordPress we run the following commands;</p><pre>cd /var/www/html/wordpress<br>sudo vi wp-config.php</pre><p>We then edit the wp-config.php file and fill it with our DB details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*8-E3A42qJKQ7CfvM.JPG" /></figure><p>We enabled TCP port 80 in inbound rules configuration for our Web Server EC2 (enable from everywhere 0.0.0.0/0 or our workstation’s IP)</p><p>We can now access our WordPress from our browser with the link;</p><p>http://&lt;Web-Server-Public-IP-Address&gt;/wordpress/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vVQWIiSH4w0M_oLl.JPG" /></figure><p>This shows that we have successfully configured Linux storage subsystem and have also deployed a full-scale Web Solution using WordPress CMS and MySQL RDBMS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc04497269a2" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploying-a-three-tier-architecture-web-solution-with-wordpress-on-aws-bc04497269a2">DEPLOYING A THREE-TIER ARCHITECTURE WEB SOLUTION WITH WORDPRESS ON AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IMPLEMENTING A CLIENT-SERVER ARCHITECTURE USING MYSQL DATABASE MANAGEMENT SYSTEM ON AWS]]></title>
            <link>https://awstip.com/implementing-a-client-server-architecture-using-mysql-database-management-system-on-aws-28da0cc7f67f?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/28da0cc7f67f</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 14:40:37 GMT</pubDate>
            <atom:updated>2023-08-12T12:30:18.736Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Client/Server Architecture?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*V2TNr853okUrVcSV.png" /></figure><p>Client-server architecture is a computer network architecture in which many clients (remote processors) request and receive service from a centralized server (host computer). Client computers provide an interface to allow a computer user to request services of the server and to display the results the server returns. Servers wait for requests to arrive from clients and then respond to them. Ideally, a server provides a standardized transparent interface to clients so that clients need not be aware of the specifics of the system (i.e., the hardware and software) that is providing the service. Clients are often situated at workstations or on personal computers, while servers are located elsewhere on the network, usually on more powerful machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sVsMpOeCqCcZrMln.png" /></figure><p>From the picture above, our Web Server has a role of a “Client” that connects and reads/writes to/from a Database (DB) Server (MySQL, MongoDB, Oracle, SQL Server, or any other). The communication between them happens over a Local Network (it can also be an Internet connection, but it is a common practice to place Web Server and DB Server close to each other in a local network).</p><p>For this project, we are provisioning two Linux-based virtual servers (EC2 instances in AWS).</p><ul><li>Server A name — mysql server</li><li>Server B name — mysql client</li></ul><p>Both of our EC2 servers are located in the same local network, so we will connect them using their respective private IP Address and have them send and return requests to each other.</p><h3>Connecting to the EC2 servers through SSH</h3><blockquote><em>NB: For this project, I already created the EC2 server on AWS; I need to connect to it to start the implementation. I also used two terminals, one for the Server and one for the Client.</em></blockquote><p>ssh -i &quot;mykey.pem&quot; ubuntu@ec2-184-72-73-85.compute-1.amazonaws.com</p><p>ssh -i &quot;mykey.pem&quot; ubuntu@ec2-52-90-160-253.compute-1.amazonaws.com</p><p>Connected Successfully to the MySQL server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/0*zfNmY_EVvcDcufz6.JPG" /></figure><p>Connected Successfully to MySQL client</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*_K2bLtY3nQbhRYln.JPG" /></figure><h3>Installing MySQL Server software on the mysql server EC2 instance</h3><p>We installed the mysql server with the command:</p><p>sudo apt install mysql-server</p><p>To check the installation status, we use the command</p><p>sudo service mysql status</p><p>And we have this, which shows the installation is successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/0*Ymr__ib3v9Xpp1K6.JPG" /></figure><h3>Installing MySQL Client software on mysql client EC2 instance</h3><p>We installed the mysql client with the command:</p><p>sudo apt install mysql-client</p><p>By default, both of our EC2 virtual servers are located in the same local virtual network, so they can communicate with each other using local IP addresses. We use mysql server’s local IP address to connect from mysql client. MySQL server uses TCP port 3306 by default, so we must open it by creating a new entry in ‘Inbound rules’ in ‘mysql server’ Security Groups. For extra security, we do not allow all IP addresses to reach our ‘mysql server.’ We only allow access to the specific local IP address of our ‘mysql client.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4nkVf3ovOcRFlzdK.JPG" /></figure><h3>Configuring MySQL Server to allow connection from remote hosts.</h3><p>To configure MySQL server to allow connections from remote hosts, we use vim to open the mysqld.cnf file with this command:</p><p>sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf</p><p>And we search for the bind-address and Replace ‘127.0.0.1’ to ‘0.0.0.0’ like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/0*tIU8gUPozWLl2JOE.JPG" /></figure><h3>Creating a remote user on MySQL Server.</h3><p>After configuring mysql server to allow connections from remote hosts, we need to create a remote user that can access our database from remote hosts. To do this, we first connect to our mysql database on the mysql server EC2 instance:</p><p>sudo mysql</p><p>We can list all users in our database with the command:</p><p>select user,plugin,host from mysql.user;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*nR_NcxProvxKqEe9.JPG" /></figure><p>This displays the list of all users that can access our database. To create a new remote user:</p><p>CREATE USER &#39;toluwase&#39;@&#39;%&#39; IDENTIFIED WITH mysql_native_password BY &#39;toluwase123&#39;;</p><p>The % sign will allow connections from remote hosts. toluwase is the username, and the password is toluwase123, as shown in the command.</p><p>To verify our new user has been created, we run the command:</p><p>select user,plugin,host from mysql.user;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*dDvL_g_wxM0dJsC3.JPG" /></figure><p>And we can see that user toluwase is now created.</p><h3>Connecting to database from MySQL Client EC2 instance.</h3><p>After creating the remote user, we can now head to the mysql client EC2 instance shell and connect to the database by using the command:</p><p>mysql --host=172.31.83.19 --user=toluwase --password=toluwase123</p><blockquote><em>NB: The IP address in the command is the private IP address of the MySQL Server EC2 instance.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/0*DktToet8bauZsC31.JPG" /></figure><p>The connection was successful. We can now start running queries on the database:</p><p>show databases;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*396NwBFQW71v8Z9u.JPG" /></figure><p>With this, we have successfully implemented a client-server architecture using MySQL DBMS on AWS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28da0cc7f67f" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/implementing-a-client-server-architecture-using-mysql-database-management-system-on-aws-28da0cc7f67f">IMPLEMENTING A CLIENT-SERVER ARCHITECTURE USING MYSQL DATABASE MANAGEMENT SYSTEM ON AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MEAN STACK ON AWS]]></title>
            <link>https://awstip.com/mean-stack-on-aws-5462948185a7?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/5462948185a7</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 14:56:41 GMT</pubDate>
            <atom:updated>2023-08-01T14:36:41.907Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Technology stack?</h3><p>A stack is an arrangement of “things” kept in order one over the other. A technology stack is a set of technologies stacked together to build any application. Popularly known as a technology infrastructure or solutions stack, technology stack has become essential for building easy-to-maintain, scalable web applications.</p><p>The technology stack determines the type of applications you can build, the level of customizations you can perform, and the resources you need to develop your application.</p><p>For example, a web tech stack typically looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*PVnrWgAhCQG7nwoo.png" /></figure><p>There are acronyms for individual technologies used together for a specific technology product. Some examples are…</p><ul><li>LAMP (Linux, Apache, MySQL, PHP or Python, or Perl)</li><li>LEMP (Linux, Nginx, MySQL, PHP or Python, or Perl)</li><li>MERN (MongoDB, ExpressJS, ReactJS, NodeJS)</li><li>MEAN (MongoDB, ExpressJS, AngularJS, NodeJS</li></ul><p>And for this project, we are implementing a MEAN stack solution.</p><p>MEAN Web stack consists of the following components:</p><ol><li>MongoDB: A document-based, No-SQL database used to store application data as documents.</li><li>ExpressJS: A server-side Web Application framework for Node.js. Makes requests to Database for Reads and Writes</li><li>Angular: (Front-end application framework) — Handles Client and Server Requests.</li><li>Node.js: A JavaScript runtime environment. It runs JavaScript on a machine rather than in a browser. It accepts requests and displays results to the end user.</li></ol><p>In this Project, we are implementing a simple Book Register web form using MEAN stack.</p><h3>Connecting to the EC2 server through SSH</h3><blockquote><em>NB: For this project, I already created an EC2 server on AWS. I need to connect to it to start the implementation.</em></blockquote><p>ssh -i &quot;mykey.pem&quot; ubuntu@ec2-3-89-215-83.compute-1.amazonaws.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/0*Oi6Rn4NuDKUK493F.JPG" /></figure><h3>Installing NodeJs</h3><p>Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js is used in this project to set up the Express routes and AngularJS controllers.</p><p>Firstly, I updated my software packages by running the following:</p><p>sudo apt update</p><p>Then upgrade ubuntu by running:</p><p>sudo apt upgrade -y</p><p>Add certificates</p><p>sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates</p><p>curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -</p><p>Install NodeJS</p><p>sudo apt install -y nodejs</p><p>Installing MongoDB.</p><p>MongoDB stores data in flexible, JSON-like documents. Fields in a database can vary from document to document, and data structure can be changed over time. For our example application, we are adding book records to MongoDB that contain the book name, ISBN number, author, and number of pages.</p><p>To import the Public Key used by Package Management System:</p><p>sudo apt-get install gnupg curl</p><p>curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor</p><p>To create a List file For MongoDB for Ubuntu 22.04:</p><pre>echo &quot;deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse&quot; | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list</pre><p>Then we reload Local Packages</p><p>sudo apt-get update</p><p>Install MongoDB</p><p>sudo apt-get install -y mongodb-org</p><p>To start and enable the Mongod service:</p><pre>sudo systemctl start mongod</pre><pre>sudo systemctl enable mongod</pre><p>To verify that the service is up and running</p><p>sudo systemctl status mongod</p><h3>To Install the body-parser package.</h3><p>We need the ‘body-parser’ package to help us process JSON files passed in requests to the server.</p><p>sudo npm install body-parser</p><p>Then we create a folder named Books and CD into the folder:</p><p>mkdir Books &amp;&amp; cd Books</p><p>In the Books directory, we initialize npm project</p><p>npm init</p><p>In the Books directory, we initialize npm project</p><p>npm init</p><p>And then we add a file named server.js</p><p>touch server.js &amp;&amp; vi server.js</p><p>Then we copy and paste the web server code below into the server.js file.</p><pre>var express = require(&#39;express&#39;);<br>var bodyParser = require(&#39;body-parser&#39;);<br>var app = express();<br>app.use(express.static(__dirname + &#39;/public&#39;));<br>app.use(bodyParser.json());<br>require(&#39;./apps/routes&#39;)(app);<br>app.set(&#39;port&#39;, 3300);<br>app.listen(app.get(&#39;port&#39;), function() {<br>    console.log(&#39;Server up: http://localhost:&#39; + app.get(&#39;port&#39;));<br>});</pre><p>And then save and quit.</p><p>:wq</p><h3>Installing Express and setting up routes to the server.</h3><p>Express is a minimal and flexible Node.js web application framework that provides features for web and mobile applications. We will use Express to pass book information to and from our MongoDB database.</p><p>We also will use the Mongoose package, which provides a straightforward, schema-based solution to model our application data. We will use Mongoose to establish a schema for the database to store data of our book register.</p><p>sudo npm install express mongoose</p><p>In ‘Books’ folder, we create a folder named apps and CD into the folder</p><p>mkdir apps &amp;&amp; cd apps</p><p>Then we create a file named routes.js</p><p>touch routes.js &amp;&amp; vi routes.js</p><p>We then copy and paste the following codes;</p><pre>const Book = require(&#39;./models/book&#39;);<br>module.exports = function(app){<br>  app.get(&#39;/book&#39;, function(req, res){<br>    Book.find({}).then(result =&gt; {<br>      res.json(result);<br>    }).catch(err =&gt; {<br>      console.error(err);<br>      res.status(500).send(&#39;An error occurred while retrieving books&#39;);<br>    });<br>  });<br><br>  app.post(&#39;/book&#39;, function(req, res){<br>    const book = new Book({<br>      name: req.body.name,<br>      isbn: req.body.isbn,<br>      author: req.body.author,<br>      pages: req.body.pages<br>    });<br>    book.save().then(result =&gt; {<br>      res.json({<br>        message: &quot;Successfully added book&quot;,<br>        book: result<br>      });<br>    }).catch(err =&gt; {<br>      console.error(err);<br>      res.status(500).send(&#39;An error occurred while saving the book&#39;);<br>    });<br>  });<br><br>  app.delete(&quot;/book/:isbn&quot;, function(req, res){<br>    Book.findOneAndRemove(req.query).then(result =&gt; {<br>      res.json({<br>        message: &quot;Successfully deleted the book&quot;,<br>        book: result<br>      });<br>    }).catch(err =&gt; {<br>      console.error(err);<br>      res.status(500).send(&#39;An error occurred while deleting the book&#39;);<br>    });<br>  });<br><br>  const path = require(&#39;path&#39;);<br>  app.get(&#39;*&#39;, function(req, res){<br>    res.sendFile(path.join(__dirname, &#39;public&#39;, &#39;index.html&#39;));<br>  });<br>};</pre><p>In the ‘apps’ folder, we create a folder named models:</p><p>mkdir models &amp;&amp; cd models</p><p>We create a file named book.js</p><p>vi book.js</p><p>Then we copy and paste the following codes;</p><pre>var mongoose = require(&#39;mongoose&#39;);<br>var dbHost = &#39;mongodb://localhost:27017/test&#39;;<br>mongoose.connect(dbHost);<br>mongoose.connection;<br>mongoose.set(&#39;debug&#39;, true);<br>var bookSchema = mongoose.Schema( {<br>  name: String,<br>  isbn: {type: String, index: true},<br>  author: String,<br>  pages: Number<br>});<br>var Book = mongoose.model(&#39;Book&#39;, bookSchema);<br>module.exports = mongoose.model(&#39;Book&#39;, bookSchema);</pre><h3>Accessing the routes with AngularJS</h3><p>AngularJS provides a web framework for creating dynamic views in our web applications. In this tutorial, we use AngularJS to connect our web page with Express and perform actions on our book register.</p><p>Change the directory back to ‘Books’</p><p>cd ../..</p><p>Then we create a folder named public and CD into the folder</p><p>mkdir public &amp;&amp; cd public</p><p>We added a file named script.js</p><p>vi script.js</p><p>We copy and paste the Code below (controller configuration defined) into the script.js file.</p><pre>var app = angular.module(&#39;myApp&#39;, []);<br>app.controller(&#39;myCtrl&#39;, function($scope, $http) {<br>  $http( {<br>    method: &#39;GET&#39;,<br>    url: &#39;/book&#39;<br>  }).then(function successCallback(response) {<br>    $scope.books = response.data;<br>  }, function errorCallback(response) {<br>    console.log(&#39;Error: &#39; + response);<br>  });<br>  $scope.del_book = function(book) {<br>    $http( {<br>      method: &#39;DELETE&#39;,<br>      url: &#39;/book/:isbn&#39;,<br>      params: {&#39;isbn&#39;: book.isbn}<br>    }).then(function successCallback(response) {<br>      console.log(response);<br>    }, function errorCallback(response) {<br>      console.log(&#39;Error: &#39; + response);<br>    });<br>  };<br>  $scope.add_book = function() {<br>    var body = &#39;{ &quot;name&quot;: &quot;&#39; + $scope.Name + <br>    &#39;&quot;, &quot;isbn&quot;: &quot;&#39; + $scope.Isbn +<br>    &#39;&quot;, &quot;author&quot;: &quot;&#39; + $scope.Author + <br>    &#39;&quot;, &quot;pages&quot;: &quot;&#39; + $scope.Pages + &#39;&quot; }&#39;;<br>    $http({<br>      method: &#39;POST&#39;,<br>      url: &#39;/book&#39;,<br>      data: body<br>    }).then(function successCallback(response) {<br>      console.log(response);<br>    }, function errorCallback(response) {<br>      console.log(&#39;Error: &#39; + response);<br>    });<br>  };<br>});</pre><p>In the public folder, we create a file named index.html;</p><p>vi index.html</p><p>We then copy and paste the code below into the index.html file</p><pre>&lt;!doctype html&gt;<br>&lt;html ng-app=&quot;myApp&quot; ng-controller=&quot;myCtrl&quot;&gt;<br>  &lt;head&gt;<br>    &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div&gt;<br>      &lt;table&gt;<br>        &lt;tr&gt;<br>          &lt;td&gt;Name:&lt;/td&gt;<br>          &lt;td&gt;&lt;input type=&quot;text&quot; ng-model=&quot;Name&quot;&gt;&lt;/td&gt;<br>        &lt;/tr&gt;<br>        &lt;tr&gt;<br>          &lt;td&gt;Isbn:&lt;/td&gt;<br>          &lt;td&gt;&lt;input type=&quot;text&quot; ng-model=&quot;Isbn&quot;&gt;&lt;/td&gt;<br>        &lt;/tr&gt;<br>        &lt;tr&gt;<br>          &lt;td&gt;Author:&lt;/td&gt;<br>          &lt;td&gt;&lt;input type=&quot;text&quot; ng-model=&quot;Author&quot;&gt;&lt;/td&gt;<br>        &lt;/tr&gt;<br>        &lt;tr&gt;<br>          &lt;td&gt;Pages:&lt;/td&gt;<br>          &lt;td&gt;&lt;input type=&quot;number&quot; ng-model=&quot;Pages&quot;&gt;&lt;/td&gt;<br>        &lt;/tr&gt;<br>      &lt;/table&gt;<br>      &lt;button ng-click=&quot;add_book()&quot;&gt;Add&lt;/button&gt;<br>    &lt;/div&gt;<br>    &lt;hr&gt;<br>    &lt;div&gt;<br>      &lt;table&gt;<br>        &lt;tr&gt;<br>          &lt;th&gt;Name&lt;/th&gt;<br>          &lt;th&gt;Isbn&lt;/th&gt;<br>          &lt;th&gt;Author&lt;/th&gt;<br>          &lt;th&gt;Pages&lt;/th&gt;<br><br>        &lt;/tr&gt;<br>        &lt;tr ng-repeat=&quot;book in books&quot;&gt;<br>          &lt;td&gt;{{book.name}}&lt;/td&gt;<br>          &lt;td&gt;{{book.isbn}}&lt;/td&gt;<br>          &lt;td&gt;{{book.author}}&lt;/td&gt;<br>          &lt;td&gt;{{book.pages}}&lt;/td&gt;<br><br>          &lt;td&gt;&lt;input type=&quot;button&quot; value=&quot;Delete&quot; data-ng-click=&quot;del_book(book)&quot;&gt;&lt;/td&gt;<br>        &lt;/tr&gt;<br>      &lt;/table&gt;<br>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Then we change the directory back up to Books</p><p>cd ..</p><p>We then start the server by running this command:</p><p>node server.js</p><p>The server is now up and running. We can connect it via port 3300 or our EC2 public ip address:3300.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/0*MkyS6VANgFKTqZr0.JPG" /></figure><p>This shows that our Book Register web form is ready, and we can add as many entries as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5462948185a7" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/mean-stack-on-aws-5462948185a7">MEAN STACK ON AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS-Well-Architected-Best-Practices-Operational-Excellence]]></title>
            <link>https://awstip.com/aws-well-architected-best-practices-operational-excellence-ab73eea82a18?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab73eea82a18</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Tue, 18 Jul 2023 10:53:50 GMT</pubDate>
            <atom:updated>2023-08-02T14:36:01.222Z</atom:updated>
            <content:encoded><![CDATA[<p>Operational excellence helps teams focus more on building new features that benefit customers and less time on maintenance and firefighting. To build correctly, we look to best practices that result in well-running systems, a balanced workload for you and your team, and, most importantly, a great customer experience.</p><h3>Objectives of the Project.</h3><p>In this project, we create an AWS Resource Group consisting of two EC2 instances and use AWS Systems Manager&#39;s “RUN Command” capability to install the Amazon CloudWatch agent to collect logs and get additional metrics.</p><p>By running this project, we will be able to:</p><ul><li>Add custom tags to EC2 instances</li><li>Create an AWS Resource Group for specific Amazon EC2 instances</li><li>Use AWS Systems Manager for the configuration of Amazon EC2 instances</li><li>Install and start the Amazon CloudWatch agent with AWS Systems Manager</li><li>Validate customs metric and log groups for Amazon EC2 instances in Amazon CloudWatch</li></ul><h3>Evaluating the existing Architecture.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/0*dT1DuJSa0JuDOXGU.png" /></figure><p>The company is a retail business, and one of the main applications of the company is a product catalog a. The Company’s Architecture contains a single Amazon VPC with an internet gateway and 2 subnets. The subnets are labeled public subnet and private subnet. Each subnet contains a single EC2 instance, one labeled web app instance, and one labeled database instance. After running the AWS Well architected framework review, it recommends the following:</p><ul><li>Automation: Most of the operational tasks are performed manually, and the company wants to Automate some of the operational tasks and provide visibility into most performance metrics like memory and disk usage, etc. Additionally, centralized log monitoring for the database and Application is needed.</li><li>Availability: A highly available architecture is required for the product catalog App</li><li>Security: Security is a top priority for the company</li><li>Rightsizing Amazon EC2 instances: The company is not sure about its current EC2 instance size and is also expecting an increase in traffic in the nearest future.</li><li>Cost: Some applications are not using the approved instance types per the company’s architecture standards, which increases cost due to overprovisioning of resources.</li></ul><p>As a solution Architect for the company tasked with the responsibility of having an Architecture with AWS best practices applied, We want the Architecture to meet the new performance requirements, mitigate risks, save money, and take Automation into consideration.</p><h3>Proposed Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O7BCOEIaVAelY6Bv.png" /></figure><p>The Architecture is an Amazon VPC containing 2 availability Zones. There are 6 total subnets in the environment, with each availability zone having 3 of the subnets. the subnets are labeled and divided by availability zone, such as 1 Public subnet, 1 Private subnet, and 1 db Private subnet. Each of the private subnets is part of an Autoscaling Group and contains 1 web server each. Each of the db private subnets contains 1 Amazon RDS instance. Internet traffic flows into an internet gateway, to an Application load balancer residing in the public subnets, Then to the Autoscaling group in the private subnet, and finally to the Amazon RDS primary instance in the db private subnet. Supporting management, automation &amp; monitoring services for the environment are; Amazon CloudWatch, Amazon Cloudtrail, AWS CloudFormation, AWS config &amp; AWS system manager. Supporting security services for the environment are AWS Identity and Access Management and AWS Secrets Manager.</p><p><em>The Operational Excellence pillar includes the ability to support development and run workloads effectively, gain insight into their operations, and continuously improve supporting processes and procedures to deliver business value.</em></p><p>Recall that some of the discoveries after running the AWS well-Architected Framework review were the need to automate some of the operational tasks, a lack of visibility into important metrics such as memory and disk usage for the EC2 instances, they also want an automated process to get that information. Additionally, they need centralized log monitoring for the database and the application instances.</p><p>We Begin implementing the new Architecture after successfully checking the existing Architecture and adding new entries to the product catalog application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/0*k79ra5HjQjU365TL.JPG" /></figure><h3>Task 1: Tag the Amazon EC2 Instances.</h3><p>With AWS, customers can assign metadata to their AWS resources in the form of Tags. Each Tag is a simple label consisting of a customer-defined key and an optional value. Tags make it easier to manage, search for, and filter resources. Tags are a great way to organize AWS resources, establish governance and enforce permissions. and they are critical to cost attribution for cost optimization.</p><ul><li>On the AWS console, we search for EC2 and clicked on Instances,</li><li>we selected the wa-web-server instance only and chose Tags on the lower half of the screen.</li><li>chose Manage Tags and add new tag</li><li>Create Tag 1 for key, we put Environment, and for Value-optional, we put Production</li><li>Create Tag 2 for key we put App, and for Value-optional, we put Product-Catalog</li><li>we chose save and return to the instances page</li><li>We now select the wa-db-server instance only and repeat the previous three steps by creating Tags.</li></ul><p>After successfully creating the Tags, we get the following message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*d7fjoaCQmYzGzr0w.JPG" /></figure><h3>Task 2: Create A Resource Group.</h3><p>A resource group is a collection of AWS resources in the same region that match a tag-based criteria provided in a search query. Resource group can be used to perform bulk actions such as Applying updates or security patches, upgrading an application version, installing new softwares, etc.</p><ul><li>At the top of AWS management console, we searched for and selected Resource Groups &amp; Tag Editor</li><li>we clicked Create a resource group, and the browser displayed the Create query-based-group page</li><li>on the page, in Group type section, we selected Tag Based</li><li>on the page, in the Grouping criteria section, for Resources, we select AWS::EC2::Instance</li><li>For Tags and Tag-Key, we typed App, and for Optional tag value, we input Product-Catalog and chose to save.</li><li>For Tags, For Tag-Key, we typed Environment, and for Optional tag value, we input Production and chose Save.</li><li>Then we chose preview group names. Both of our previously tagged Amazon EC2 are listed in the Group resources section.</li><li>on the create query-based-group page in the Group details section, for Group name, we input rg-wa, and for Group description, we input Resource Group for Well-Architected Labs. and then we chose Create groups.</li></ul><p>The browser displays the rg-wa Group details page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4VDEDMTqUAYQ3WZu.JPG" /></figure><h3>Task 3: Turn on Systems Manager for Amazon EC2 Instances.</h3><p>AWS Systems Manager is a service you can use to control your infrastructure on AWS. Systems Manager provides a unified user interface to track and resolve operational issues across AWS applications and resources from a central place.</p><p>AWS Systems Manager Agent (SSM Agent) is Amazon software that can be installed and configured on Amazon EC2 instances, an on-premise server, or a Virtual Machine (VM). The system manager agent makes it possible for the system manager service to update, manage, and configure these resources. By default, AWS SSM is pre-install on Amazon Linux, Amazon Linux 2, and Ubuntu servers 16.04, 18.04 &amp; 20.04. etc.</p><ul><li>At the top of the AWS management console, we searched for and selected EC2</li><li>we select instances and choose wa-web-server instance. we chose Action, Security, and Modify IAM Role.</li><li>on the Modify IAM Role for IAM Roles we chose Ec2SSMServerInstanceProfile, And the we chose Update IAM Role</li><li>We repeat the steps for the second EC2 and then Reboot both instances for the changes to take place.</li><li>After the reboot, we check for the EC2 in the system manager by searching for Systems Manager at the top of the AWS management console.</li><li>in the navigation menu under Node Management, we chose Inventory and scrolled down to see our EC2 instances in the Corresponding manage instances section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/0*gwCXmhPQP9EZc-nl.JPG" /></figure><p>Now we can use systems manager to Automate operational tasks on our EC2 instances.</p><h3>Task 4: Install Amazon CloudWatch Agent with the SSM Agent.</h3><p>The CloudWatch agent monitors activities on our EC2 instances to collect logs and metrics. The CloudWatch agent needs to be installed with the AWS Systems Manager on the EC2 instances using the Run command. Run command allows us to perform actions on EC2 instances remotely. This tool is especially helpful at scale, where we can manage the configuration of many instances with a single command.</p><ul><li>We chose the run command in the navigation menu on the AWS Systems Manager page under Node Management. This takes us to the Run Command page.</li><li>in the command document search box, we input AWS-ConfigureAWSPackage, press enter, and then select the AWS-ConfigureAWSPackage.</li><li>On the Run command page in the Target Selection section, for Target Selection, we select Choose Resource Group and choose the rg-wa resource group we created earlier.</li><li>We scrolled to the bottom of the page and chose Run</li></ul><p>We wait for the installation process to complete, and it then displays:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/0*C7vYiJp3hfDMYRd4.JPG" /></figure><h3>Task 4: Start The Amazon CloudWatch Agent.</h3><ul><li>We chose the run command in the navigation menu on the AWS Systems Manager page under Node Management. This takes us to the Run Command page.</li><li>in the command document search box, we input AmazonCloudWatch-ManageAgent, press enter, and then select the AmazonCloudWatch-ManageAgent.</li><li>In the command parameter section, for Action, we select Configure and for Optimal configuration source, we select SSM.</li><li>for Optimal configuration location, we enter the parameter name wa-cw-config-file-httpd-mariadb. This wa-cw-config-file-httpd-mariadb is saved in the parameter store, one of the capabilities of the AWS systems manager. The JSON document is shown below :</li></ul><pre>{<br>  &quot;agent&quot;: {<br>    &quot;metrics_collection_interval&quot;: 60,<br>    &quot;run_as_user&quot;: &quot;root&quot;<br>  },<br>  &quot;logs&quot;: {<br>    &quot;logs_collected&quot;: {<br>      &quot;files&quot;: {<br>        &quot;collect_list&quot;: [<br>          {<br>            &quot;file_path&quot;: &quot;/var/log/messages&quot;,<br>            &quot;log_group_name&quot;: &quot;messages&quot;,<br>            &quot;log_stream_name&quot;: &quot;{instance_id}&quot;<br>          },<br>          {<br>            &quot;file_path&quot;: &quot;/var/log/httpd/access_log&quot;,<br>            &quot;log_group_name&quot;: &quot;httpd_access_log&quot;,<br>            &quot;log_stream_name&quot;: &quot;{instance_id}&quot;<br>          },<br>          {<br>            &quot;file_path&quot;: &quot;/var/log/mariadb/wa-db-server.log&quot;,<br>            &quot;log_group_name&quot;: &quot;db_general_query_log&quot;,<br>            &quot;log_stream_name&quot;: &quot;{instance_id}&quot;<br>          },<br>          {<br>            &quot;file_path&quot;: &quot;/var/log/mariadb/mariadb.log&quot;,<br>            &quot;log_group_name&quot;: &quot;mariadb_log&quot;,<br>            &quot;log_stream_name&quot;: &quot;{instance_id}&quot;<br>          }<br>        ]<br>      }<br>    }<br>  },<br>  &quot;metrics&quot;: {<br>    &quot;append_dimensions&quot;: {<br>      &quot;AutoScalingGroupName&quot;: &quot;${aws:AutoScalingGroupName}&quot;,<br>      &quot;ImageId&quot;: &quot;${aws:ImageId}&quot;,<br>      &quot;InstanceId&quot;: &quot;${aws:InstanceId}&quot;,<br>      &quot;InstanceType&quot;: &quot;${aws:InstanceType}&quot;<br>    },<br>    &quot;metrics_collected&quot;: {<br>      &quot;disk&quot;: {<br>        &quot;measurement&quot;: [&quot;used_percent&quot;],<br>        &quot;metrics_collection_interval&quot;: 60,<br>        &quot;resources&quot;: [&quot;*&quot;]<br>      },<br>      &quot;mem&quot;: {<br>        &quot;measurement&quot;: [&quot;mem_used_percent&quot;],<br>        &quot;metrics_collection_interval&quot;: 60<br>      },<br>      &quot;statsd&quot;: {<br>        &quot;metrics_aggregation_interval&quot;: 60,<br>        &quot;metrics_collection_interval&quot;: 10,<br>        &quot;service_address&quot;: &quot;:8125&quot;<br>      }<br>    }<br>  }<br>}</pre><ul><li>On the Run command page in the Target Selection section, for Target Selection, we select Choose Resource Group and choose the rg-wa resource group we created earlier.</li><li>We scrolled to the bottom of the page and chose Run. We wait for the installation process to complete, and it then displays:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/0*Ijb0KA7RVxVCoO7N.JPG" /></figure><p>After all these were done successfully, we implemented the Operational-Excellence pillar of AWS well Architected framework by Adding custom tags to EC2 instances, Creating an AWS Resource Group for the Amazon EC2 instances, Using AWS Systems Manager for the configuration of Amazon EC2 instances, Installing and starting the Amazon CloudWatch agent with AWS Systems Manager, and, Validating customs metric and log groups for Amazon EC2 instances in Amazon CloudWatch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab73eea82a18" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/aws-well-architected-best-practices-operational-excellence-ab73eea82a18">AWS-Well-Architected-Best-Practices-Operational-Excellence</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MERN STACK ON AWS]]></title>
            <link>https://awstip.com/mern-stack-on-aws-a99496ba5a65?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/a99496ba5a65</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Tue, 09 May 2023 09:57:40 GMT</pubDate>
            <atom:updated>2023-05-11T18:09:19.925Z</atom:updated>
            <content:encoded><![CDATA[<h3>WEB STACK IMPLEMENTATION (MERN STACK) ON AWS</h3><h3>What is a Technology stack?</h3><p>A stack is an arrangement of “things” kept in order one over the other. A technology stack is a set of technologies stacked together to build any application. Popularly known as a technology infrastructure or solutions stack, technology stack has become essential for building easy-to-maintain, scalable web applications.</p><p>The technology stack determines the type of applications you can build, the level of customizations you can perform, and the resources you need to develop your application.</p><p>For example, a web tech stack typically looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*6HmUvfq4a58AXPPX.png" /></figure><p>There are acronyms for individual technologies used together for a specific technology product. Some examples are…</p><ul><li>LAMP (Linux, Apache, MySQL, PHP or Python, or Perl)</li><li>LEMP (Linux, Nginx, MySQL, PHP or Python, or Perl)</li><li>MERN (MongoDB, ExpressJS, ReactJS, NodeJS)</li><li>MEAN (MongoDB, ExpressJS, AngularJS, NodeJS</li></ul><p>And for this project, we are implementing a MERN stack solution.</p><p>MERN Web stack consists of the following components:</p><ol><li>MongoDB: A document-based, No-SQL database used to store application data in documents.</li><li>ExpressJS: A server-side Web Application framework for Node.js.</li><li>ReactJS: A frontend framework developed by Facebook. It is based on JavaScript, used to build User Interface (UI) components.</li><li>Node.js: A JavaScript runtime environment. It runs JavaScript on a machine rather than in a browser.</li></ol><p>For this project, we are creating a simple to-do application on mern web stack</p><h3>Connecting to the EC2 server through SSH</h3><blockquote>NB: For this project, i already created an EC2 server on AWS, i just need to connect to it to start the implementation.</blockquote><p>ssh -i &quot;mykey.pem&quot; <a href="/service/mailto:ubuntu@ec2-52-206-208-144.compute-1.amazonaws.com">ubuntu@ec2-52-206-208-144.compute-1.amazonaws.com</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YtmuZgVZWy4wP2Cn.JPG" /></figure><p>Then Update my software packages by running the:</p><p>sudo apt update</p><p>Then upgrade Ubuntu by running:</p><p>sudo apt upgrade</p><h3>BACKEND CONFIGURATION</h3><p>Firstly, Let’s get the location of Node.js software from Ubuntu repositories.</p><p>curl -fsSL <a href="https://deb.nodesource.com/setup_18.x">https://deb.nodesource.com/setup_18.x</a> | sudo -E bash -</p><p>Then we installed Node.js and npm with the command:</p><p>sudo apt-get install -y nodejs</p><p>We verify the node installation with the command:</p><p>node -v</p><p>npm -v</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/0*DaafaKsQR47-7YZ7.JPG" /></figure><h3>Setting up our Application code</h3><p>First, we create a new directory for our To-Do project:</p><p>mkdir Todo</p><p>We check for the folder by using the ‘ls’ command:</p><p>ls</p><p>And then we CD into our new directory:</p><p>cd Todo</p><p>Next, we used the command npm init to initialize our project so that a new file named package.json would be created. This file will typically contain information about our application and the dependencies that it needs to run. We followed the prompts after running the command by pressing Enter several times to accept default values, then get to write out the package.json file by typing yes.</p><p>npm init</p><h3>INSTALLING EXPRESS JS</h3><p>Express is a minimal and flexible Node.js web application framework that provides robust features for web and mobile applications. Express is a framework for Node.js. Therefore, many things developers would have programmed are already taken care of out of the box. Thus it simplifies development and abstracts a lot of low-level details. For example, Express helps define our application’s routes based on HTTP methods and URLs.</p><p>To use Express, install it using npm:</p><p>npm install express</p><p>Now we create a file index.js with the command:</p><p>touch index.js</p><p>Then we install the dotenv module:</p><p>DotEnv is a lightweight npm package that automatically loads environment variables from a .env file into the process. Env object. To use DotEnv, we first install it using the command: npm install dotenv . Then in our app, require and configure the package like this: need (‘dotenv’).</p><p>npm install dotenv</p><p>We open the index.js file with the command:</p><p>```vim index.js ``</p><p>We then type the following code, save and quit Vim:</p><p>COPY</p><pre>const express = require(&#39;express&#39;);<br>require(&#39;dotenv&#39;).config();</pre><pre>const app = express();</pre><pre>const port = process.env.PORT || 5000;</pre><pre>app.use((req, res, next) =&gt; {<br>res.header(&quot;Access-Control-Allow-Origin&quot;, &quot;\*&quot;);<br>res.header(&quot;Access-Control-Allow-Headers&quot;, &quot;Origin, X-Requested-With, Content-Type, Accept&quot;);<br>next();<br>});</pre><pre>app.use((req, res, next) =&gt; {<br>res.send(&#39;Welcome to Express&#39;);<br>});</pre><pre>app.listen(port, () =&gt; {<br>console.log(`Server running on port ${port}`)<br>});</pre><p>Now it is time to start our server to see if it works by opening the terminal in the same directory as our index.js file and typing:</p><p>node index.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*LM1dJcNNUViJD8pw.JPG" /></figure><p>We can now access our App by updating our EC2 security group to allow inbound connection on port 5000, as listed in our code.</p><p>To see our public IP address from the terminal:</p><p>curl -s <a href="http://169.254.169.254/latest/meta-data/public-ipv4">http://169.254.169.254/latest/meta-data/public-ipv4</a></p><p>To see our public DNS name from the terminal:</p><p>curl -s <a href="http://169.254.169.254/latest/meta-data/public-hostname">http://169.254.169.254/latest/meta-data/public-hostname</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*B55hNdk9philGz_y.JPG" /></figure><p>We exit the node server shell by typing ctrl C.</p><h3>Routes</h3><p>There are three actions that our To-Do application needs to be able to do:</p><ol><li>Create a new task</li><li>Display a list of all tasks</li><li>Delete a completed task</li></ol><p>Each task will be associated with some particular endpoint and will use different standard HTTP request methods: POST, GET, and DELETE.</p><p>For each task, we need to create routes that will define various endpoints that the To-do app will depend on. So we create a folder routes</p><p>mkdir routes</p><p>We can now CD into the routes folder</p><p>Now, we create a file api.js with the command:</p><p>touch api.js</p><p>And we open the file with Vim:</p><p>vim api.js</p><p>Then we copy and paste the code:</p><p>COPY</p><pre>const express = require (&#39;express&#39;);<br>const router = express.Router();</pre><pre>router.get(&#39;/todos&#39;, (req, res, next) =&gt; {</pre><pre>});</pre><pre>router.post(&#39;/todos&#39;, (req, res, next) =&gt; {</pre><pre>});</pre><pre>router.delete(&#39;/todos/:id&#39;, (req, res, next) =&gt; {</pre><pre>})</pre><pre>module.exports = router;</pre><h3>Models</h3><p>Since the app is going to make use of MongoDB, which is a NoSQL database, we need to create a model. A model is at the heart of JavaScript-based applications, and it is what makes it interactive.</p><p>We will also use models to define the database schema. This is important so that we will be able to define the fields stored in each MongoDB document. In essence, the Schema is a blueprint of how the database will be constructed, including other data fields that may not be required to be stored in the database. These are known as virtual properties</p><p>To create a Schema and a model, we install Mongoose, a Node.js package that makes working with MongoDB easier.</p><p>Change the directory back Todo folder with cd Todo and install Mongoose:</p><p>cd Todo</p><p>npm install mongoose</p><p>We create a new folder model:</p><p>mkdir models</p><p>And CD into models:</p><p>cd models</p><p>Inside the models folder, we create a file and named it todo.js:</p><p>touch todo.js</p><p>We can as well execute the three commands above on a single line with the help of &amp;&amp;:</p><p>mkdir models &amp;&amp; cd models &amp;&amp; touch todo.js</p><p>We then open the file created with vim todo.js then paste the code below in the file:</p><p>COPY</p><pre>const mongoose = require(&#39;mongoose&#39;);<br>const Schema = mongoose.Schema;</pre><pre>//create schema for todo<br>const TodoSchema = new Schema({<br>action: {<br>type: String,<br>required: [true, &#39;The todo text field is required&#39;]<br>}<br>})</pre><pre>//create model for todo<br>const Todo = mongoose.model(&#39;todo&#39;, TodoSchema);</pre><pre>module.exports = Todo;</pre><p>Now we need to update our routes from the file api.js in ‘routes’ directory to make use of the new model.</p><p>In the Routes directory, open api.js with vim api.js, delete the code inside with %d command and paste there code below into it, then save and exit</p><p>COPY</p><pre>const express = require (&#39;express&#39;);<br>const router = express.Router();<br>const Todo = require(&#39;../models/todo&#39;);</pre><pre>router.get(&#39;/todos&#39;, (req, res, next) =&gt; {</pre><pre>//this will return all the data, exposing only the id and action field to the client<br>Todo.find({}, &#39;action&#39;)<br>.then(data =&gt; res.json(data))<br>.catch(next)<br>});</pre><pre>router.post(&#39;/todos&#39;, (req, res, next) =&gt; {<br>if(req.body.action){<br>Todo.create(req.body)<br>.then(data =&gt; res.json(data))<br>.catch(next)<br>}else {<br>res.json({<br>error: &quot;The input field is empty&quot;<br>})<br>}<br>});</pre><pre>router.delete(&#39;/todos/:id&#39;, (req, res, next) =&gt; {<br>Todo.findOneAndDelete({&quot;_id&quot;: req.params.id})<br>.then(data =&gt; res.json(data))<br>.catch(next)<br>})</pre><pre>module.exports = router;</pre><h3>MONGODB DATABASE</h3><p>We need a database where we will store our data. MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.</p><p>For this project, we will make use of mLab. mLab provides MongoDB database as a service solution (DBaaS), so to make life easy, we will need to sign up for a shared clusters free account, which is ideal for our use case. <a href="https://www.mongodb.com/atlas-signup-from-mlab">Sign up here</a>. Follow the sign-up process, select AWS as the cloud provider, and choose a region near us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TVA0QAG8Qt9b8Q1L.JPG" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*sHHCiplNr5ZkgcqT.JPG" /></figure><p>Allow access to the MongoDB database from anywhere:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/0*VOXT-2fBe-Mru7VH.JPG" /></figure><p>In the index.js file, we specified process.env to access environment variables, but we have not yet created this file. So we need to do that now.</p><p>We create a file in our Todo directory and name it .env:</p><p>COPY</p><pre>touch .env<br>vi .env</pre><p>And Add our connection string into our application code:</p><p>mongodb+srv://Tolu4realluv:&lt;password&gt;@<a href="http://kaycuster.fgsh3gv.mongodb.net/?retryWrites=true&amp;w=majority">kaycuster.fgsh3gv.mongodb.net/?retryWrites=true&amp;w=majority</a></p><p>Now we need to update the index.js to reflect the use of .env so that Node.js can connect to the database by deleting the existing content in the file and updating it with the entire code below:</p><p>COPY</p><pre>const express = require(&#39;express&#39;);<br>const bodyParser = require(&#39;body-parser&#39;);<br>const mongoose = require(&#39;mongoose&#39;);<br>const routes = require(&#39;./routes/api&#39;);<br>const path = require(&#39;path&#39;);<br>require(&#39;dotenv&#39;).config();</pre><pre>const app = express();</pre><pre>const port = process.env.PORT || 5000;</pre><pre>//connect to the database<br>mongoose.connect(process.env.DB, { useNewUrlParser: true, useUnifiedTopology: true })<br>.then(() =&gt; console.log(`Database connected successfully`))<br>.catch(err =&gt; console.log(err));</pre><pre>//since mongoose promise is depreciated, we overide it with node&#39;s promise<br>mongoose.Promise = global.Promise;</pre><pre>app.use((req, res, next) =&gt; {<br>res.header(&quot;Access-Control-Allow-Origin&quot;, &quot;\*&quot;);<br>res.header(&quot;Access-Control-Allow-Headers&quot;, &quot;Origin, X-Requested-With, Content-Type, Accept&quot;);<br>next();<br>});</pre><pre>app.use(bodyParser.json());</pre><pre>app.use(&#39;/api&#39;, routes);</pre><pre>app.use((err, req, res, next) =&gt; {<br>console.log(err);<br>next();<br>});</pre><pre>app.listen(port, () =&gt; {<br>console.log(`Server running on port ${port}`)<br>});</pre><p>Using environment variables to store information is considered more secure, and best practice to separate configuration and secret data from the application instead of writing connection strings directly inside the index.js application file.</p><p>Starting our server using the command:</p><p>node index.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*SANoqWxYO54GYRff.JPG" /></figure><p>So far, we have written the backend part of our To-Do application and configured a database, but we do not have a front-end UI yet. We need ReactJS code to achieve that. But during development, we will need a way to test our code using RESTful API. Therefore, we will need to make use of some API development client to test our code.</p><p>In this project, we will use Postman to test our API. <a href="https://www.postman.com/downloads/">Click</a> Install Postman to download and install Postman on our machine.</p><p>Now we open our Postman and create a POST request to the API:</p><p><a href="http://52.206.208.144:5000/api/todos">http://52.206.208.144:5000/api/todos</a> This request sends a new task to our To-Do list so the application can store it in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uUVbX6kEZiPqdreO.JPG" /></figure><p>We can now send a GET request to retrieve our data from the DB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ClqqohyvIyVxnwjZ.JPG" /></figure><h3>FRONTEND CREATION</h3><p>Since we are done with the functionality we want from our backend and API, it is time to create a user interface for a Web client (browser) to interact with the application via API. To start out with the front end of the To-do app, we will use the create-react-app command to scaffold our app.</p><p>In the same root directory as our backend code, which is the Todo directory, we run:</p><p>npx create-react-app client</p><p>This will create a new folder in our Todo directory called client, where we will add all the react code.</p><h3>Running a React App</h3><p>Before testing the react app, some dependencies need to be installed.</p><ol><li>Install concurrently. It is used to run more than one command simultaneously from the same terminal window.</li></ol><p>npm install concurrently --save-dev</p><ol><li>Install nodemon. It is used to run and monitor the server. If there is any change in the server code, nodemon will restart it automatically and load the new changes.</li></ol><p>npm install nodemon --save-dev</p><ol><li>In the Todo folder, we open the package.json file. Change the highlighted part of the below screenshot and replace it with the code below.</li></ol><p>COPY</p><pre>&quot;scripts&quot;: {<br>&quot;start&quot;: &quot;node index.js&quot;,<br>&quot;start-watch&quot;: &quot;nodemon index.js&quot;,<br>&quot;dev&quot;: &quot;concurrently \&quot;npm run start-watch\&quot; \&quot;cd client &amp;&amp; npm start\&quot;&quot;<br>},</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oARVnxvvSDxIIl0t.jpg" /></figure><h3>Configure Proxy in package.json</h3><ol><li>Change the directory to ‘client’</li></ol><p>cd client</p><ol><li>Open the package.json file</li></ol><p>vim package.json</p><ol><li>Add the key-value pair in the package.json file “proxy”: “<a href="http://localhost:5000/">http://localhost:5000</a>&quot;.</li></ol><p>The whole purpose of adding the proxy configuration in number 3 above is to make it possible to access the application directly from the browser by simply calling the server URL like <a href="http://52.206.208.144:5000/">http://52.206.208.144:5000</a> rather than always including the entire path like <a href="http://52.206.208.144:5000/api/todos">http://52.206.208.144:5000/api/todos</a></p><p>Now, we CD back inside the Todo directory and simply do:</p><p>npm run dev</p><p>Our App is now running on port 3000. to access it via browser, we update our security group rule to allow inbound connection on port 3000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KyDz8xipAiyPGgF0.JPG" /></figure><h3>Creating our React Components.</h3><p>One of the advantages of React is that it makes use of components which are reusable and also makes code modular. For our Todo app, there will be two stateful components and one stateless component.</p><p>From our Todo directory, we run:</p><p>cd client</p><p>We move to the src directory:</p><p>cd src</p><p>Inside our src folder, we create another folder called components</p><p>mkdir components</p><p>We move into the components directory with:</p><p>cd components</p><p>Inside ‘components’ directory, create three files Input.js, ListTodo.js, and Todo.js.</p><p>touch Input.js ListTodo.js Todo.js</p><p>We open the Input.js file</p><p>vim input.js</p><p>We paste the following codes:</p><p>COPY</p><pre>import React, { Component } from &#39;react&#39;;<br>import axios from &#39;axios&#39;;</pre><pre>class Input extends Component {</pre><pre>state = {<br>action: &quot;&quot;<br>}</pre><pre>addTodo = () =&gt; {<br>const task = {action: this.state.action}</pre><pre>    if(task.action &amp;&amp; task.action.length &gt; 0){<br>      axios.post(&#39;/api/todos&#39;, task)<br>        .then(res =&gt; {<br>          if(res.data){<br>            this.props.getTodos();<br>            this.setState({action: &quot;&quot;})<br>          }<br>        })<br>        .catch(err =&gt; console.log(err))<br>    }else {<br>      console.log(&#39;input field required&#39;)<br>    }</pre><pre>}</pre><pre>handleChange = (e) =&gt; {<br>this.setState({<br>action: e.target.value<br>})<br>}</pre><pre>render() {<br>let { action } = this.state;<br>return (<br>&lt;div&gt;<br>&lt;input type=&quot;text&quot; onChange={this.handleChange} value={action} /&gt;<br>&lt;button onClick={this.addTodo}&gt;add todo&lt;/button&gt;<br>&lt;/div&gt;<br>)<br>}<br>}</pre><pre>export default Input</pre><p>To make use of Axios, which is a Promise-based HTTP client for the browser and node.js, we cd into our client from our terminal and run yarn add axios or npm install axios.</p><p>npm install axios</p><p>We CD to the ‘components’ directory</p><p>cd components</p><p>After that, we open our ListTodo.js:</p><p>vim ListTodo.js</p><p>In ListTodo.js, we copy and paste the following code:</p><p>COPY</p><pre>import React from &#39;react&#39;;</pre><pre>const ListTodo = ({ todos, deleteTodo }) =&gt; {</pre><pre>return (<br>&lt;ul&gt;<br>{<br>todos &amp;&amp;<br>todos.length &gt; 0 ?<br>(<br>todos.map(todo =&gt; {<br>return (<br>&lt;li key={todo._id} onClick={() =&gt; deleteTodo(todo._id)}&gt;{todo.action}&lt;/li&gt;<br>)<br>})<br>)<br>:<br>(<br>&lt;li&gt;No todo(s) left&lt;/li&gt;<br>)<br>}<br>&lt;/ul&gt;<br>)<br>}</pre><pre>export default ListTodo</pre><p>Then in our Todo.js file, we write the following code:</p><p>COPY</p><pre>import React, {Component} from &#39;react&#39;;<br>import axios from &#39;axios&#39;;</pre><pre>import Input from &#39;./Input&#39;;<br>import ListTodo from &#39;./ListTodo&#39;;</pre><pre>class Todo extends Component {</pre><pre>state = {<br>todos: []<br>}</pre><pre>componentDidMount(){<br>this.getTodos();<br>}</pre><pre>getTodos = () =&gt; {<br>axios.get(&#39;/api/todos&#39;)<br>.then(res =&gt; {<br>if(res.data){<br>this.setState({<br>todos: res.data<br>})<br>}<br>})<br>.catch(err =&gt; console.log(err))<br>}</pre><pre>deleteTodo = (id) =&gt; {</pre><pre>    axios.delete(`/api/todos/${id}`)<br>      .then(res =&gt; {<br>        if(res.data){<br>          this.getTodos()<br>        }<br>      })<br>      .catch(err =&gt; console.log(err))</pre><pre>}</pre><pre>render() {<br>let { todos } = this.state;</pre><pre>    return(<br>      &lt;div&gt;<br>        &lt;h1&gt;My Todo(s)&lt;/h1&gt;<br>        &lt;Input getTodos={this.getTodos}/&gt;<br>        &lt;ListTodo todos={todos} deleteTodo={this.deleteTodo}/&gt;<br>      &lt;/div&gt;<br>    )</pre><pre>}<br>}</pre><pre>export default Todo;</pre><p>We need to make a little adjustment to our react code. Delete the logo and adjust our App.js to look like this.</p><p>Firstly, we CD to the src folder and then open the App.js</p><p>vim App.js</p><p>We copy and paste the code below into it:</p><p>COPY</p><pre>import React from &#39;react&#39;;</pre><pre>import Todo from &#39;./components/Todo&#39;;<br>import &#39;./App.css&#39;;</pre><pre>const App = () =&gt; {<br>return (<br>&lt;div className=&quot;App&quot;&gt;<br>&lt;Todo /&gt;<br>&lt;/div&gt;<br>);<br>}</pre><pre>export default App;</pre><p>In the src directory, we open the App.css:</p><p>vim App.css</p><p>Then we paste the following code into App.css:</p><p>COPY</p><pre>.App {<br>text-align: center;<br>font-size: calc(10px + 2vmin);<br>width: 60%;<br>margin-left: auto;<br>margin-right: auto;<br>}</pre><pre>input {<br>height: 40px;<br>width: 50%;<br>border: none;<br>border-bottom: 2px #101113 solid;<br>background: none;<br>font-size: 1.5rem;<br>color: #787a80;<br>}</pre><pre>input:focus {<br>outline: none;<br>}</pre><pre>button {<br>width: 25%;<br>height: 45px;<br>border: none;<br>margin-left: 10px;<br>font-size: 25px;<br>background: #101113;<br>border-radius: 5px;<br>color: #787a80;<br>cursor: pointer;<br>}</pre><pre>button:focus {<br>outline: none;<br>}</pre><pre>ul {<br>list-style: none;<br>text-align: left;<br>padding: 15px;<br>background: #171a1f;<br>border-radius: 5px;<br>}</pre><pre>li {<br>padding: 15px;<br>font-size: 1.5rem;<br>margin-bottom: 15px;<br>background: #282c34;<br>border-radius: 5px;<br>overflow-wrap: break-word;<br>cursor: pointer;<br>}</pre><pre>@media only screen and (min-width: 300px) {<br>.App {<br>width: 80%;<br>}</pre><pre>input {<br>width: 100%<br>}</pre><pre>button {<br>width: 100%;<br>margin-top: 15px;<br>margin-left: 0;<br>}<br>}</pre><pre>@media only screen and (min-width: 640px) {<br>.App {<br>width: 60%;<br>}</pre><pre>input {<br>width: 50%;<br>}</pre><pre>button {<br>width: 30%;<br>margin-left: 10px;<br>margin-top: 0;<br>}<br>}</pre><p>In the src directory, we open the index.css</p><p>vim index.css</p><p>We copy and paste the code below:</p><p>COPY</p><pre>body {<br>margin: 0;<br>padding: 0;<br>font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Roboto&quot;, &quot;Oxygen&quot;,<br>&quot;Ubuntu&quot;, &quot;Cantarell&quot;, &quot;Fira Sans&quot;, &quot;Droid Sans&quot;, &quot;Helvetica Neue&quot;,<br>sans-serif;<br>-webkit-font-smoothing: antialiased;<br>-moz-osx-font-smoothing: grayscale;<br>box-sizing: border-box;<br>background-color: #282c34;<br>color: #787a80;<br>}</pre><pre>code {<br>font-family: source-code-pro, Menlo, Monaco, Consolas, &quot;Courier New&quot;,<br>monospace;<br>}</pre><p>Then we CD back to the Todo directory and run:</p><p>npm run dev</p><p>We can now see our App running on port 3000 using our browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s-a5G7IFjIVECf23.JPG" /></figure><p>This shows that our To-Do app is ready and fully functional with the functionality discussed earlier: creating a task, deleting a task, and viewing all our tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a99496ba5a65" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/mern-stack-on-aws-a99496ba5a65">MERN STACK ON AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WEB STACK IMPLEMENTATION (LEMP STACK) IN AWS]]></title>
            <link>https://awstip.com/web-stack-implementation-lemp-stack-in-aws-c2c0f32aa2eb?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2c0f32aa2eb</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Sat, 06 May 2023 10:52:27 GMT</pubDate>
            <atom:updated>2023-05-19T16:33:05.182Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Technology stack?</h3><p>A stack is an arrangement of “things” kept in order one over the other. A technology stack is a set of technologies that are stacked together to build any application. Popularly known as a technology infrastructure or solutions stack, technology stack has become essential for building easy-to-maintain, scalable web applications.</p><p>The technology stack determines the type of applications you can build, the level of customizations you can perform, and the resources you need to develop your application.</p><p>For example, a web tech stack typically looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*3ovZ15RS1jvipanZ.png" /></figure><p>There are acronyms for individual technologies used together for a specific technology product. some examples are…</p><ul><li>LAMP (Linux, Apache, MySQL, PHP or Python, or Perl)</li><li>LEMP (Linux, Nginx, MySQL, PHP or Python, or Perl)</li><li>MERN (MongoDB, ExpressJS, ReactJS, NodeJS)</li><li>MEAN (MongoDB, ExpressJS, AngularJS, NodeJS</li></ul><p>And for this project, we are implementing LEMP stack solution.</p><h3>Connecting to the EC2 server through SSH</h3><blockquote><em>NB: For this project, i already created an EC2 server on AWS, i just need to connect to it to start the implementation.</em></blockquote><p>ssh -i &quot;mykey.pem&quot; ubuntu@ec2-54-204-72-76.compute-1.amazonaws.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oVBqkPOAhl1pKsAu.JPG" /></figure><p>Then Update my software packages by running:</p><p>sudo apt update</p><h3>INSTALLING THE NGINX WEB SERVER</h3><p>NGINX is open-source web server software used for reverse proxy, load balancing, and caching. It provides HTTPS server capabilities and is mainly designed for maximum performance and stability. It also functions as a proxy server for email communications protocols, such as IMAP, POP3, and SMTP.</p><p>In order to display web pages to our site visitors, we are going to employ Nginx, a high-performance web server. We’ll use the apt package manager to install this package:</p><p>sudo apt install nginx</p><p>To verify Nginx is running:</p><p>sudo netstat -tulpn | grep nginx</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/0*58kuidoqTWcyJugR.JPG" /></figure><h3>INSTALLING MYSQL</h3><p>Now that we have a web server up and running, we need to install a Database Management System (DBMS) to be able to store and manage data for your site in a relational database. MySQL is a relational database management system (RDBMS) developed by Oracle that is based on structured query language (SQL). MySQL is a popular relational database management system used within PHP environments, so we will use it in our project.</p><h4>To install MYSQL using Ubuntu’s package manager, we run the following commands</h4><p>sudo apt install mysql-server</p><p>when prompted, confirm installation by typing y</p><p>connect to the database:</p><p>sudo mysql</p><p>It’s recommended that we run a security script that comes pre-installed with MySQL. This script will remove some insecure default settings and lock down access to our database system. Before running the script, we will set a password for the root user, using mysql_native_password as the default authentication method. We’re defining this user’s password as PassWord.2:</p><p>ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED WITH mysql_native_password BY &#39;PassWord.1&#39;;</p><p>Then we Exit the MYSQL shell:</p><p>exit</p><p>Then Start the interactive script by running:</p><p>sudo mysql_secure_installation</p><p>This asked if we’ll like to set up VALIDATE PASSWORD COMPONENT, which we say NO</p><p>we can now log in to MYSQL with the root password and run some queries:</p><p>sudo mysql -p</p><p>After successfully installing and testing MySQL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*_Nx9tOcP6E2cVgoH.JPG" /></figure><h3>Installing PHP</h3><p>We have Nginx installed to serve our content and MySQL installed to store and manage our data. Now you can install PHP to process code and generate dynamic content for the web server.</p><p>While Apache embeds the PHP interpreter in each request, Nginx requires an external program to handle PHP processing and act as a bridge between the PHP interpreter itself and the web server. This allows for better overall performance in most PHP-based websites, but it requires additional configuration. we’ll need to install php-fpm, which stands for “PHP FastCGI process manager”, and tell Nginx to pass PHP requests to this software for processing. Additionally, we’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. Core PHP packages will automatically be installed as dependencies.</p><p>To install these packages at once, we run:</p><p>sudo apt install php php-fpm php-mysql</p><p>we enter ‘Y’ for any prompt</p><p>To check PHP is properly installed:</p><p>php -v</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/0*Bi3CjDY-U6hyRodu.JPG" /></figure><h3>CONFIGURING NGINX TO USE PHP PROCESSOR</h3><p>When using the Nginx web server, we can create server blocks (similar to virtual hosts in Apache) to encapsulate configuration details and host more than one domain on a single server. In this guide, we will use projectLEMP as an example domain name.</p><p>On Ubuntu 20.04, Nginx has one server block enabled by default and is configured to serve documents out of a directory at /var/www/html. While this works well for a single site, it can become difficult to manage if we are hosting multiple sites. Instead of modifying /var/www/html, we’ll create a directory structure within /var/www for the our_domain website, leaving /var/www/html in place as the default directory to be served if a client request does not match any other sites.</p><p>we Create the root web directory for our_domain as follows:</p><p>sudo mkdir /var/www/projectLEMP</p><p>Next, we assign ownership of the directory with the $USER environment variable, which will reference your current system user:</p><p>we know our current username by using the command;</p><p>whoami</p><p>sudo chown -R ubuntu:ubuntu /var/www/projectLEMP</p><p>Then, we open a new configuration file in Nginx’s sites-available directory using our preferred command-line editor. Here, we’ll use nano:</p><p>sudo nano /etc/nginx/sites-available/projectLEMP</p><p>This will create a new blank file. then we Paste in the following bare-bones configuration:</p><pre>#/etc/nginx/sites-available/projectLEMP</pre><pre>server {<br>    listen 80;<br>    server_name projectLEMP <a href="http://www.projectlemp;/">www.projectLEMP;</a><br>    root /var/www/projectLEMP;</pre><pre>    index index.html index.htm index.php;</pre><pre>    location / {<br>        try_files $uri $uri/ =404;<br>    }</pre><pre>    location ~ \.php$ {<br>        include snippets/fastcgi-php.conf;<br>        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;<br>     }</pre><pre>    location ~ /\.ht {<br>        deny all;<br>    }</pre><pre>}</pre><p>Here’s what each of these directives and location blocks does:</p><ul><li>listen — Defines what port Nginx will listen on. In this case, it will listen on port 80, the default port for HTTP</li><li>root — Defines the document root where the files served by this website are stored</li><li>index — Defines in which order Nginx will prioritize index files for this website. It is a common practice to list index.html files with higher precedence than index.php files to allow for quickly setting up a maintenance landing page in PHP applications. You can adjust these settings to better suit your application needs.</li><li>server_name — Defines which domain names and/or IP addresses this server block should respond for. Point this directive to your server’s domain name or public IP address.</li><li>location / — The first location block includes a try_files directive, which checks for the existence of files or directories matching a URI request. If Nginx cannot find the appropriate resource, it will return a 404 error.</li><li>location ~ .php$ — This location block handles the actual PHP processing by pointing Nginx to the FastCGI-php.conf configuration file and the php7.4-fpm.sock file, which declares what socket is associated with php-fpm.</li><li>location ~ /.ht — The last location block deals with .htaccess files, which Nginx does not process. By adding the deny all directive, if any .htaccess files happen to find their way into the document root, they will not be served to visitors.</li></ul><p>After completion, we save and close the file. by typing CTRL+X and then y and ENTER to confirm.</p><p>we then activate our configuration by linking to the config file from Nginx’s sites-enabled directory:</p><p>sudo ln -s /etc/nginx/sites-available/projectLEMP /etc/nginx/sites-enabled/</p><p>This will tell Nginx to use the configuration the next time it is reloaded. we test our configuration for syntax errors by typing:</p><p>sudo nginx -t</p><p>and we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/0*GopNeAmwETUe5Eaq.JPG" /></figure><p>We also need to disable the default Nginx host that is currently configured to listen on port 80; for this we run:</p><p>sudo unlink /etc/nginx/sites-enabled/default</p><p>We then reload Nginx to apply the changes:</p><p>sudo systemctl reload nginx</p><p>our new website is now active, but the web root /var/www/projectLEMP is still empty. We created an index.html file in that location so that we can test that our new server block works as expected:</p><pre>sudo echo &#39;Hello LEMP from Toluwase&#39; $(curl -s http://169.254.169.254/latest/meta-data/public-hostname) &#39;with public IP&#39; $(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) &gt; /var/www/projectLEMP/index.html</pre><p>We check this by typing our EC2 public ip address in a browser</p><p>http://&lt;Public-IP-Address&gt;:80</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/0*Eaod3EchT6izpHH-.JPG" /></figure><h3>TESTING PHP WITH NGINX</h3><p>At this point, our LEMP stack is completely installed and fully operational. we test it to validate that Nginx can correctly hand .php files off to our PHP processor. we do this by creating a test PHP file in our document root. we opened a new file called info.php within our document root in our text editor:\</p><p>sudo nano /var/www/projectLEMP/info.php</p><p>We then paste the following lines into the new file. This is valid PHP code that returns information about our server:</p><pre>&lt;?php<br>phpinfo();</pre><p>We access this page in our web browser by visiting the domain name or public IP address we’ve set up in our Nginx configuration file, followed by /info.php:</p><p><a href="http://`server_domain_or_ip`/info.php">http://`server_domain_or_IP`/info.php</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jr583nixiHba6Vp8.JPG" /></figure><p>This shows that our NGINX can now handle PHP files</p><h3>RETRIEVING DATA FROM MYSQL DATABASE WITH PHP</h3><p>In this step, we will create a test database (DB) with a simple “To-do list” and configure access to it, so the Nginx website would be able to query data from the DB and display it. We’ll need to create a new user with the mysql_native_password authentication method in order to be able to connect to the MySQL database from PHP.</p><p>We will create a database named makay_database and a user named makay.</p><p>Connecting to the MySQL root user:</p><p>sudo mysql -p</p><p>Create a new Database with the command:</p><p>CREATE DATABASE `makay_database`;</p><p>We then create a new user and grant him full privilege with the Database we just created:</p><p>CREATE USER &#39;makay&#39;@&#39;%&#39; IDENTIFIED WITH mysql_native_password BY &#39;password&#39;;</p><p>GRANT ALL ON makay_database.* TO &#39;makay&#39;@&#39;%&#39;;</p><p>This gives the makay user full privileges over the makay_database database while preventing this user from creating or modifying other databases on our server.</p><p>We then exit the MySQL shell:</p><p>exit</p><p>And then test the connection to our new Database:</p><p>mysql -u makay -p</p><p>And then check to see the databases</p><p>show databases;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/0*FnGe2zfogjm-O3mE.JPG" /></figure><p>Next, we’ll create a test table named kay_list. From the MySQL console, we run the following statement:</p><pre>CREATE TABLE makay_database.kay_list (<br>    item_id INT AUTO_INCREMENT,<br>    content VARCHAR(255),<br>    PRIMARY KEY(item_id) );</pre><p>Then we Insert a few rows of content in the test table. we repeat the command a few times, using different VALUES:</p><p>INSERT INTO makay_database.kay_list (content) VALUES (&quot;My first important item&quot;);</p><p>INSERT INTO makay_database.kay_list (content) VALUES (&quot;My second important item&quot;);</p><p>INSERT INTO makay_database.kay_list (content) VALUES (&quot;My third important item&quot;);</p><p>INSERT INTO makay_database.kay_list (content) VALUES (&quot;my number four to-do item&quot;);</p><p>INSERT INTO makay_database.kay_list (content) VALUES (&quot;My number five to-do item&quot;);</p><p>To confirm that the data was successfully saved to our table, we run:</p><p>SELECT * FROM makay_database.kay_list;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*8zQnyTr2UsRK3XKt.JPG" /></figure><p>We can now exit the mysql shell</p><p>exit</p><p>Now we can create a PHP script that will connect to MySQL and query for our content. We create a new PHP file in our custom web root directory using our preferred editor. We’ll use nano for that:</p><p>nano /var/www/projectLEMP/kay_list.php</p><p>And then, we paste the config script that connects to the MySQL database and query for the content of the kay_list table, displaying the results in a list. If there is a problem with the database connection, it will throw an exception:</p><pre>&lt;?php<br>$user = &quot;makay&quot;;<br>$password = &quot;password&quot;;<br>$database = &quot;makay_database&quot;;<br>$table = &quot;kay_list&quot;;</pre><pre>try {<br>  $db = new PDO(&quot;mysql:host=localhost;dbname=$database&quot;, $user, $password);<br>  echo &quot;&lt;h2&gt;TODO&lt;/h2&gt;&lt;ol&gt;&quot;;<br>  foreach($db-&gt;query(&quot;SELECT content FROM $table&quot;) as $row) {<br>    echo &quot;&lt;li&gt;&quot; . $row[&#39;content&#39;] . &quot;&lt;/li&gt;&quot;;<br>  }<br>  echo &quot;&lt;/ol&gt;&quot;;<br>} catch (PDOException $e) {<br>    print &quot;Error!: &quot; . $e-&gt;getMessage() . &quot;&lt;br/&gt;&quot;;<br>    die();<br>}</pre><p>We save and close the file by typing CTRL X, Y, and Enter</p><p>We can now access this page in our web browser by visiting the domain name or public IP address configured for our website, followed by /kay_list.php:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*RdgQ-MRu4_0PgErK.JPG" /></figure><p>This means our PHP environment is ready to connect and interact with our MySQL server</p><p>This shows everything is working perfectly, and we have successfully deployed and configured a LEMP stack website in AWS Cloud.</p><p>Give feedback</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2c0f32aa2eb" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/web-stack-implementation-lemp-stack-in-aws-c2c0f32aa2eb">WEB STACK IMPLEMENTATION (LEMP STACK) IN AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WEB STACK IMPLEMENTATION (LAMP STACK) IN AWS]]></title>
            <link>https://awstip.com/web-stack-implementation-lamp-stack-in-aws-e6f468321e7f?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6f468321e7f</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[lamp-stack]]></category>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Wed, 03 May 2023 11:42:00 GMT</pubDate>
            <atom:updated>2023-05-26T15:09:18.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Technology stack?</h3><p>A stack is an arrangement of “things” kept in order one over the other. A technology stack is a set of technologies that are stacked together to build any application. Popularly known as a technology infrastructure or solutions stack, technology stack has become essential for building easy-to-maintain, scalable web applications.</p><p>The technology stack determines the type of applications you can build, the level of customizations you can perform, and the resources you need to develop your application.</p><p>For example, a web tech stack typically looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*ZfVihulooWdwWZdx.png" /></figure><p>There are acronyms for individual technologies used together for a specific technology product. some examples are…</p><ul><li>LAMP (Linux, Apache, MySQL, PHP or Python, or Perl)</li><li>LEMP (Linux, Nginx, MySQL, PHP or Python, or Perl)</li><li>MERN (MongoDB, ExpressJS, ReactJS, NodeJS)</li><li>MEAN (MongoDB, ExpressJS, AngularJS, NodeJS</li></ul><p>And for this project, we are implementing LAMP stack solution.</p><h3>Connecting to the EC2 server through SSH</h3><blockquote><em>NB: For this project, i already created an EC2 server on AWS, i just need to connect to it to start the implementation.</em></blockquote><p>ssh -i &quot;mykey.pem&quot; ec2-user@ec2-54-152-255-29.compute-1.amazonaws.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NlWLMQLZPxvu9LL8.JPG" /></figure><h3>INSTALLING APACHE AND UPDATING THE FIREWALL</h3><h3>What is Apache?</h3><p>Apache HTTP Server is the most widely used web server software. Developed and maintained by Apache Software Foundation, Apache is an open-source software available for free. It runs on 67% of all web servers in the world. It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules. Most WordPress hosting providers use Apache as their web server software. However, websites and other applications can run on other web server software as well. Such as Nginx, Microsoft’s IIS, etc.</p><p>The Apache web server is among the most popular web servers in the world. It’s well documented, has an active community of users, and has been in wide use for much of the history of the web, which makes it a great default choice for hosting a website.</p><h4>To install Apache using Ubuntu’s package manager, we run the following commands</h4><p>sudo apt update</p><p>sudo apt install apache2</p><blockquote><em>NB: if your operating system is Amazon Linux based AMI, use yum package manager instead of apt you can follow the instruction on this </em><a href="https://docs.rackspace.com/support/how-to/centos-7-apache-and-php-install/"><em>Link</em></a><em> to install Apache on AMI</em></blockquote><p>After successful installation, it takes us to the test page for Apache 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v8Jwr8gtOXyRSfz-.JPG" /></figure><h3>INSTALLING INSTALLING MYSQL</h3><p>Now that we have a web server up and running, we need to install a Database Management System (DBMS) to be able to store and manage data for your site in a relational database. MySQL is a relational database management system (RDBMS) developed by Oracle that is based on structured query language (SQL). MySQL is a popular relational database management system used within PHP environments, so we will use it in our project.</p><h4>To install MYSQL using Ubuntu’s package manager, we run the following commands</h4><p>sudo apt install mysql-server</p><p>when prompted, confirm installation by typing y</p><p>After successfully installing MySQL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*bsL0bBwP4aBLe0j5.JPG" /></figure><h3>INSTALLING PHP</h3><p>We have Apache installed to serve your content and MySQL installed to store and manage our data. PHP is the component of our setup that will process code to display dynamic content to the end user. In addition to the php package, we’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. we’ll also need libapache2-mod-php to enable Apache to handle PHP files. Core PHP packages will automatically be installed as dependencies.</p><h4>To install these three packages at once, run:</h4><p>sudo apt install php libapache2-mod-php php-mysql</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/0*O58BgzRIWrTdQTDw.JPG" /></figure><h3>CREATING A VIRTUAL HOST FOR OUR WEBSITE USING APACHE</h3><p>In this project, we set up a domain called Projectlamp</p><p>Create the directory for projectlamp using ‘mkdir’ command as follows:</p><p>sudo mkdir /var/www/projectlamp</p><p>Next, we assign ownership of the directory to our current system user:</p><p>sudo chown -R $USER:$USER /var/www/projectlamp</p><p>Then, we create and open a new configuration file in Apache’s sites-available directory using Vim</p><p>sudo vi /etc/apache2/sites-available/projectlamp.conf</p><p>This will create a new blank file. we Paste in the following bare-bones configuration by hitting on i on the keyboard to enter the insert mode and paste the text:</p><pre>&lt;VirtualHost *:80&gt;<br>    ServerName projectlamp<br>    ServerAlias www.projectlamp <br>    ServerAdmin webmaster@localhost<br>    DocumentRoot /var/www/projectlamp<br>    ErrorLog ${APACHE_LOG_DIR}/error.log<br>    CustomLog ${APACHE_LOG_DIR}/access.log combined<br>&lt;/VirtualHost&gt;</pre><p>To save and close the file, we follow the steps below:</p><ol><li>Hit the ESC button on the keyboard</li><li>Type :</li><li>Type wq. w for write and q for quit</li><li>Hit ENTER to save the file</li></ol><p>we use the a2ensite command to enable the new virtual host, disable the default host, test the config file then finally reload apache2 to update changes:</p><p>sudo a2ensite projectlamp</p><p>sudo a2dissite 000-default</p><p>sudo apache2ctl configtest</p><p>sudo systemctl reload apache2</p><p>The new website is now active, but the web root /var/www/projectlamp is still empty. we Create an index.html file in that location so that we can test that the virtual host works as expected:</p><pre>sudo echo &#39;Hello LAMP from hostname&#39; $(curl -s http://169.254.169.254/latest/meta-data/public-hostname) &#39;with public IP&#39; $(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) &gt; /var/www/projectlamp/index.html</pre><p>we confirmed this by opening a new browser tab and navigating to our EC2 public IP Address</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/0*N9MzR_Ix2Cv5vaLX.JPG" /></figure><h3>ENABLE PHP ON THE WEBSITE</h3><p>With the default DirectoryIndex settings on Apache, a file named index.html will always take precedence over an index.php file. This is useful for setting up maintenance pages in PHP applications by creating a temporary index.html file containing an informative message to visitors. Because this page will take precedence over the index.php page, it will then become the landing page for the application. Once maintenance is over, the index.html is renamed or removed from the document root, bringing back the regular application page.</p><p>In case we want to change this behavior, we’ll need to edit the /etc/apache2/mods-enabled/dir.conf file and change the order in which the index.php file is listed within the DirectoryIndex directive:</p><p>sudo vim /etc/apache2/mods-enabled/dir.conf</p><p>And add the following config</p><pre>&lt;IfModule mod_dir.c&gt;<br>        #Change this:<br>        #DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm<br>        #To this:<br>        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm<br>&lt;/IfModule&gt;</pre><p>After saving and closing the file, we reload Apache2 so the changes take effect:</p><p>sudo systemctl reload apache2</p><p>Finally, we create a PHP script to test that PHP is correctly installed and configured on our server.</p><p>Now that we have a custom location to host our website’s files and folders, we’ll create a PHP test script to confirm that Apache is able to handle and process requests for PHP files.</p><p>we Create a new file named index.php inside our custom web root folder:</p><p>vim /var/www/projectlamp/index.php</p><p>This opens a blank file. we then add the following text, which is valid PHP code, inside the file:</p><pre>&lt;?php<br>phpinfo();</pre><p>Finally, checking code status on browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J6Ne6_K8cFFSnJMj.JPG" /></figure><p>The Image Shows everything is working perfectly, and we have successfully deployed a LAMP stack website in AWS Cloud.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6f468321e7f" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/web-stack-implementation-lamp-stack-in-aws-e6f468321e7f">WEB STACK IMPLEMENTATION (LAMP STACK) IN AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW AWS SERVERLESS COMPUTING CAN BENEFIT STARTUP]]></title>
            <link>https://medium.com/@toluwase2/how-aws-serverless-computing-can-benefit-startup-cf7731c74718?source=rss-a6121db16f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf7731c74718</guid>
            <dc:creator><![CDATA[Toluwase Makanjuola]]></dc:creator>
            <pubDate>Thu, 19 Jan 2023 12:40:09 GMT</pubDate>
            <atom:updated>2023-01-19T12:40:09.977Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mBEQBaMM60c-hExn.png" /></figure><p>Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on demand, taking care of the servers on behalf of their customers. “Serverless” is a misnomer because cloud service providers still use servers to execute code for developers. With serverless, the cloud vendor takes care of all routine infrastructure management and maintenance, including updating the operating system (OS), applying patches, managing security, system monitoring, and planning capacity. With serverless computing, developers don’t have to manage machine instances in the cloud. Instead, they can run code on cloud servers without configuring or maintaining them. Pricing is based on an application’s actual amount of resources rather than on pre-purchased capacity units. As of the time of writing this article, There are more than ten serveless services offered by AWS, but we’re going to talk about five of those services: AWS Lambda, AWS Fargate, AWS Step Functions, Amazon SNS, and AWS AppSync.</p><p><strong>AWS Lambda: </strong>AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS). Users of AWS Lambda create functions, self-contained applications written in one of the supported languages and runtimes, and upload them to AWS Lambda, which executes those functions efficiently and flexibly. In AWS Lambda the code is executed based on the response of events in AWS services, such as add/delete files in S3 bucket, HTTP requests from Amazon API gateway, etc. However, Amazon Lambda can only be used to execute background tasks. Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, and logging. With Lambda, you can run code for virtually any application or backend service. All you need to do is supply your code in one of the languages that Lambda supports.</p><p>Developers can start using AWS Lambda services, either by uploading the code or coding directly in Lambda’s code editor and mentioning the conditions that trigger the code. The code executed on the Lambda run time environment is called a Lambda Function. With this, any event can prompt your function without developers worrying about handling the server or getting the right type of application or resource. Businesses don’t have to pay when your code is not running, thereby saving on server costs. AWS Lambda function helps you focus on your core product and business logic instead of managing operating system (OS) access control, patching, right-sizing, provisioning, scaling, etc.</p><p><strong>AWS Fargate : </strong>AWS Fargate is a service that provisions serverless compute resources to run AWS ECS and EKS containers. AWS Fargate eliminates the requirement for customers to manage their own EC2 instances. Users are not required to utilize AWS EC2 instances at all. Fargate will serve as the computational engine. It allows you to concentrate on aspects such as planning and building your application rather than maintaining the infrastructure that supports it. All you have to do with the Fargate launch type is package your application in containers, select the memory and CPU requirements, establish IAM policies, and start your application. AWS Fargate also makes scaling your apps simple. AWS Fargate provides all of the scalability and infrastructure required to operate your containers in a highly available way once you declare all your application needs. It interfaces with Amazon ECS and EKS, launching and managing your containers for you. With Fargate, you only pay for the resources required to run your containers as they are consumed, eliminating over-provisioning and paying for servers you don’t need. Fargate tasks (pods) run in their kernels providing a secure and isolated compute environment, which provides an isolated workload and improved security as a consequence. With Amazon ECS on AWS Fargate, you pay for the vCPU and memory resources your tasks use. Fargate also offers Savings Plans which provides significant savings on your AWS usage.</p><p><strong>AWS Step Functions : </strong>AWS Step Functions is a serverless orchestration service that lets developers create and manage multi-step application workflows in the cloud. By using the service’s drag-and-drop visual editor, teams can quickly assemble individual microservices into unified workflows. Step Functions manages input, output, error handling, and retries at each step of a given workflow so that developers can focus on higher-value business logic for their applications. AWS Step Functions has two workflow options — Standard and Express. When your business process is expected to take longer than five minutes for a single execution, you should choose Standard. Some examples of a long running workflow are an ETL orchestration pipeline or when any step in your workflow waits for response from a human to move to the next step.</p><p>Express workflows are suited for workflows that take less than five minutes, and are ideal when you need high execution volume i.e. 100,000 invocations per second. You can use either Standard or Express distinctly, or combine them such that a longer Standard workflow triggers multiple shorter Express workflows that execute in parallel. The main benefit of AWS Step Functions is that it eliminates the need to manually orchestrate your application components and define how they should work together. As a result, engineers can spend less time writing workflow code and focus more on higher-value business logic.</p><p><strong>Amazon SNS : </strong>Amazon Simple Notification Service (SNS) is a cloud service for coordinating the delivery of push messages from software applications to subscribing endpoints and clients. All messages published to Amazon SNS are warehoused across several availability zones to prevent loss.</p><p>Amazon SNS allows users to push messages to Windows, Google, Apple and certain internet-connected smart devices by using an application programming interface (API) or the AWS Management Console. Once a message is published to the service, it can be sent multiple times to different recipients. Service users also have the flexibility to send direct messages to several devices or one subscriber by using a sole publish request. Clients can subscribe to an SNS topic and receive published messages via any supported endpoint, including Amazon Kinesis Data Firehose, Amazon SQS, AWS Lambda, HTTP, email, mobile push notifications, and mobile text messaging (SMS).</p><p>The benefits of AWS SNS are as follows:</p><ul><li><strong>Instant delivery</strong>: Works on a push-based system. It is sent once a message is posted on a topic and forwarded to many subscribers.</li><li><strong>It’s cheap</strong> because it’s built on a pay-as-you-go basis, which means we only pay when we use the resources and you don’t pay any upfront fees.</li><li>Multiple endpoints are supported, making it versatile. Different endpoints can receive messages via other transport protocols, including email, SMS, Lambda, Amazon SQS, HTTP, and more.</li><li><strong>Ease of use</strong>: The AWS web management console offers the simplicity of a point-and-click interface, making it a very straightforward service.</li></ul><p><strong>AWS AppSync : </strong>AWS AppSync is a new service in Public Preview that enables you to manage and update mobile app data in real-time between devices and the cloud, and allows apps to interact with the data on the mobile device when it is offline. With AWS AppSync, applications can easily access AWS services using a data language called GraphQL and an SDK that is optimized for mobile and web applications. GraphQL is an open standard that lets you request, change, and subscribe to the exact data you need in a single network request. This makes prototyping and building data intensive applications as simple as writing a few lines of code.</p><p>AWS AppSync lets you quickly and easily prototype and build apps that deliver real-time collaborative experiences in browsers and mobile apps that remain usable even when network connectivity is lost. GraphQL queries and mutations can be used when the client is connected or disconnected from the network, including optimistic UI updates. GraphQL subscriptions can be used for clients to get real-time data updates between connected devices and the cloud.</p><p>AWS AppSync integrates into popular mobile application frameworks including iOS, Android and JavaScript, and automatically enables your apps for real-time and offline functionality. You can select which data is automatically synchronized to each user’s device when changes are made, optimizing the user experience and minimizing storage and bandwidth requirements. With AWS AppSync, your app can access data in Amazon DynamoDB, trigger AWS Lambda functions, or run Amazon Elasticsearch queries. AWS AppSync also integrates with AWS Identity and Access Management and Amazon Cognito User Pools, so you can set fine grained permissions on GraphQL operations and keep users and app data secure.</p><p><strong>Benefits of Serverless Architecture</strong></p><p><strong>Deploy in Minutes: </strong>Serverless architecture brings with it the benefit of faster deployment. While IaaS can take days and months, serverless applications can be deployed within minutes. Moreover, concurrent uses of that same function can happen within milliseconds. This is perfect for cash-trapped startups as it provides flexible computing needs.</p><p><strong>Infrastructure Cost Savings: </strong>I know a large transport organization shifted to serverless architecture to solve their problem of unpredictable and slow response times between databases. This enabled real-time operation and facilitated real-time reporting and analytics.</p><p>Moreover, this created a centralized source of sales data. This significantly reduced redundant data in their repository due to lack of consistency. As a result, the organisation saved $340,000 annually by cutting money spent on maintenance and support for the existing systems.</p><p><strong>Pay per Millisecond: </strong>While your traditional dedicated server might be spinning and running and charging you 24*7, irrespective of whether anybody uses it or not. However, this is not the case with serverless architecture.</p><p>For example, if I use my server for 2 minutes in the morning, 4 minutes in the afternoon, and 1 minute in the evening, it will charge me exactly for 7 minutes or 420,000 milliseconds, no less and no more.</p><p><strong>Language of your Choice: </strong>Hiring a variety of developers for language-specific servers isn’t a feasible option for startups, is it? However, this is a thing of the past, and the use of multiple languages is viable within serverless architecture.</p><p>You can have a python developer, node.js developer and C# developer, all working together for a single goal and none of them will be required to learn a new language at all!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf7731c74718" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>