Simple Web-application deployment on EC2 using AWS CodeDeploy & S3 services

 

Prerequisite

  1. AWS CLI Installations: Click Here
  2. Configure Service Role for S3.
    1. Go to IAM
    2. Click on Role. Select AWS services –> Ec2. Click on Next Permission.
    3. Select S3FullAccess Click on Tag (optional)–>Click on Review.
    4. Define Role Name –> Click on Create.
  1. Configure Service Role for CodeDeploy.
    1. Go to IAM
    2. Click on Role. Select AWS services –> CodeDeploy
    3. Select your Use Case –>CodeDeploy
    4. Click on Next Permission. Click on Tag(optional)–>Click on Review.

5. Define Role Name –> mycodedeployrole.Click on Create.

 Steps to Deployment of Web Application

1. Create an EC-2 Instance.

  1. Choose an Amazon Machine Image (AMI), find the Amazon Linux AMI  at the top of the list and choose Select.
  2. Choose an Instance Type, choose Next: Configure Instance Details.
  3. Configure Instance Details, choose Network, and then choose the entry for your default VPC. It should look something like vpc-xxxxxxx (172.31.0.0/16) (default).
  4. Choose Subnet, and then choose a subnet in any Availability Zone.
  5. Select IAM role as mys3role.
  6. Choose Next: Add Storage.
  7. Choose Next: Tag Instance. (It is very important to assign tag to ec2 instance because code deploy on ec2 based on tag only)
    • Name:-AppName
    • Value:-Demo
  8. Configure Security Group, review the contents of this page, ensure that Assign a security group is set to Create a new security group, and verify that the inbound rule being created has the following default values.
    • Type: SSH, HTTP
    • Protocol: TCP
    • Port Range: 22, 80.
    • Source: Anywhere 0.0.0.0/0
  9. Select Key pair. Click on Launch.
  10. Access EC2-using Putty Click Here

2. Install CodeDeploy agent for EC2(Ubuntu Server)

#sudo yum update

#sudo yum install –y httpd php

#sudo yum install ruby

#sudo yum install wget

#cd /home/ec2-user

#wget https://bucket-name.s3.amazonaws.com/latest/install

Note:- bucket-name is the name of the Amazon S3 bucket where your codedeploy resourcekit files stored region wise. Find your region bucket name.

#chmod +x ./install

#sudo ./install auto

#sudo service codedeploy-agent status

3. Create a developer machine which is connected with AWS CodeDeploy service (Help to upload code to S3)

  1. Go to the IAM on AWS Console.
  2. Create User. Name:-cddemouser
  3. Select programmatic access.
  4. Assign Permission. Click on existing Policy.
    • CodeDeployfullaccess
    • S3fullaccess
  5. Click on Create.
  6. Use Access key & Secret Key in AWS CLI on your Local machine.
  7. Open Type aws configure
  8. Enter Access key, Secret key, Default Region (region must be the same as EC2)(skip), Default output format (skip).
  9. Go to the web app directory.
  10. Now create bucket in S3. Name –>cddemo
  11. Now Create your demo.zip and load it into CodeDeploy & Push Code from Local machine(AWS CLI) to s3 using two commands.
    • #aws deploy create-application –application-name demo
    • #aws deploy push –application-name demo –s3-location s3://<MY_BUCKET_NAME>(cddemo)/demo.zip –ignore-hidden-files
  12. Now Check in your S3 bucket, demo.zip is uploaded.

4. Now Open CodeDeploy.

  1. Click on create the application.
  2. Now click on Create deployment group.
    • deployment group name :- demo
    • Service Role:- select mycodedeployrole
    • Deployment type:- In-Place
    • Environment configuration:- select Amazon EC2 instances
      • Key:- AppName
      • Value:- Demo
    • Deployment settings:-CodeDeployDefault.AllAtOnce
    • Load balancer:- Uncheck(not required)
  3. Click on Create deployment and go to the Deployment settings
    • Deployment group:- select demo
    • Revision type:- My application is stored in Amazon S3
    • Revision location:- s3://cddemo/demo.zip
    • Remaining things as it is click on Create deployment

OutPut: –Now Go to EC-2 Console copy IP address and open in web browser.

Comments

Popular posts from this blog

Install terraform on ubuntu and Create EC2 instance on AWS using terraform script

Deployment of Website Using AWS CICD pipeline & Fargate

Deploy Django website using AWS Elastic Beanstalk CLI in windows