DEV Community

Revathi Joshi
Revathi Joshi

Posted on

3-part series - (1) Launch an EC2 Instance, Install CodeDeploy Agent and upload App_Linux.zip file to version enabled S3 bucket

In this Create and Deploy applications using CodeDeploy and CodePipeline with Amazon S3 bucket versioning enabled -

In the 1st article, We will create, SSH into EC2 Instance and Install CodeDeploy Agent. Then Create a S3 bucket with versioning enabled, upload App_Linux.zip

Let’s get started!

Please visit my GitHub Repository for CI-CD/Docker/ECS/ECR articles on various topics being updated on constant basis.

Objectives:

1. Sign in to AWS Management Console

2. Launch an EC2 instance, Connect (SSH) to EC2 Instance thru Putty

3. Install CodeDeploy Agent

4. Create S3 Bucket, upload App_Linux.zip and Copy the Object's key

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • AWS CLI.

Resources Used:

CodeCommit

CodeBuild

CodeDeploy

AWS CodePipeline

Steps for implementation to this project

1. Sign in to AWS Management Console

  • Log into the AWS Management Console, AWS Region as US East (N. Virginia) us-east-1.

2. Launch an EC2 instance, Connect (SSH) to EC2 Instance thru Putty

Launch an EC2 instance

  • Go to EC2 Dashboard, Launch instance, my-ec2, Select t2.micro. NVirKey, default vpc, subnets - no preference, Auto-assign public IP - enable, Create Security group, CodePipeline-SG, SSH with 0.0.0.0/0, Add security group rule, HTTP, 80, 0.0.0.0/0

  • Attach Role - Role-EC2Instance with attched policyAmazonEC2RoleforAWSCodeDeploy

  • Launch instance

Image description

  • Connect (SSH) to EC2 Instance thru Putty

Image description

3. Install CodeDeploy Agent

  • Switch to root user
 yum update -y 
Enter fullscreen mode Exit fullscreen mode
  • Before Installing CodeDeploy Agent, Install the prerequisite i.e. ruby and wget
yum install ruby wget -y 
Enter fullscreen mode Exit fullscreen mode
  • Download the CodeDeploy agent's installer
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install 
Enter fullscreen mode Exit fullscreen mode
  • Change the permission of the installer
chmod +x ./install 
Enter fullscreen mode Exit fullscreen mode
  • Install the latest version of the CodeDeploy agent
sudo ./install auto 
Enter fullscreen mode Exit fullscreen mode
  • Check status
service codedeploy-agent status 
Enter fullscreen mode Exit fullscreen mode
  • Note: If the output is "The AWS CodeDeploy agent is running as PID 3523" or any other PID. It means codedeploy agent is running fine.

Image description

  • If the output says, "error: No AWS CodeDeploy agent running", then start the agent by running the below command and check the status again.

  • Start the agent

service codedeploy-agent start 
Enter fullscreen mode Exit fullscreen mode
  • check the status
service codedeploy-agent status 
Enter fullscreen mode Exit fullscreen mode

4. Create S3 Bucket, upload App_Linux.zip and Copy the Object's key

  • On S3 Console, Create bucket, codecommit-bucket12, Uncheck Block all public access, Bucket Versioning - Enable

  • Create bucket

  • Click the bucket, Upload, Addfiles, App_Linux.zip, Upload

Image description

  • App_Linux.zip - has the following files

  • appspec.yaml

version: 0.0 os: linux files: - source: /index.html destination: /var/www/html/ hooks: BeforeInstall: - location: scripts/install_dependencies timeout: 300 runas: root - location: scripts/start_server timeout: 300 runas: root ApplicationStop: - location: scripts/stop_server timeout: 300 runas: root 
Enter fullscreen mode Exit fullscreen mode
  • index.html
<!doctype html> <html> <body> <h1>This is my Codepipeline from S3 bucket! </h1> </body> </html> 
Enter fullscreen mode Exit fullscreen mode
  • scripts folder has 3 files

install_dependencies

#!/bin/bash yum install -y httpd 
Enter fullscreen mode Exit fullscreen mode

start_server

#!/bin/bash service httpd start 
Enter fullscreen mode Exit fullscreen mode

stop_server

#!/bin/bash service httpd stop 
Enter fullscreen mode Exit fullscreen mode
  • Copy the object Key, and save it to notepad

Image description

What we have done so far

  • We have successfully created, SSH into EC2 Instance and Installed CodeDeploy Agent. Then Created a S3 bucket with versioning enabled, uploaded App_Linux.zip

Top comments (0)