Application Deployment in Amazon Lightsail Instance using AWS CodePipeline and AWS CodeDeploy
Tags: aws, awslightsail, awscodedeploy, awscodepipeline
Published: 2022-01-01 14:21:19

“Challenges faced to find the solution of how to deploy an application with continuous change in code”. I have found the solution in AWS as a service used for automation as AWS CodePipeline. Using CodePipeline service, I am able to set an automation with a github account for continuous integration and continuous delivery. Also able to deploy it using AWS CodeDeploy service. I have used an Amazon lightsail instance to deploy my application with required permissions. In terms of cost and security perspective, an automation set is cheaper as compared to using any other service. Also it is secured and can be notified easily to users.

A keyword define "**Devtron**" play an important role in sorting the complexity of DevOps, AppOps and Kubernetes. Also "**GitHub**" helps to integrate and automate. Both Devtron and GitHub is an open source one.

In this post, you will get to know how to deploy an application in lightsail instance using codepipeline and codedeploy. Here I have used a lightsail instance to deploy an application. And used codedeploy and codepipeline for automation purposes. Also having metrics to get a record of parameters value in cloudwatch.

#Prerequisites
You’ll need a [Github](https://github.com/) account and git installed on a local machine. You’ll need [AWS CLI](https://aws.amazon.com/cli/) installed and configured on your local machine.

You’ll need an Amazon Simple Storage Service for this post. [Getting started with Amazon Simple Storage Service](https://aws.amazon.com/s3/getting-started/) provides instructions on how to create a bucket in simple storage service. For this blog, I assume that I have created a s3 bucket.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mizy8y6kodtnj7q09on.png)
The architecture diagram shows the overall deployment architecture with data flow, lightsail server, codedeploy, codepipeline, s3 bucket and github account.

#Solution overview
The blog post consists of the following phases:
1. Create IAM User with appropriate access and Create a Lightsail Instance
2. Register the Lightsail Instance with CodeDeploy and Configure of application in CodeDeploy
3. Create CodePipeline and Check the pipeline status after configuration
4. Testing and Updating the application and Monitoring the metrics in cloudwatch
I have a s3 bucket created as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3k603tua82i0z4uu995h.png)

##Phase 1: Create IAM User with appropriate access and Create a Lightsail Instance  
1. Open the IAM console, create a role with policy as codedeploy. Also create a user with programmatic access with s3codedeploybucket policy. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uej4r99hth0bp2ue57ql.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbprjpo15odv1bs8uyg7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d0ew8nf9gz6uzdycsk6.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7h02h673afkjd97q3xf7.png)
2. Open the lightsail console, create an instance with linux platform and os only option. Choose the instance plan and define the script for installation of codedeploy agent. Then give the key-value tag and click on create instance. Once the instance is created, we can see all the configuration of the instance and can check if the codedeploy agent service is running.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pw4jo6wc6fc1pfpsl8u.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6c6fuvxi6nphr4ciubz.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3ebl0tqgn3esvtkgibn.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk8zcfnadzrcp461mqiy.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/skaxbqnsspczmbk7xifp.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z89odnh2jydekshptu77.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0gckjeapes5yw84ig48c.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/byw3ogsw2136ivyd5rcv.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/503s5d9f9wnqsobvomhf.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqh3vyos7jnfbuq9zvpj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytiypk47ycnkokizc51c.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zot4awyzh2nak1ffar4r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/am6tzbt8p232h72xh5in.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rhwqsgeooitdzrckenc.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uzy9xquomd3vnu679vs.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9d49jw2tfmkf2begkwc.png)

##Phase 2: Register the Lightsail Instance with CodeDeploy and Configure of application in CodeDeploy
1. Run the commands on the local machine to register and tag your lightsail instance with Codedeploy. Also run a command to verify the machine was successfully registered.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1obxnqxelim23nj3t1aa.png)
2. Create an application named DemoDeployApp with EC2/On-premises compute platform. Also create a deployment group with required parameters named DemoDeploymentGroup.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcaefcxvai8gr48p307u.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hxn14mxr6j77lflg8j0.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5970op71kleqae4bf75x.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zg1p259pqd2myr529lgj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjdvwte0viyitxpanu1v.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7xvqaz3g7sg23ddp035.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eb5t4gji5xw2atwm5xo6.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lwctj8fh4zsx3s7u9er.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/796f81ushwvaz8d4dq2d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lposo2lfjx90ouyw633z.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/osxhrmgzbfgnsu1q9g8d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f46ipgz4mgxk4vgi8c5y.png)

##Phase 3: Create CodePipeline and Check the pipeline status after configuration
1. Create a codepipeline named DemoPipeline. Set up source provider as github and deploy provider as codedeploy. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgufylkd42ievdn6msjp.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3kslhig2cq8nrqsnr9r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4zbcmo0fi61hq2bggck.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s160qfcr86rmd95w5ttv.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gt0irvm93pr0i8wvjiil.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0seykpgof1p6eb1ldcy.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufg3lijdvuh5zbu0iya5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7tcb7smqlhqeavox9dh.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/753j62qowyrw7etulch6.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbk505lf24qiffcoxtq9.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e9hbzoy7lxjko2gnrk9a.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3esp3y4i3i8mwn3uui0q.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0e5sqjm3kw9zzvvq2dkg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/97w80yb8wkb6yhpxiho5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yqxjaus8i0srpoht2mo6.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwou029banz6jemr7qq1.png)

##Phase 4: Testing and Updating the application and Monitoring the metrics in cloudwatch 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wm1rwk9nifbfoaicjtfu.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/acdxzhfm5qyj4h39v8ud.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6kjlxshq4edoo7jfb616.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygbzacws2ek3k8gguafo.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkvw1gsimbe1umi3lhyp.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m69o0vzkatayzr1p78ab.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0nz2e4s18n5x4qiilsum.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iscas0gqledxk2dqxj2r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/18w4k5e7bq02ndpu4fwh.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivzc2uts2849od5a1vet.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux4rjyf6emoy0j9511ke.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9ljqqps0ikychd04664.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylodl489njkwhe5sb05o.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4v98hu6s3wgfnl2iqy1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92z3n36kvki5quz7qqmu.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogsrxwkvg1ui8i9dt9wp.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7edkd79d6q8n0ninv9h4.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/am78y633r58f9lt8lhhi.png)

#Clean-up
Delete AWS CodePipeline, AWS CodeDeploy, IAM, Amazon Lightsail Instance, S3 bucket.

#Pricing
I review the pricing and estimated cost of this example. 
Cost of Lightsail → 
USD 0.0 per GB for data transfer out = 0.000228 GB = $0.0
USD 0.0 per Hour of 0.5GB bundle Instance free trial = 8.008 Hrs = $0.0
Total = ($0.0+$0.0) =$0.0
Cost of CodeDeploy = $0.02 per on-premises instance update = 3.000 OnPremUpdates = $0.06
Cost of CodePipeline = $0.00 per trial pipeline = 2.000 pipelines = $0.0
Cost of Simple Storage Service = $0.04 
Cost of Cloudwatch = $0.0
Cost of Data Transfer = $0.0 
Total Cost = $(0.0+0.06+0.0+0.04+0.0+0.0) = $0.1

#Summary
In this post, I showed “how to deploy an application in Amazon Lightsail instance using AWS CodeDeploy and AWS CodePipeline”.

For more details on Amazon LightSail, Checkout Get started Amazon LightSail, open the [Amazon Lightsail console](https://lightsail.aws.amazon.com/ls/webapp/home/instances). To learn more, read the [Amazon Lightsail documentation](https://docs.aws.amazon.com/lightsail/?id=docs_gateway). For more details on AWS CodeDeploy, Checkout Get started AWS CodeDeploy, open the [AWS CodeDeploy console](https://ap-south-1.console.aws.amazon.com/codesuite/codedeploy/deployments?region=ap-south-1&deployments-meta=eyJmIjp7InRleHQiOiIifSwicyI6e30sIm4iOjUwLCJpIjowfQ). To learn more, read the [AWS CodeDeploy documentation](https://docs.aws.amazon.com/codedeploy/?id=docs_gateway). For more details on AWS CodePipeline, Checkout Get started AWS CodePipeline, open the [AWS CodePipeline console](https://ap-south-1.console.aws.amazon.com/codesuite/codepipeline/pipelines?region=ap-south-1&pipelines-meta=eyJmIjp7InRleHQiOiIifSwicyI6eyJwcm9wZXJ0eSI6InVwZGF0ZWQiLCJkaXJlY3Rpb24iOi0xfSwibiI6MTAsImkiOjB9). To learn more, read the [AWS CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/?id=docs_gateway).

For more details on **Devtron and GitHub**, Checkout Links:
[Devtron Website](https://devtron.ai/)
[GitHub Repo](https://github.com/devtron-labs/devtron)
[Join the Discord Community](https://discord.com/invite/jsRG5qx2gp)
[Follow on Twitter](https://twitter.com/DevtronL)
[Raise feature requests, suggest enhancements, report bugs](https://github.com/devtron-labs/devtron/issues)
[Read Devtron Blog](https://devtron.ai/blog/)

Lets quickly adopt and try it! And post the response using **#AdoptK8sWithDevtron** **#devtron**

The above blog is submitted as part of 'Devtron Blogathon 2022' - [https://devtron.ai/](https://devtron.ai/)
Check out Devtron's GitHub repo - [https://github.com/devtron-labs/devtron/](https://github.com/devtron-labs/devtron/) and give a ⭐ to show your love & support.
Follow Devtron on LinkedIn - [https://www.linkedin.com/company/devtron-labs/](https://www.linkedin.com/company/devtron-labs/) and Twitter - [https://twitter.com/DevtronL/](https://twitter.com/DevtronL/), to keep yourself updated on this Open Source project.

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)