<?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 Enyioma Nwadibia on Medium]]></title>
        <description><![CDATA[Stories by Enyioma Nwadibia on Medium]]></description>
        <link>https://medium.com/@enyioman?source=rss-71a63f34971d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GScwtbTuerPsxskQh6WU0A.jpeg</url>
            <title>Stories by Enyioma Nwadibia on Medium</title>
            <link>https://medium.com/@enyioman?source=rss-71a63f34971d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:50:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@enyioman/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[Implementing DevSecOps: Deploying a Netflix-Clone App on AWS EKS]]></title>
            <link>https://awstip.com/implementing-devsecops-deploying-a-netflix-clone-app-on-aws-eks-6b1078344ace?source=rss-71a63f34971d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b1078344ace</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Enyioma Nwadibia]]></dc:creator>
            <pubDate>Mon, 05 Feb 2024 10:07:26 GMT</pubDate>
            <atom:updated>2024-03-13T20:46:51.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S3vABAcMLrfaqrnFMmqVPQ.png" /><figcaption>Pipeline Architecture</figcaption></figure><p>Launching a Netflix-clone application using Amazon Web Services’ Elastic Kubernetes Service (AWS EKS) should require more than just deploying code; it should entail a culture of security, collaboration, and creativity. We will examine the subtleties of DevSecOps and use modern tools to create, secure, and release a productive application.</p><p>Jenkins, the foundation of our pipeline for continuous integration, is where our journey starts. We use Docker to containerize our application, and DockerHub as our repository. Sonarqube is used to thoroughly inspect each line of code to ensure fundamental security. Our diligent vulnerability scanner, Trivy, keeps watch to defend our containers from any threats, ensuring the reliability of our deployment.</p><p>Together, Prometheus and Grafana enable real-time monitoring and visualization, giving us a pulse on the health of our AWS EKS cluster, EC2 Servers, and Jenkins pipeline. Helm which is a Kubernetes package manager is used to simplify deployment complications. Our continuous delivery tool, ArgoCD, works in tandem with Helm to streamline and organize our deployment procedure.</p><p>Security in the cloud is critical, and AWS EKS offers our Netflix-inspired application a scalable and robust basis. However, this path entails a cultural revolution in addition to tools and platforms. Throughout the deployment lifetime, our pipeline’s automated email notifications promote team cohesion and communication.</p><p>With the short intro to the pipeline architecture out of the way, let’s get the project started.</p><h3><strong>Step 1: Infrastructure Provisioning and Local Deployment</strong></h3><p>For consistency, version control, reproducibility, auditability, and all the right reasons that Infrastructure as code has to offer, we are going to build the basic infrastructure with Terraform. The below script sets up a basic networking environment, provisions an EC2 instance of Ubuntu Server 22.04 LTS flavour with 20GB root volume. It also associates an Elastic IP with the instance.</p><pre>resource &quot;aws_vpc&quot; &quot;netflix&quot; {<br>  cidr_block           = &quot;172.31.0.0/16&quot;<br>  enable_dns_hostnames = true<br>  enable_dns_support   = true<br>  tags = {<br>    Name = &quot;NetflixClone&quot;<br>  }<br>}<br>resource &quot;aws_subnet&quot; &quot;netflix-subnet&quot; {<br>  vpc_id            = aws_vpc.netflix.id<br>  cidr_block        = &quot;172.31.0.0/16&quot;<br>  availability_zone = &quot;eu-west-2a&quot;<br><br>  tags = {<br>    Name = &quot;netflix&quot;<br>  }<br>}<br>resource &quot;aws_internet_gateway&quot; &quot;netflix-gw&quot; {<br>  vpc_id = aws_vpc.netflix.id<br>  tags = {<br>    Name = &quot;netflix-env-gw&quot;<br>  }<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;admin_role&quot; {<br>  name = &quot;NetflixAccessRole&quot;<br><br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;,<br>    Statement = [<br>      {<br>        Action = &quot;sts:AssumeRole&quot;,<br>        Effect = &quot;Allow&quot;,<br>        Principal = {<br>          Service = &quot;ec2.amazonaws.com&quot;,<br>        },<br>      },<br>    ],<br>  })<br>}<br><br># Attach the AdministratorAccess policy to the IAM role<br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;admin_role_attachment&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AdministratorAccess&quot;<br>  role       = aws_iam_role.admin_role.name<br>}<br><br>resource &quot;aws_iam_instance_profile&quot; &quot;admin_instance_profile&quot; {<br>  name = &quot;AdministratorAccessInstanceProfile&quot;<br>  role = aws_iam_role.admin_role.name<br>}<br><br><br>resource &quot;aws_instance&quot; &quot;netflix_server&quot; {<br>  ami                         = &quot;ami-0e5f882be1900e43b&quot;<br>  key_name                    = &quot;netflixkp&quot;<br>  instance_type               = &quot;t2.large&quot;<br>  vpc_security_group_ids      = [aws_security_group.netflix_sg.id]<br>  subnet_id                   = aws_subnet.netflix-subnet.id<br>  associate_public_ip_address = true<br>  iam_instance_profile        = aws_iam_instance_profile.admin_instance_profile.name<br>  user_data                   = file(&quot;netflix.sh&quot;)<br><br>  root_block_device {<br>    volume_type = &quot;gp3&quot;<br>    volume_size = 20<br>  }<br><br><br>  tags = {<br>    &quot;Name&quot; = &quot;Netflix Server&quot;<br>  }<br>}<br><br>resource &quot;aws_eip&quot; &quot;netflix_elastic_ip&quot; {<br>  vpc = true<br>  instance = aws_instance.netflix_server.id<br>}</pre><p>This will be our Jenkins Server. We’ll need to have Jenkins, Docker, and Trivy installed on this server. We’ll achieve that with the use of the below bash script netflix.sh:</p><pre>#!/bin/bash<br><br># Docker<br><br>sudo apt-get update -y<br>sudo apt-get install docker.io -y<br>sudo usermod -aG docker ubuntu<br>newgrp docker<br>sudo chmod 777 /var/run/docker.sock<br><br># Trivy<br><br>sudo apt-get install wget apt-transport-https gnupg lsb-release<br>wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -<br>echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list<br>sudo apt-get update -y<br>sudo apt-get install trivy -y       <br><br># Jenkins<br><br>sudo apt update -y<br>sudo apt install fontconfig openjdk-17-jre -y<br>java -version<br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br>/etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update -y<br>sudo apt-get install jenkins -y<br>sudo systemctl start jenkins<br>sudo systemctl enable jenkins<br><br><br># Clone repo<br><br>git clone https://github.com/enyioman/DevSecOps-Project.git<br><br># Rename hostname<br><br>sudo hostnamectl set-hostname jenkins_server</pre><p>Next, let’s SSH into the EC2, CD into the DevSecOps-Project repo, and build the application locally using docker.</p><pre>docker build -t netflix .<br>docker run -d --name netflix -p 8081:80 netflix:latest<br><br>#to delete<br>docker stop &lt;containerid&gt;<br>docker rmi -f netflix</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxUywWVh1A0pOlIBOfyk1g.png" /><figcaption>Docker images</figcaption></figure><p>We have to make sure the ports for application(8081), Jenkins(8080), and Sonarqube(9000) are open.</p><pre>resource &quot;aws_security_group&quot; &quot;netflix_sg&quot; {<br>  name   = &quot;netflix_sg&quot;<br>  vpc_id = aws_vpc.netflix.id<br><br>  ingress {<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  ingress {<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  ingress {<br>    from_port   = 8081<br>    to_port     = 8081<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  ingress {<br>    from_port   = 8080<br>    to_port     = 8080<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  ingress {<br>    from_port   = 9000<br>    to_port     = 9000<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  ingress {<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = -1<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    name = &quot;netflix_sg&quot;<br>  }<br>}<br>resource &quot;aws_route_table&quot; &quot;route-netflix-env&quot; {<br>  vpc_id = aws_vpc.netflix.id<br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.netflix-gw.id<br>  }<br>  tags = {<br>    Name = &quot;netflix-env-route-table&quot;<br>  }<br>}<br>resource &quot;aws_route_table_association&quot; &quot;subnet-association&quot; {<br>  subnet_id      = aws_subnet.netflix-subnet.id<br>  route_table_id = aws_route_table.route-netflix-env.id<br>}<br><br></pre><p>With the public ip of the EC2 and port 8081, navigate to the application. Oh crap! It failed to load because a TMDB API key is required for the app to run properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O_ydZmJPf1CaqXLr8R0Tng.png" /><figcaption>Unsuccessful Load</figcaption></figure><h3>Fetching the TMDB API Key</h3><ul><li>Open a web browser and navigate to TMDB (The Movie Database) website.</li><li>Click on “Login” and create an account.</li><li>Once logged in, go to your profile, and select “Settings.”</li><li>Click on “API” from the left side panel.</li><li>Create a new API key by clicking “Create” and accepting the terms and conditions.</li><li>Provide the required basic details and click “Submit.”</li><li>You will receive your TMDB API key.</li></ul><p>Afterward, remove the current Docker image and generate a new one using the provided API key.</p><pre>docker build --build-arg TMDB_V3_API_KEY=&lt;your-tmdb-api-key&gt; -t netflix .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtEKQu9yXUXpnBjbKT3Xwg.png" /><figcaption>Docker build with API</figcaption></figure><p>Run a new container from the new image and we should have a working application. Awesome!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3wObFiFQGbmKVxd-N8iyg.png" /><figcaption>Successful page load</figcaption></figure><h3>Step 2: Security Implementation</h3><p>We’ll make use of two efficient tools for this stage, Sonarqube and Trivy.</p><p><strong>SonarQube</strong> is designed for continuous code quality inspection and assessment in software projects. It employs static code analysis to identify and address issues related to code quality, security vulnerabilities, and adherence to coding standards. With support for multiple programming languages, SonarQube serves as a comprehensive tool for promoting best practices and maintaining a high level of code quality throughout the software development lifecycle.</p><p>We’ll set up Sonarqube using the official docker image and run it as a container.</p><pre>docker run -d --name sonar -p 9000:9000 sonarqube:lts-community</pre><p>We’ll access it using the public ip and port 9000. The default username and password is ‘admin’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q7e-Rh3eqE8klfchdpmN7g.png" /><figcaption>Sonarqube running</figcaption></figure><p><strong>Trivy</strong> is a vulnerability scanner designed for containerized environments, particularly focusing on container images and applications. It helps identify security vulnerabilities within container images by scanning their components and dependencies. Trivy utilizes an extensive vulnerability database to check for known security issues, including outdated libraries, common vulnerabilities, and exposures (CVEs), and other potential risks.</p><p>Recall that we earlier installed it via the EC2 user data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KfqGVb_4PynxpWi3MdtFCQ.png" /><figcaption>Trivy Installed</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K4fq2-soQZBFxO75ZAs7gw.png" /><figcaption>Trivy scan</figcaption></figure><h3>Step 3: CI/CD Setup</h3><p>We’ll make use of Jenkins for this stage. Jenkins is an open-source automation server widely used for continuous integration and continuous delivery (CI/CD) purposes. It enables the automation of building, testing, and deploying software applications, streamlining the development and release processes. It also supports integration with various version control systems, build tools, security and testing tools, and deployment platforms, allowing teams to create automated workflows tailored to their specific needs.</p><p>Recall that we installed Jenkins earlier also through the EC2 user data. Let’s confirm by checking the status.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cpPtkZ3ZohPXy3rD_kGiAg.png" /><figcaption>Jenkins active</figcaption></figure><p>Jenkins runs on port 8080 by default. Let’s navigate to it, set it up, and start integrating some of the needed tools for our pipeline. From the Jenkins Dashboard, navigate to Manage Jenkins →Plugins → Available Plugins. We’ll install the following plugins:</p><ol><li>Eclipse Temurin Installer (Install without restart)</li><li>SonarQube Scanner (Install without restart)</li><li>NodeJs Plugin (Install Without restart)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7SaDkVTlffEREbJcJJ64oQ.png" /><figcaption>Plugins installation</figcaption></figure><h3>Configure Java and Nodejs in Global Tool Configuration</h3><p>Goto Manage Jenkins → Tools → Install JDK(17) and NodeJs(16)→ Click on Apply and Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbapL1XI-77csKkL37YW0A.png" /><figcaption>Tools configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U19QmyAoVPGRvoYrGKHDhw.png" /><figcaption>Tools configuration</figcaption></figure><h3>Configure Sonar Server in Jenkins</h3><p>We’ll next go to our Sonarqube Server. Click on Administration → Security → Users → Click on Tokens and Update Token → Give it a name → and click on Generate Token. We’ll copy the token.</p><p>Back to our Jenkins Server, Jenkins Dashboard → Manage Jenkins → Credentials → Add Secret Text, we’ll paste the Sonarqube token in ‘Secret’ and use sonar-token as our ‘ID’ and ‘Description’.</p><p>Moving on, we head back to Manage Jenkins → System → Sonarqube Installations like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HL41Z06WOjPbodjvBRAEjA.png" /><figcaption>Jenkins Sonarqube configuration</figcaption></figure><p>Then, Manage Jenkins → Tools → Sonarqube Scanner installations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BXOJ7u7oPjqNad0W7BZkFg.png" /><figcaption>Jenkins Sonarqube configuration</figcaption></figure><p>It’s time to create the CI/CD pipeline in Jenkins to automate the deployment of our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bLWz0iA74e_cbUWYE8q9YQ.png" /><figcaption>Pipeline creation</figcaption></figure><p>Paste the following as the pipeline script:</p><pre>pipeline {<br>    agent any<br>    tools {<br>        jdk &#39;jdk17&#39;<br>        nodejs &#39;node16&#39;<br>    }<br>    environment {<br>        SCANNER_HOME = tool &#39;sonar-scanner&#39;<br>    }<br>    stages {<br>        stage(&#39;clean workspace&#39;) {<br>            steps {<br>                cleanWs()<br>            }<br>        }<br>        stage(&#39;Checkout from Git&#39;) {<br>            steps {<br>                git branch: &#39;main&#39;, url: &#39;https://github.com/enyioman/DevSecOps-Project.git&#39;<br>            }<br>        }<br>        stage(&quot;Sonarqube Analysis&quot;) {<br>            steps {<br>                withSonarQubeEnv(&#39;sonar-server&#39;) {<br>                    sh &#39;&#39;&#39;$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \<br>                    -Dsonar.projectKey=Netflix&#39;&#39;&#39;<br>                }<br>            }<br>        }<br>        stage(&quot;quality gate&quot;) {<br>            steps {<br>                script {<br>                    waitForQualityGate abortPipeline: false, credentialsId: &#39;sonar-token&#39;<br>                }<br>            }<br>        }<br>        stage(&#39;Install Dependencies&#39;) {<br>            steps {<br>                sh &quot;npm install&quot;<br>            }<br>        }<br>    }<br>}</pre><h3>Setup Projects in Sonarqube for Jenkins</h3><p>Go to Projects → Create Manually → Locally → Project display name (Netflix) → Setup → Generate new project token → Continue → Run analysis on your project (Choose ‘Other…’) → OS (for our case we’ll choose Linux).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xY3et-Tr071ZMB3_iNHHiQ.png" /><figcaption>Sonarqube project creation</figcaption></figure><p>We’ll head over to Jenkins and hit ‘Build Now’.S</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFkgDowygPpZM8i4FQJnBQ.png" /><figcaption>Pipeline running</figcaption></figure><p>Sonarqube should now have the analysis results with vulnerabilities and suggestions to checkmate them. The detailed report can be found under ‘issues’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsG9r8P2cvpUctf4pm_IVQ.png" /><figcaption>Sonarqube report</figcaption></figure><p><strong>Install the Dependency-Check Plugin and Docker Tools in Jenkins:</strong></p><ul><li>Navigate to Jenkins Dashboard.</li><li>Head to “Manage Jenkins” → “Manage Plugins.”</li><li>Switch to the “Available” tab and search for “OWASP Dependency-Check.”</li><li>Select the checkbox next to “OWASP Dependency-Check.”</li><li>Switch to the “Available” tab again and search for “Docker.”</li><li>Check the following Docker-related plugins:<br> — Docker<br> — Docker Commons<br> — Docker Pipeline<br> — Docker API<br> — docker-build-step</li><li>Click on the “Install without restart” button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuT-OfE33Xw1hvHIZwLBHQ.png" /><figcaption>Plugin Installation</figcaption></figure><p>After installing the plugins, we’ll need to configure them. Navigate to Dashboard → Manage Jenkins → Global Tool Configuration. Find the section for Dependency-Check. Add the tool’s name, e.g: “DP-Check”, then Apply and Save your settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRwFlSyB9l3pSPBuSqhbIg.png" /><figcaption>Plugin configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4oELbKwXfW13WzvH-xLOg.png" /><figcaption>Plugin configuration</figcaption></figure><p>After installing and configuring the Dependency-Check plugin, adding Docker-related plugins, and setting up our DockerHub credentials in Jenkins, we are ready to configure our Jenkins pipeline. We’ll ensure we update the TMDB_V3_API_KEY=&lt;your TMDB API key&gt; in the Docker build and push stage of the pipeline script below in accordance with our API key.</p><pre>pipeline{<br>    agent any<br>    tools{<br>        jdk &#39;jdk17&#39;<br>        nodejs &#39;node16&#39;<br>    }<br>    environment {<br>        SCANNER_HOME=tool &#39;sonar-scanner&#39;<br>    }<br>    stages {<br>        stage(&#39;clean workspace&#39;){<br>            steps{<br>                cleanWs()<br>            }<br>        }<br>        stage(&#39;Checkout from Git&#39;){<br>            steps{<br>                git branch: &#39;main&#39;, url: &#39;https://github.com/enyioman/DevSecOps-Project.git&#39;<br>            }<br>        }<br>        stage(&quot;Sonarqube Analysis &quot;){<br>            steps{<br>                withSonarQubeEnv(&#39;sonar-server&#39;) {<br>                    sh &#39;&#39;&#39; $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \<br>                    -Dsonar.projectKey=Netflix &#39;&#39;&#39;<br>                }<br>            }    <br>        }<br>        stage(&quot;quality gate&quot;){<br>           steps {<br>                script {<br>                    waitForQualityGate abortPipeline: false, credentialsId: &#39;sonar-token&#39; <br>                }<br>            } <br>        }<br>        stage(&#39;Install Dependencies&#39;) {<br>            steps {<br>                sh &quot;npm install&quot;<br>            }<br>        }<br>        stage(&#39;OWASP FS SCAN&#39;) {<br>            steps {<br>                dependencyCheck additionalArguments: &#39;--scan ./ --disableYarnAudit --disableNodeAudit&#39;, odcInstallation: &#39;DP-Check&#39;<br>                dependencyCheckPublisher pattern: &#39;**/dependency-check-report.xml&#39;<br>            }<br>        }<br>        stage(&#39;TRIVY FS SCAN&#39;) {<br>            steps {<br>                sh &quot;trivy fs . &gt; trivyfs.txt&quot;<br>            }<br>        }<br>        stage(&quot;Docker Build &amp; Push&quot;){<br>            steps{<br>                script{<br>                   withDockerRegistry(credentialsId: &#39;docker&#39;, toolName: &#39;docker&#39;){   <br>                       sh &quot;docker build --build-arg TMDB_V3_API_KEY=&lt;your TMDB API key&gt; -t netflix .&quot;<br>                       sh &quot;docker tag netflix fynewily/netflix:latest &quot;<br>                       sh &quot;docker push fynewily/netflix:latest &quot;<br>                    }<br>                }<br>            }<br>        }<br>        stage(&quot;TRIVY&quot;){<br>            steps{<br>                sh &quot;trivy image fynewily/netflix:latest &gt; trivyimage.txt&quot; <br>            }<br>        }<br>        stage(&#39;Deploy to container&#39;){<br>            steps{<br>                sh &#39;docker run -d -p 8081:80 fynewily/netflix:latest&#39;<br>            }<br>        }<br>    }<br>}</pre><p>After a successful build, we should have a netflix clone container running and also an image uploaded to DockerHub registory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOGzewrpOHlMxDZ5rnvFSQ.png" /><figcaption>Pipeline build</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cF4tt0eROPPNS9_smCzhIQ.png" /><figcaption>App deployed by pipeline</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4ShhQuCOeTv5PTFdYWv5w.png" /><figcaption>Image pushed to Dockerhub</figcaption></figure><h3><strong>Step 4: Configure Jenkins Email Notification</strong></h3><p>We’re incorporating email notification as our pipeline post build step to inform us about the build status and provide necessary details for troubleshooting or reviewing the build results.</p><p>First, we’ll need to have Two-factor Authentication enabled in our email. Then, we’ll generate a Gmail App Password by following these steps. On our Gmail account → Settings → Search “app password” → Give it a name → Create.</p><p>Back to Jenkins Dashboard → Manage Jenkins → Credentials → System → Global credentials(unrestricted) → Add Credentials → Create a new credential as Email and Password → Input email and generated password → Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lgsf10IbzVFTY64F49KWmQ.png" /><figcaption>Notification configuration</figcaption></figure><p>Next, Jenkins Dashboard → Manage Jenkins → System → Email Notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VytduLWm6GataLwT7sWVtQ.png" /><figcaption>Notification configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FWj55Buh8NozESzoDJACtg.png" /><figcaption>Notification configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVNT-fLz_QfzFQ3ORzh3GQ.png" /><figcaption>Notification testing</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRvcjQJ9K_R-ararOfxj1A.png" /><figcaption>Notification configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KxB6Edl0-T-Hn4_yjvJWQg.png" /><figcaption>Notification configuration</figcaption></figure><p>Update the pipeline with the following script and build the pipeline one more time.</p><pre>post {<br>  always {<br>    emailext(<br>      attachLog: true,<br>      subject: &quot;&#39;${currentBuild.result}&#39;&quot;,<br>      body: &quot;Project: ${env.JOB_NAME}&lt;br/&gt;&quot; +<br>            &quot;Build Number: ${env.BUILD_NUMBER}&lt;br/&gt;&quot; +<br>            &quot;URL: ${env.BUILD_URL}&lt;br/&gt;&quot;,<br>      to: &#39;example@gmail.com&#39;,<br>      attachmentsPattern: &#39;trivyfs.txt,trivyimage.txt&#39;<br>    )<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0sDhf-mveNqhfnrVeNxyPg.png" /><figcaption>Pipeline Notification</figcaption></figure><h3>Step 5: Monitoring</h3><p>Monitoring and observability are integral to CI/CD pipelines as they ensure the stability, reliability, and performance of applications, facilitate early issue detection, and support a continuous improvement mindset in software development and deployment processes. For our project, we’ll use Prometheus and Grafana for this purpose.</p><p>Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability. It collects and stores time-series data from various sources, allowing users to query and visualize metrics, set up alerts, and gain insights into the performance and health of their systems.</p><p>Node Exporter is a Prometheus exporter that gathers various metrics about the host machine’s hardware and operating system. It exposes these metrics in a format that Prometheus can scrape, providing valuable information for monitoring and analysis.</p><p>Grafana is an open-source platform for monitoring and observability that integrates with various data sources, including Prometheus. Grafana enables users to create interactive and customizable dashboards, visualizing data from different sources. It is commonly used to build visually appealing and informative displays for monitoring metrics and performance in real-time.</p><p>We’ll spin up another EC2 using Terraform plus a skeletal installation bash script of the needed tools as its user data. We’ll not forget to enable the default ports for the tools: Prometheus(Port 9090), Node Exporter(Port 9100), and Grafana(Port 3000). Let’s get it:</p><pre>resource &quot;aws_instance&quot; &quot;monitoring_server&quot; {<br>  ami                         = &quot;ami-0e5f882be1900e43b&quot;<br>  key_name                    = &quot;netflixkp&quot;<br>  instance_type               = &quot;t2.medium&quot;<br>  vpc_security_group_ids      = [aws_security_group.netflix_sg.id]<br>  subnet_id                   = aws_subnet.netflix-subnet.id<br>  associate_public_ip_address = true<br>  iam_instance_profile        = aws_iam_instance_profile.admin_instance_profile.name<br>  user_data                   = file(&quot;monitoring.sh&quot;)<br><br>  root_block_device {<br>    volume_type = &quot;gp3&quot;<br>    volume_size = 20<br>  }<br><br>  tags = {<br>    &quot;Name&quot; = &quot;Monitoring Server&quot;<br>  }<br>}<br><br>resource &quot;aws_eip&quot; &quot;monitoring_elastic_ip&quot; {<br>  vpc = true<br>  instance = aws_instance.monitoring_server.id<br>}</pre><pre>#!/bin/bash<br><br># Installing Prometheus<br><br>sudo useradd --system --no-create-home --shell /bin/false prometheus<br>wget https://github.com/prometheus/prometheus/releases/download/v2.47.1/prometheus-2.47.1.linux-amd64.tar.gz<br>tar -xvf prometheus-2.47.1.linux-amd64.tar.gz<br>cd prometheus-2.47.1.linux-amd64/<br>sudo mkdir -p /data /etc/prometheus<br>sudo mv prometheus promtool /usr/local/bin/<br>sudo mv consoles/ console_libraries/ /etc/prometheus/<br>sudo mv prometheus.yml /etc/prometheus/prometheus.yml<br>sudo chown -R prometheus:prometheus /etc/prometheus/ /data/<br><br>#Installing Node Exporter<br><br>sudo useradd --system --no-create-home --shell /bin/false node_exporter<br>wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz<br>tar -xvf node_exporter-1.6.1.linux-amd64.tar.gz<br>sudo mv node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/<br>rm -rf node_exporter*<br><br># Installing Grafana<br><br>sudo apt-get update<br>sudo apt-get install -y apt-transport-https software-properties-common<br>wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -<br>echo &quot;deb https://packages.grafana.com/oss/deb stable main&quot; | sudo tee -a /etc/apt/sources.list.d/grafana.list<br>sudo apt-get update<br>sudo apt-get -y install grafana<br>sudo systemctl enable grafana-server<br>sudo systemctl start grafana-server<br><br># Rename hostname<br><br>sudo hostnamectl set-hostname monitoringserver</pre><p>Let’s finalize Prometheus installation by creating a systemd unit configuration file for Prometheus.</p><pre>sudo vi /etc/systemd/system/prometheus.service</pre><p>We’ll add the following to the file:</p><pre>[Unit]<br>Description=Prometheus<br>Wants=network-online.target<br>After=network-online.target<br><br>StartLimitIntervalSec=500<br>StartLimitBurst=5<br><br>[Service]<br>User=prometheus<br>Group=prometheus<br>Type=simple<br>Restart=on-failure<br>RestartSec=5s<br>ExecStart=/usr/local/bin/prometheus \<br>  --config.file=/etc/prometheus/prometheus.yml \<br>  --storage.tsdb.path=/data \<br>  --web.console.templates=/etc/prometheus/consoles \<br>  --web.console.libraries=/etc/prometheus/console_libraries \<br>  --web.listen-address=0.0.0.0:9090 \<br>  --web.enable-lifecycle<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>This unit file is an essential part of setting up Prometheus as a systemd service. It ensures proper dependencies, restart behavior, and configuration for running Prometheus as a background service on a Linux system. The Prometheus service is configured to start after the network is online, and it will automatically restart in case of failure. The provided ExecStart command includes necessary parameters for Prometheus to operate effectively.</p><p>Next, we’ll enable and start Prometheus. Then, verify its status.</p><pre>sudo systemctl enable prometheus<br>sudo systemctl start prometheus<br><br>sudo systemctl status prometheus</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NUNw77EeNGbY-NOGkEyzg.png" /><figcaption>Prometheus up and running</figcaption></figure><p>Awesome!!! Prometheus is now active and running. We’ll access it through the public IP and on port 9090:</p><pre>http://&lt;your-server-ip&gt;:9090</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aq4QRXq0XgMZWr7nd21yaw.png" /><figcaption>Prometheus interface</figcaption></figure><p>We’ll navigate to Status → Target, to get the targets that prometheus is to scrape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_PBFRexVtqrgPNPwlEayA.png" /><figcaption>Prometheus targets</figcaption></figure><p><strong>Node Exporter Configuration</strong></p><p>Similarly, we’ll create a systemd unit configuration file for Node Exporter:</p><pre>sudo vi /etc/systemd/system/node_exporter.service</pre><pre>[Unit]<br>Description=Node Exporter<br>Wants=network-online.target<br>After=network-online.target<br><br>StartLimitIntervalSec=500<br>StartLimitBurst=5<br><br>[Service]<br>User=node_exporter<br>Group=node_exporter<br>Type=simple<br>Restart=on-failure<br>RestartSec=5s<br>ExecStart=/usr/local/bin/node_exporter --collector.logind<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Enable and start Node Exporter:</p><pre>sudo systemctl enable node_exporter<br>sudo systemctl start node_exporter</pre><p>Verify its status:</p><pre>sudo systemctl status node_exporter</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45dCaSujgho2Qm1d1X1v3A.png" /><figcaption>Node Exporter active</figcaption></figure><p>Next, we’ll need to define scraping intervals and targets for metric collection by modifying our /etc/prometheus/prometheus.yml file. We’ll first add a job for the Node Exporter. This will also add a new target for Prometheus to monitor and scrape.</p><pre>sudo vi /etc/prometheus/prometheus.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QL3Bkd-bHtP9gYVi0bE5vg.png" /><figcaption>Node Exporter Job</figcaption></figure><p>We can use Promtool to check the syntax of the config. If it’s successful, we then go ahead and reload Prometheus configuration without restarting.</p><pre>promtool check config /etc/prometheus/prometheus.yml</pre><pre>curl -X POST http://localhost:9090/-/reload</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBcXRBzY4OHk4EDIQ8XFXw.png" /><figcaption>Syntax check and Prometheus reload</figcaption></figure><p>On refreshing the Prometheus Target page, we should have a new target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a97zyEdVsS_VFxck27AIKw.png" /><figcaption>New Target Added</figcaption></figure><p>Likewise, let’s integrate Jenkins with Prometheus to monitor the CI/CD pipeline. First we’ll install the Prometheus metrics plugin on Jenkins. The installation will entail restarting Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76C0sR7_VPKqKDFL8TWlRQ.png" /><figcaption>Prometheus on Jenkins</figcaption></figure><p>Then add a Job for the Jenkins Prometheus Metrics on the Prometheus Server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlW7O8X0wOitEyg0mJFNvg.png" /><figcaption>Jenkins job</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VqAYGq-v2zZYN_5Ag5hOg.png" /><figcaption>Jenkins target</figcaption></figure><p><strong>Grafana</strong></p><p>We’ve already installed Grafana via the user data script. Let’s confirm its status.</p><pre>sudo systemctl status grafana-server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGZCIJheufRp-S9h8lKBkQ.png" /><figcaption>Grafana running</figcaption></figure><p>Grafana User Interface can be accessed through the server public IP on port 3000 by default. The default username and password is ‘admin’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFkIEYqyrVEfR5aO2abr3Q.png" /><figcaption>Grafana UI</figcaption></figure><p><strong>Prometheus Data Source Integration</strong></p><p>You can add a data source and enable metric display by doing the following :</p><ul><li>First, choose “Data Sources.”</li><li>Press the button labeled “Add data source.”</li><li>Select the “Prometheus” data source type.</li><li>Within the “HTTP” segment:</li><li>Put <a href="http://http/">http://&lt;prometheus-server-ip&gt;:&lt;prometheus-port&gt;</a> in the “URL” field.</li><li>To ensure that the data source has been successfully integrated, click “Save &amp; Test.”</li></ul><p>By following these steps, you can be sure Grafana is set up to efficiently retrieve and show metrics from Prometheus.</p><p><strong>Importing Dashboards:</strong></p><p>We’ll import pre-configured dashboards to make analysing metrics easier by following the below steps:</p><ul><li>To access the “Create” menu, click the “+” (plus) button in the left sidebar.</li><li>Select “Dashboard.”</li><li>Select the dashboard option labeled “Import.”</li><li>Type in the dashboard code (such as code 1860 for Node Exporter and 9964 for Prometheus) that you want to import.</li><li>Select “Load” from the menu.</li><li>Choose the data source (Prometheus) that you added earlier from the dropdown menu.</li><li>Select “Import” to complete the procedure.</li></ul><p>With these methods, you may expeditiously integrate and display the appropriate dashboard in Grafana, thereby optimizing your monitoring workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egR2LZTnjgZ0XgQYdmTStg.png" /><figcaption>Dashboard import</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NL8cuBpPsOoHW7olFvU-UQ.png" /><figcaption>Node Exporter Dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dS_TO1SQoyJEU2vyEnjx8w.png" /><figcaption>Prometheus Dashboard</figcaption></figure><h3><strong>Step 6: Kubernetes (EKS)</strong></h3><p>Similar to the other infrastructure, we will set up EKS using Terraform. Note that this is a skeletal configuration and therefore might not be very optimal.</p><pre>data &quot;aws_iam_policy_document&quot; &quot;assume_role&quot; {<br>  statement {<br>    effect = &quot;Allow&quot;<br><br>    principals {<br>      type        = &quot;Service&quot;<br>      identifiers = [&quot;eks.amazonaws.com&quot;]<br>    }<br><br>    actions = [&quot;sts:AssumeRole&quot;]<br>  }<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;netflix_role&quot; {<br>  name               = &quot;eks-cluster-cloud&quot;<br>  assume_role_policy = data.aws_iam_policy_document.assume_role.json<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;netflix-AmazonEKSClusterPolicy&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSClusterPolicy&quot;<br>  role       = aws_iam_role.netflix_role.name<br>}<br><br>#get vpc data<br>data &quot;aws_vpc&quot; &quot;netflix_sg&quot; {<br>  default = true<br>}<br>#get public subnets for cluster<br>data &quot;aws_subnets&quot; &quot;public&quot; {<br>  filter {<br>    name   = &quot;vpc-id&quot;<br>    values = [data.aws_vpc.netflix_sg.id]<br>  }<br><br>   filter {<br>    name   = &quot;availability-zone&quot;<br>    values = [&quot;eu-west-2a&quot;, &quot;eu-west-2b&quot;, &quot;eu-west-2c&quot;, &quot;eu-west-2d&quot;]<br>  }<br>}<br>#cluster provision<br>resource &quot;aws_eks_cluster&quot; &quot;netflix_cluster&quot; {<br>  name     = &quot;NETFLIX_CLUSTER&quot;<br>  role_arn = aws_iam_role.netflix_role.arn<br><br>  vpc_config {<br>    subnet_ids = data.aws_subnets.public.ids<br>  }<br><br>  # Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.<br>  # Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.<br>  depends_on = [<br>    aws_iam_role_policy_attachment.netflix-AmazonEKSClusterPolicy,<br>  ]<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;netflix_role2&quot; {<br>  name = &quot;eks-node-group-cloud&quot;<br><br>  assume_role_policy = jsonencode({<br>    Statement = [{<br>      Action = &quot;sts:AssumeRole&quot;<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;ec2.amazonaws.com&quot;<br>      }<br>    }]<br>    Version = &quot;2012-10-17&quot;<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;netflix-AmazonEKSWorkerNodePolicy&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy&quot;<br>  role       = aws_iam_role.netflix_role2.name<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;netflix-AmazonEKS_CNI_Policy&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy&quot;<br>  role       = aws_iam_role.netflix_role2.name<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;netflix-AmazonEC2ContainerRegistryReadOnly&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly&quot;<br>  role       = aws_iam_role.netflix_role2.name<br>}<br><br>#create node group<br>resource &quot;aws_eks_node_group&quot; &quot;netflix_nodes&quot; {<br>  cluster_name    = aws_eks_cluster.netflix_cluster.name<br>  node_group_name = &quot;Node-cloud&quot;<br>  node_role_arn   = aws_iam_role.netflix_role2.arn<br>  subnet_ids      = data.aws_subnets.public.ids<br><br>  scaling_config {<br>    desired_size = 1<br>    max_size     = 1<br>    min_size     = 1<br>  }<br>  instance_types = [&quot;t3.medium&quot;]<br><br>  # Ensure that IAM Role permissions are created before and deleted after EKS Node Group handling.<br>  # Otherwise, EKS will not be able to properly delete EC2 Instances and Elastic Network Interfaces.<br>  depends_on = [<br>    aws_iam_role_policy_attachment.netflix-AmazonEKSWorkerNodePolicy,<br>    aws_iam_role_policy_attachment.netflix-AmazonEKS_CNI_Policy,<br>    aws_iam_role_policy_attachment.netflix-AmazonEC2ContainerRegistryReadOnly,<br>  ]<br>}</pre><p>The Terraform script provisions an Amazon EKS cluster on AWS, along with associated resources. We create IAM roles and policies, defining permissions for EKS and the associated node group. VPC and subnet information is retrieved, and an EKS cluster is established, linking it to the specified VPC and subnets. Additionally, we create an EKS node group, configuring instance types, scaling, and associating it with the EKS cluster.</p><p>We’ll update our kubeconfig file afterwards:</p><pre>aws eks update-kubeconfig --name &lt;cluster-name&gt; --region &lt;your-region&gt;</pre><p>Then install ArgoCD. ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It allows users to maintain and manage Kubernetes applications using Git repositories as the source of truth for the desired application state. ArgoCD automates the deployment, monitoring, and lifecycle management of applications in Kubernetes clusters.</p><pre>kubectl create namespace argocd<br>kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.7/manifests/install.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxCU0mXIvAh8Pvv4zFZPOg.png" /><figcaption>ArgoCD installed</figcaption></figure><p>Let’s expose the ArgoCD service:</p><pre>kubectl patch svc argocd-server -n argocd -p &#39;{&quot;spec&quot;: {&quot;type&quot;: &quot;LoadBalancer&quot;}}&#39;</pre><p><strong>Install Node Exporter Using Helm</strong></p><p>We’ll use Node Exporter to collect our Kubenetes Cluster Nodes system-level metrics. Helm is a requisite though and can be installed via this <a href="https://helm.sh/docs/intro/install/">link</a> if you don’t already have it. Helm is a package manager for Kubernetes applications. It simplifies the process of defining, installing, and upgrading even the most complex Kubernetes applications. Install Node Exporter using Helm through the following steps:</p><p>a. Add the Prometheus Community Helm repository:</p><pre>helm repo add prometheus-community https://prometheus-community.github.io/helm-charts</pre><p>b. Create a Kubernetes namespace for the Node Exporter:</p><pre>kubectl create namespace prometheus-node-exporter</pre><p>c. Install the Node Exporter using Helm:</p><pre>helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace prometheus-node-exporter</pre><p>We’ll add a Job to scrape metrics on nodeip:9001/metrics. We can achieve this by adding the following configuration to our prometheus.yml file and reloading Prometheus afterward:</p><pre>  - job_name: &quot;Netflix App&quot;<br>    metrics_path: &quot;/metrics&quot;<br>    static_configs:<br>      - targets: [&quot;node1Ip:9100&quot;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSiV561eHqEnMGQhYgYn9A.png" /><figcaption>Cluster Monitoring</figcaption></figure><p><strong>Configuring ArgoCD</strong></p><p>Let’s fetch ArgoCD LoadBalancer URL.</p><pre>export ARGOCD_SERVER=`kubectl get svc argocd-server -n argocd -o json | jq --raw-output &#39;.status.loadBalancer.ingress[0].hostname&#39;`<br>echo $ARGOCD_SERVER</pre><p>Copy and paste it in a browser. Click on the ‘Advanced’ settings and accept the risk. Lol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eDHOj5o2rT2r3f4CfLLNJg.png" /><figcaption>ArgoCD setup</figcaption></figure><p>To login, default username is “admin” but we’ll need to fetch the password like so:</p><pre>export ARGO_PWD=`kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=&quot;{.data.password}&quot; | base64 -d`<br>echo $ARGO_PWD</pre><p>Let’s connect ArgoCD to our repo. Navigate to Settings → Repositories → Connect Repo Using HTTPS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fINgLKliChzlCOjDcXQGPg.png" /><figcaption>Connecting Repo</figcaption></figure><p>Next, we head to Manage Applications → New App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeEz4ngOvLZVd1gICxhefA.png" /><figcaption>App creation 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YgK3cPqbXOB39iLJV1BMVQ.png" /><figcaption>App creation 2</figcaption></figure><p>We’ll access the application through the node public IP on port 30007 (ensure you enable port 30007 on the Node Cluster Security Group).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eP2CpC5vhTROPVmQIybC2Q.png" /><figcaption>App running</figcaption></figure><p>Awesome! We have our App running in Kubernetes with CD managed by ArgoCD.</p><h3><strong>Step 7: Cleanup</strong></h3><p>For this setup, we’ll simply terraform destroy the whole building and that’s it. Lol!!!</p><h3><strong>Summary</strong></h3><p>Phew! It’s been a long read and build. Congratulations for coming thus far. We successfully built a DevSecOps Pipeline Application using Jenkins as our CI tool, Sonarqube, OWASP, and Trivy to handle security and vulnerability detection, Docker to containerize our App. We also made use of a GitOps tool, ArgoCD for Continous Deployment to AWS EKS, and Helm for Kubernetes applications management. We were also able to gain insight into our application, cluster and pipeline with the use of Prometheus and Grafana.</p><p>Do follow me on <a href="https://www.linkedin.com/in/enyioman/">LinkedIn</a> and <a href="https://twitter.com/enyiomann">X</a> for more.</p><p>Please don’t forget to <strong>clap</strong> and <strong>share</strong> to help others.</p><p>Thank you!</p><p>References:</p><p><a href="https://github.com/N4si/DevSecOps-Project">https://github.com/N4si/DevSecOps-Project</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b1078344ace" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/implementing-devsecops-deploying-a-netflix-clone-app-on-aws-eks-6b1078344ace">Implementing DevSecOps: Deploying a Netflix-Clone App on AWS EKS</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[Elevating Customer Experience: Streamlining Workflows with AWS S3 Event Triggers]]></title>
            <link>https://awstip.com/elevating-customer-experience-streamlining-workflows-with-aws-s3-event-triggers-c0e481dee275?source=rss-71a63f34971d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e481dee275</guid>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Enyioma Nwadibia]]></dc:creator>
            <pubDate>Wed, 30 Aug 2023 21:03:48 GMT</pubDate>
            <atom:updated>2023-09-01T12:25:04.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*RyydkQwVL7DPQNJ5e460zg.png" /><figcaption>Project Architecture</figcaption></figure><p><strong>Introduction</strong></p><p>In this era of instant communication and real-time data processing, businesses are constantly seeking ways to keep their customers informed about the latest updates and events. Amazon Web Services (AWS) offers a powerful combination of services that allows companies to achieve just that. In this article, we’ll dive into how you can leverage AWS Lambda and AWS SNS to automate customer notifications when objects are uploaded to an S3 bucket.</p><p>AWS S3 (Amazon Simple Storage Service) event triggering solves the problem of efficiently responding to changes in data stored within S3 buckets. S3 is a highly scalable object storage service provided by Amazon Web Services, and it’s commonly used for storing and managing vast amounts of data, such as images, videos, log files, backups, and more.</p><p>S3 event triggering allows you to set up event notifications for specific actions that occur within your S3 buckets, such as object creation, deletion, or modification. When these actions occur, S3 can automatically invoke AWS Lambda functions, SQS (Simple Queue Service) queues, SNS (Simple Notification Service) topics, or other AWS services. This capability solves several problems which include Real-time processing, efficiency, automation, scalability, cost-savings, and decoupling.</p><p>Use cases for S3 event triggering are diverse and include things like real-time image processing, log analysis, triggering data replication, updating search indexes, notifying users about new content, and much more. In essence, S3 event triggering helps streamline processes, reduce latency, and enable more responsive and dynamic applications by reacting to changes in your S3 data in an automated and efficient manner.</p><p><strong>1. The Power of Event-Driven Architecture</strong></p><p>Traditional approaches to notifying customers about new content often involve manual checks or scheduled processes. However, with event-driven architecture, we can create a seamless and responsive system that automatically alerts customers as soon as new data becomes available. AWS provides the tools to set up event triggers that kick-start workflows when specific events occur, and S3 buckets are a perfect candidate for such triggers.</p><p><strong>2. Setting Up the Event Trigger</strong></p><p>The first step in this process is configuring the event trigger on our S3 bucket. We define the event that should be monitored (e.g., object creation) and specify the action(s) to be taken when the event occurs. This action is where AWS Lambda comes into play.</p><p><strong>3. AWS Lambda: Your Automation Powerhouse</strong></p><p>AWS Lambda is a serverless compute service that allows us to run code without provisioning or managing servers. When an S3 object creation event takes place, AWS Lambda can automatically execute a function we’ve defined, processing the uploaded object in real-time.</p><p><strong>4. Custom Logic and Customer Engagement</strong></p><p>Inside the Lambda function, we can implement custom logic that suits our business needs. For our scenario, we want to send notifications to subscribed customers whenever a new object is uploaded. This might involve content-specific processing, data validation, or any other required transformations.</p><p><strong>5. Defining IAM Roles and Policies</strong></p><p>To enable secure interactions between services, IAM roles and policies need to be carefully configured.</p><ul><li>Lambda Execution Role: We’ll create an IAM role for the Lambda function. We will attach the AWSLambdaBasicExecutionRole policy for basic Lambda execution. Additionally, we can create a custom policy that grants s3:GetObject permissions on the relevant S3 bucket.</li><li>SNS Publishing Policy: We’ll craft an IAM policy that permits publishing messages to the SNS topic and attach this policy to the Lambda execution role.</li></ul><p><strong>6. Introducing AWS SNS for Notifications</strong></p><p>To deliver notifications to customers, we’ll integrate AWS Lambda with AWS SNS (Simple Notification Service). SNS provides a flexible and scalable way to send messages to a variety of endpoints. We’ll create an SNS topic that acts as a central communication channel for these messages.</p><p><strong>7. The Subscription Model</strong></p><p>Our Customers who already are subscribed to the SNS topic will receive a notification whenever a new object is uploaded into the S3 bucket. They can choose their preferred delivery methods, such as email, SMS, or even custom endpoints. For this project, we’ll stick with email notifications.</p><p><strong>8. Crafting and Sending Notifications</strong></p><p>Once our Lambda function has processed the object, it’s time to craft the notification. This could include relevant information about the uploaded content, links, or any other contextual details. Using shell scripts, we’ll make our Lambda function send the notification message to the subscribed SNS topic.</p><p><strong>9. Real-Time Engagement</strong></p><p>With the infrastructure in place, our customers will receive notifications in real-time or near-real-time, depending on their chosen delivery methods. This immediacy of communication enhances their experience and keeps them engaged with the latest updates from our business.</p><p>Now that we have the planning and designing out of the way, let’s roll up our sleeves and get to work.</p><p>Firstly, we’ll need to install and configure AWS CLI on our host machine. This <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">guide</a> will help in achieving that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hK2PRzEqKxUWFCgNooiwCQ.png" /><figcaption>AWS CLI installed</figcaption></figure><p>Next, we’ll install the following packages: jq and zip. Using shell script, we’ll create an S3 bucket, Lambda function, IAM role and policies and SNS topic. We will attach permissions policies to the IAM role granting it access to AWS Lambda and AWS SNS, upload a file to the S3 bucket, create a zip file containing a Lambda function code, add permissions to the S3 bucket to invoke the Lambda function, configure an S3 event trigger for the Lambda function causing it to be triggered whenever a new object is uploaded, subscribe the specified email address to the SNS topic, and publish a message to the SNS topic when the Lambda function is triggered.</p><p>We’ll create a file named `s3-event-trigger.sh` and then paste the following shell script from the gist:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7efbe238a16c6716932efae1402d11e6/href">https://medium.com/media/7efbe238a16c6716932efae1402d11e6/href</a></iframe><p>Create a directory s3-lambda-function. In the directory, create two files s3-lambda-function.py and requirements.txt.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9895daa93b1eb29def2fd87f5a085e60/href">https://medium.com/media/9895daa93b1eb29def2fd87f5a085e60/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4ba0407945851356bbaae1fa6e93654/href">https://medium.com/media/e4ba0407945851356bbaae1fa6e93654/href</a></iframe><p>Run the script with ./s3-event-trigger.sh, it’ll be executed if there are no errors. You’ll recieve an email to confirm your subscription to AWS SNS. Upload a new file to the S3 to validate that we have an efficient solution.</p><pre>aws s3 cp example_file4.txt s3://&lt;bucket-name&gt;/example_file4.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddVU-e3U5SWN3z6gKAwJdw.png" /><figcaption>SNS notification</figcaption></figure><p>Voila!!! We’ve just built an efficient and scalable event-driven solution that can be tweaked to so many other use cases.</p><p><strong>Conclusion</strong></p><p>In a fast-paced digital landscape, automated customer engagement is key to staying competitive. Leveraging AWS Lambda and AWS SNS to automate customer notifications based on S3 object uploads brings your communication strategy to a new level. By creating a dynamic, event-driven system, you ensure that your customers are always in the loop, receiving timely updates as soon as new content is available. As you integrate these AWS services into your workflows, you empower your business to provide exceptional customer experiences that are both responsive and informative.</p><p>The full tutorial can be found here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZOGeOmla5Sw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZOGeOmla5Sw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZOGeOmla5Sw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d51e0b78fdd3f94c76022304799a4c28/href">https://medium.com/media/d51e0b78fdd3f94c76022304799a4c28/href</a></iframe><p>Thank you for making it this far. Please don’t forget to give your claps, share, and follow me for more DevOps content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e481dee275" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/elevating-customer-experience-streamlining-workflows-with-aws-s3-event-triggers-c0e481dee275">Elevating Customer Experience: Streamlining Workflows with AWS S3 Event Triggers</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[CRUD Application Using API Gateway, Lambda, DynamoDB, and Python]]></title>
            <link>https://awstip.com/crud-application-using-api-gateway-lambda-dynamodb-and-python-84d486c87df4?source=rss-71a63f34971d------2</link>
            <guid isPermaLink="false">https://medium.com/p/84d486c87df4</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Enyioma Nwadibia]]></dc:creator>
            <pubDate>Wed, 28 Dec 2022 11:56:26 GMT</pubDate>
            <atom:updated>2024-02-13T18:35:54.787Z</atom:updated>
            <content:encoded><![CDATA[<h4>A tutorial with a complete working cloud-native and serverless CRUD application.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*kulXFyTaywex_aU6eUyPRA.png" /></figure><h3><strong>Objectives:</strong></h3><p>I will demonstrate how to use boto3 and python to create a Lambda function in the AWS interface for CRUD (Create, Read, Update, Delete) operations. Then use the API gateway in the AWS interface to create an API. When the API is called, the API Gateway will direct the call to the Lambda function, which will in turn process data in the DynamoDB table. The response ought to subsequently be sent back via the API Gateway. We will build an API that has the following operations:</p><ul><li>GET \health</li><li>GET \student</li><li>GET \students</li><li>POST \student</li><li>PATCH \student</li><li>DELETE \student</li></ul><h3>Technologies Used</h3><p>The technologies used in this guide are:</p><ul><li><strong>AWS Lambda</strong> (<a href="https://aws.amazon.com/lambda/">https://aws.amazon.com/lambda/</a>) for running code without provisioning servers</li><li><strong>AWS API Gateway</strong> (<a href="https://aws.amazon.com/api-gateway/">https://aws.amazon.com/api-gateway/</a>) for Serverless API creation &amp; management</li><li><strong>AWS Lambda (</strong><a href="https://aws.amazon.com/lambda/">https://aws.amazon.com/lambda/</a>) for serverless code execution</li><li><strong>AWS Identity and Access Management (IAM) </strong>(<a href="https://aws.amazon.com/iam/">https://aws.amazon.com/iam/</a>) for creating a role for the Lambda function</li></ul><p><strong>Setting up the Database</strong></p><p>Log in to AWS and navigate to the <strong>DynamoDB</strong> service. Then click <strong>Create table. </strong>Choose a primary key (I used <strong><em>studentId</em></strong>), give your table a name (I called mine <strong><em>students-data</em></strong>), and then click <strong>Create</strong>. The primary key you choose must uniquely identify each item in the table so that no two objects can share the same key. This is why it is crucial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4azySYzX6iprSlzCgqkGig.png" /><figcaption>table creation</figcaption></figure><h3>Creating the Lambda Role</h3><p>AWS roles essentially serve as a means of granting internal access between AWS services. We’ll create a role and assign it to our Lambda functions. These functions will be permitted access to our DynamoDB table with the help of this role.</p><p>Click <strong>Roles</strong> on the <strong>AWS IAM</strong> service. Click <strong>Create role. </strong>Select Lambda as the service that will use the role. Then click <strong>Next: Permissions. </strong>We now need to attach a permission policy to that role. Search for <strong><em>AmazonDynamoDBFullAccess</em></strong>, check the checkbox, and do the same for <strong><em>CloudWatchFullAccess</em></strong> and <strong><em>AWSLambda_FullAccess</em></strong> permission policies. Click <strong>Next</strong> and, on the review page provide a name for your role (I chose <strong><em>serverless-api-role</em></strong>). Finally, click <strong>Create role.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-V4K2SO2ASB3wDamIN0NMg.png" /><figcaption>IAM role</figcaption></figure><h3>Creating Lambda Functions:</h3><p>Navigate to the Lambda service in AWS and click <strong>Create Function. </strong>Because we’re creating this function from scratch, click <strong>Author from scratch</strong>. Choose <strong>Python 3.9</strong> as the Runtime, name your function (I went with <strong><em>students-lambda-funtions</em></strong>), and utilize the role with permissions we previously generated for the execution role (<strong><em>serverless-api-role</em></strong> in my case). Finally, select <strong>Create function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A5-_0Fvg_V0TSkRGpVuShg.png" /><figcaption>lambda functions</figcaption></figure><p>We’ll replace the lambda code with the following python codes and click <strong>Deploy</strong> thereafter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d1865ce64b3b3ec8633da2ae22b3ee5/href">https://medium.com/media/9d1865ce64b3b3ec8633da2ae22b3ee5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9835ed7c1750bc3282380dcca0e534cb/href">https://medium.com/media/9835ed7c1750bc3282380dcca0e534cb/href</a></iframe><h3>Creating the API</h3><p>With the Lambda function created, we can begin creating our Serverless API. Navigate to AWS API Gateway and click <strong>Get started, </strong>select <strong>REST API,</strong> and click on <strong>Build</strong>. Name your API (I called mine <strong><em>student-data-api</em></strong>), select <strong>Regional,</strong> and click <strong>Create API</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QV4ylXxn_GtUTvO6z9Tszg.png" /><figcaption>Serverless API</figcaption></figure><p>We’ll go ahead with creating the resources. With the <strong><em>root path</em></strong> highlighted, click the <strong>Actions</strong> drop-down and then click <strong>Create Resource</strong>. Also, enable <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html"><strong><em>Enable API Gateway CORS</em></strong></a>. We’ll create 3 resources ( health, student, and students) under the root path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2_D80R6XNONUQFvr1MSvw.png" /><figcaption>Resource creation</figcaption></figure><p>We’ll select the health resource and create a GET method for the health path. This will be used to test the health status of the API. Enable <strong>Use Lambda Proxy integration</strong>, select the Lambda function created earlier, and hit <strong>Save</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*njOKF7W-sl4LV-76w6EXwQ.png" /><figcaption>GET method</figcaption></figure><p>Then we’ll create GET, POST, PATCH, and DELETE methods under the <strong><em>student </em></strong>resource, then a GET method under <strong><em>students</em></strong> resource. Below is a sample of what we’ll have at the end of the day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*siw1pwdBNy7u7vHPib-iGQ.png" /><figcaption>Resources and Methods creation</figcaption></figure><p>Do not forget to deploy the API after the creation of the methods. Click <strong>Actions</strong> again and <strong>Deploy API</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QGP6X2Q-Dp6LJC0lA5N9Eg.png" /><figcaption>Deploy API</figcaption></figure><p>Which stage you want to deploy the API to is subsequently asked in a modal window that displays. Create a new stage and give it the name prod, then hit <strong>Deploy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ing7V8RHTRhkuMBK4euAAg.png" /></figure><p>Tadaa!!! It’s time to test our API and I’ll be doing that with Postman. For the purpose of not making this post too long and also not to bore you, I attached a few screenshots of the tests.</p><p>GET /health</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kNNv__KwCX8ZDK2TcawNOA.png" /><figcaption>Health status</figcaption></figure><p>POST /student</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vO5CAxQrddvlCa38mRJfhQ.png" /><figcaption>Add record</figcaption></figure><p>DynamoDB Table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChoQ95NBPCA0ZbEEXCFFcg.png" /><figcaption>Records added</figcaption></figure><p>GET /student</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NCDx90S9cTOHTuiSNHE66w.png" /><figcaption>Get a single record</figcaption></figure><p>GET /students</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7bbk1z3SEVLrO0BY0Wh3Q.png" /><figcaption>Get all records</figcaption></figure><p><strong>Conclusion</strong></p><p>Congratulations on making it this far! You can, among other things, do the following if you want to expand your new API:</p><ul><li>Add request validation</li><li>Use AWS Cognito to require authentication to access your APIs</li><li>Deploy the API to your own custom domain</li><li>Use API keys to limit the API use.</li></ul><p>There you have it. We were able to build a serverless CRUD API using Python, API Gateway, AWS Lambda, and AWS DynamoDB.</p><p><em>Follow us on </em><a href="https://twitter.com/enyiomann"><strong><em>Twitter</em></strong></a><strong><em> </em></strong><em>and </em><a href="https://www.linkedin.com/in/enyioman/"><strong><em>LinkedIn</em></strong></a><em>. Also, please click the clap 👏 button below a few times to show your support! Thank you!!!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84d486c87df4" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/crud-application-using-api-gateway-lambda-dynamodb-and-python-84d486c87df4">CRUD Application Using API Gateway, Lambda, DynamoDB, and Python</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[Deploy a Docker Container on AWS ECS using Terraform]]></title>
            <link>https://awstip.com/deploy-a-docker-container-on-aws-ecs-using-terraform-6ad99c7d0498?source=rss-71a63f34971d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ad99c7d0498</guid>
            <dc:creator><![CDATA[Enyioma Nwadibia]]></dc:creator>
            <pubDate>Thu, 20 Oct 2022 13:06:45 GMT</pubDate>
            <atom:updated>2023-09-06T11:13:05.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*YtENbbYZbahJp-Lyr4WQkg.png" /><figcaption>Project resources</figcaption></figure><p>If you are looking to deploy a dockerized application on AWS ECS, Elastic Container Service, Terraform is the tool for you. In this project, I will show you how to use Terraform to create an AWS ECS and deploy a dockerized image (centos image for this demo) in it. Firstly, we will pull the centos image from Docker Hub, and then we will push it to AWS ECR, Elastic Container Registry. Afterward, we will use Terraform to launch the Docker image in an AWS ECS cluster with AWS Fargate.</p><p>Before proceeding, let’s be clear on some of the concepts and services:</p><ul><li><strong>AWS Fargate</strong> is a serverless compute engine that you can run containers on without needing to manage individual servers or clusters. It is integrated with ECS and also integrates with CloudWatch to give you metrics about your application’s performance.</li><li><strong>AWS Elastic Container Service</strong> is a container orchestration service fully managed by AWS that makes the deployment, management, and scaling of applications effortless.</li><li><strong>AWS Elastic Container Registry</strong> is a service that is used to store, share, and deploy container images.</li><li><strong>Terraform</strong> is an Infrastructure as Code (IaC) tool that allows you to provision, modify, and version infrastructure and services both on-prem and in the cloud.</li><li><strong>Docker</strong> is an open-source container runtime and packaging system designed to streamline application development by enabling portability across various platforms and environments. It is used to package an application and its dependencies into a single unit called a Container and then run on one or more hosts.</li><li>A <strong>Docker image</strong> is a collection of files needed to run your container, including code, configuration data, and other supporting files.</li></ul><p><strong>Prerequisites</strong>:</p><ul><li>AWS account</li><li>IDE of your choice (I’ll be using VS Code)</li><li>AWS configured</li><li>Terraform installed</li><li>Docker installed</li></ul><p>We’ll proceed by creating two directories in VS Code. I named mine ecr and ecs.</p><p><strong>STEP 1</strong>:</p><p>To pull the centos image from Docker Hub using Terraform, let’s first cd into the ecr directory and create a file for the providers Terraform will work with. I named mine providers.tf. Add the following code to the file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f5a2ee2f9d6472b0f6a29c588d73ab0/href">https://medium.com/media/1f5a2ee2f9d6472b0f6a29c588d73ab0/href</a></iframe><p>From the above code snippet, you can deduce that we’ll be making use of AWS and Docker. Next, we’ll create another file docker.tf, then add the code that will pull a centos image from Docker Hub and create an ECR repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/404db90a2cf2af55646bc7fce65bf3db/href">https://medium.com/media/404db90a2cf2af55646bc7fce65bf3db/href</a></iframe><p>Save your files (mine is on autosave), then run terraform init so that Terraform can initialize the backend, provider plugins, and create a lock file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7OiN6lh1FpNG0Hj01Z0IKw.png" /><figcaption>Terraform initialization</figcaption></figure><p>Then run terraform fmt to format the codes, and terraform validate to validate the configuration files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3_UsR0HirpULSSU9sN_fg.png" /><figcaption>Terraform validation</figcaption></figure><p>If there are no errors, go ahead and run terraform plan and then terraform apply for the resources to be created. When prompted, enter “yes” to approve the resource creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xMOMgN1f7zfwwy3cF3ftXw.png" /><figcaption>Resources created</figcaption></figure><p>Let’s confirm the creation of our image with the command docker image ls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JiTWjp1VoVqzeqr69isRqw.png" /><figcaption>Image created</figcaption></figure><p>Awesome! Our centos image has been created. Remember that the code in docker.tf was also meant to create our ECR repository. Let’s open our AWS console and navigate to <em>Elastic Container Registry</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jbzze0E5Kn7paNXuyhl_dQ.png" /><figcaption>ECR created</figcaption></figure><p>We’ll copy out the repository URI and then retrieve the token through our command line with the following command:</p><pre>aws ecr get-login-password --region us-east-1</pre><p>Copy out the token also. Then, issue the following command with your token and repository URI:</p><pre>aws ecr --region us-east-1| docker login -u AWS -p &lt;encrypted_token&gt; &lt;repo_uri&gt;</pre><p>This should output <em>Login Successful</em>. Next, we’ll have to tag the docker image before pushing it to the ECR repo. Enter the following command with your image name and repo URI to achieve this.</p><pre>docker tag centos &lt;target_ecr_repo_uri&gt;</pre><p>Then push the docker image to AWS ECR with the following command:</p><pre>docker push &lt;ecr-repo-uri&gt;</pre><p>This might take a few minutes. Navigate to Elastic Container Registry via AWS Console after a successful upload for confirmation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJLAKaHanl3wFvB_F-nA0Q.png" /><figcaption>Image uploaded</figcaption></figure><p><strong>STEP 2</strong>:</p><p>Let’s cd into the ecs directory and create another providers.tf file. Notice that we included AWS access key and secret key in this configuration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7be51ad5af41ed74b80eea502bcc46a/href">https://medium.com/media/f7be51ad5af41ed74b80eea502bcc46a/href</a></iframe><p>Create a file variables.tf and declare the variables. We do not want to input these sensitive keys in this file either. Therefore, we’ll create another file with .tfvars extension and input the default values there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/799c78cebf6c617067860dd108f6bba2/href">https://medium.com/media/799c78cebf6c617067860dd108f6bba2/href</a></iframe><p>Our cluster needs to be launched in a VPC. Therefore, we’ll create a file vpc.tf and input the following codes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c8732d5a0b3a8f0f901c649b87b966c/href">https://medium.com/media/2c8732d5a0b3a8f0f901c649b87b966c/href</a></iframe><p>Other resources we will need for our VPC include an internet gateway, 2 public subnets, route table, and route table associations. To that effect, we’ll create a file subnets.tf and input the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/164b227f64c8cdc1b66fb6625c16c7e7/href">https://medium.com/media/164b227f64c8cdc1b66fb6625c16c7e7/href</a></iframe><p>Next, we create the ECS cluster, Fargate, and relevant ECS roles in a file main.tf.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd22c69620f95e32acfcfbce85db4456/href">https://medium.com/media/dd22c69620f95e32acfcfbce85db4456/href</a></iframe><p>Now that we’re done with our file creation, go ahead and run terraform fmt, and terraform validate. If all looks good, proceed with terraform plan and terraform apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9iHyAeG_WhjXpaJ18VCgVg.png" /><figcaption>Resources created</figcaption></figure><p>Head over to AWS console and confirm the resources and deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*snL5Wtv_q9MODjncWi7-sA.png" /><figcaption>VPC</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvF1c6LAIgwuaZQiHGzi4w.png" /><figcaption>Subnets</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dND6U_GaUF7UySywL0WRA.png" /><figcaption>ECS cluster</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8jOAhWr7UILKVGG2djf_w.png" /><figcaption>Tasks running</figcaption></figure><p>Voila! We’ve successfully deployed a Docker image on AWS ECS using Terraform.</p><p>Do not forget to cleanup using terraform destroy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad99c7d0498" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploy-a-docker-container-on-aws-ecs-using-terraform-6ad99c7d0498">Deploy a Docker Container on AWS ECS using Terraform</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[Nailing an Internship Program]]></title>
            <link>https://medium.com/@enyioman/nailing-an-internship-program-ec099ed2e1ed?source=rss-71a63f34971d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec099ed2e1ed</guid>
            <category><![CDATA[internships]]></category>
            <dc:creator><![CDATA[Enyioma Nwadibia]]></dc:creator>
            <pubDate>Sun, 31 Mar 2019 01:54:32 GMT</pubDate>
            <atom:updated>2019-03-31T01:54:32.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HmTs49gLJZwSgCsN" /><figcaption>Photo by <a href="https://unsplash.com/@danieleriggifotovideo?utm_source=medium&amp;utm_medium=referral">Daniele Riggi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I took part in a Tech internship (HNG Internship 4.0) a year ago. I never made it half-way to the top ranks. Though I was a newbie then in software development, reflections on that journey revealed that excelling in an internship program requires more than professional competence.</p><p>Let’s get to understand what an internship program is and why companies organize same.</p><p>The term <em>internship</em> was formerly exclusive to medical graduates, but it is now used by other sectors for the sole purpose of recruiting top talents who recorded outstanding performance and exhibited excellent attitude during the program.</p><p>You must know your onions as regards professionalisms in your chosen field but what are those other qualities that will make you stand out? Be it paid or unpaid internship, onsite or remote, the below are some of much needed qualities:</p><ol><li><strong>Say Hi: </strong>You just got ‘recruited’ into a new working environment so a show of courtesy by greeting everyone you meet and introducing yourself to them is the best you can do. Having a friendly and positive attitude to everyone coupled with great communication skills is key to a successful working relationship.</li><li><strong>Ask Questions: </strong>Experienced hands will be assigned to supervise and mentor you during the course of the program. They are there to guide you because the firm or employer doesn’t expect you to know everything about the job or industry. So, ask questions on anything you don’t understand. Apart from you understanding and learning more when you ask questions, you’ll be seen as being motivated and ambitious.</li><li><strong>Set Personal Goals: </strong>Set personal goals that you want to achieve during the course of the internship. This will guide you in making research, learning more and delivering your tasks before deadlines.</li><li><strong>Be A Good Team Player: </strong>Because you are disciplined with delivering your tasks before deadlines which in turn is as a result of setting personal goals, you will have some free time. Be generous with that time by helping other members of your team with their tasks. You will end up learning more and becoming better plus the goodwill you’ll garner among them.</li></ol><p>To be continued!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec099ed2e1ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>