Development Notes
  • Introduction
  • Programming Langauges
    • Java
      • Cache
      • Java Fundamentals
      • Multithreading & Concurrency
      • Spring Boot
        • Spring Security
        • Development tips
      • ORM
        • Mybatis
      • Implementation & Testing
    • Node.js
      • Asynchronous Execution
      • Node.js Notes
    • Python
      • Memo
  • Data Structure & Algorithm
  • Database
  • Design Pattern
  • AWS Notes
    • Services
      • API Gateway
      • CloudHSM
      • Compute & Load Balancing
        • Auto Scaling Group
        • EC2
        • ECS
        • ELB
        • Lambda
      • Data Engineering
        • Athena
        • Batch
        • EMR
        • IoT
        • Kinesis
        • Video Streaming
        • Quicksight
      • Deployment
        • CloudFormation
        • Code Deploy
        • Elastic Beanstalk
        • OpsWorks
        • SAM
        • SSM
      • ElasticSearch
      • Identity & Federation
        • Directory Service
        • IAM
        • Organizations
        • Resource Access Manager (RAM)
        • SSO
        • STS
      • KMS
      • Management Tools
        • Catalog
        • CloudTrail
        • CloudWatch
        • Config
        • Cost Allocation Tags
        • GuardDuty
        • Savings Plans
        • Trusted Advisor
        • X-Ray
      • Migration
        • Cloud Migration: The 6R
        • Disaster Recovery
        • DMS
        • VM Migrations
      • Networking
        • ACM
        • CloudFront
        • Direct Connect
        • EIP & ENI
        • Network Security
        • PrivateLink
        • Route53
        • VPC
        • VPN
      • Service Commnucation
        • Amazon MQ
        • SNS
        • SQS
        • Step Functions
        • SWF
      • Storage
        • Aurora
        • DynamoDB
        • EBS
        • EFS
        • ElastiCache
        • RDS
        • Redshift
        • S3
        • Storage Gateway
      • Other Services
        • Alexa for Business, Lex, Connect
        • AppStream 2.0
        • CloudSearch
        • Comprehend
        • Data Tools
        • Elastic Transcoder
        • Mechanical Turk
        • Rekognition
        • WorkDocs
        • WorkSpaces
    • Well Architect Framework
      • Security
      • Reliability
      • Performance Effeciency
      • Cost Optimization
      • Operational Excellence
    • Labs
      • Webserver Implementation
      • ELB Implementation
      • Auto-scaling Implementation
      • A 3-tier Architecture In VPC
  • Architecture
    • Security
  • Spark
    • Memo
  • Conference Notes
    • Notes of JCConf 2017
  • AI Notes
Powered by GitBook
On this page

Was this helpful?

  1. AWS Notes
  2. Labs

Webserver Implementation

Purpose

  • Launching a webserver

Steps

  1. Creating an EC2 instance for web server

    • Choose AMI: Amazon Linux AMI 2017.09.0 (HVM), SSD Volume Type (Tick Free tier only if needed)

    • Choose Instance Type: t2.micro

    • Configure Instance Detail:

      • If tick "Protect against accidental termination", instance termination would be disabled. Turning termination protection off by Actions -> instance settings -> Change termination protection.

      • Advanced Details -> "User Data" -> "As text" to specify bash scripts to be run. See "3.(2)" in article.

      • IAM Role: Select role with "AmazonS3FullAccess" privilege if a S3 operation is required.

    • Add Storage: Change "Volume Type" to: "Magnetic"

    • Add Tag: Add "key", "value": "name", "MyEC2WebServer" (Should tag as much as possible for future cost control)

    • Configure Security Group:

    • Create a new security group and give the name, description as "MyWebDMZ" (Demilitarized Zone)

    • Add Rule: HTTP, HTTPS

    • When be asked needing to select or create a key pair

    • Choose: "Create a key pair" and give the key pair name: "MyEC2KeyPair"

    • click "Download Key Pair"

    • click "Launch instance"

  2. Preserve key pair file Creating a SSH folder (could be everywhere) to store key pair file

    $ cd ~/Downloads
    $ mkdir SSH
    $ mv MyEC2KeyPair.pem SSH
    $ cd SSH
    $ chmod 400 MyEC2KeyPair.pem
  3. Creating a web server There are several ways to achieve: (1) Manually link to the instance and install a web server Linking through SSH, input "yes" for first login. The i option is for file.

    $ ssh ec2-user@${ec2_public_ip} -i MyEC2KeyPair.pem

    Switch user to make package update and web server installed

    $ sudo su
    $ yum update -y
    $ yum install httpd -y

    Adding a index page. Turning on the web server and browsing to the instance ip should see the result.

    $ cd /var/www/html/
    $ vim index.html
    $ service httpd start

    Add web server as a routine when instance is activated.

    $ chkconfig httpd on

    (2) Running shell commands during instance initiation Above manual process can be done with shell commands. When creating instance, "Configure Instance" -> "Advanced Details" -> "User data" choose "As text" and give below text.

    #!/bin/bash
    yum install httpd -y
    yum update -y
    echo "<html><body>Hi, this is a webserver.</body></html>" > /var/www/html/index.html
    service httpd start
    chkconfig httpd on

    (3) Running shell commands with a S3 bucket Above manual process can be done with shell commands. When creating instance, On "Configure Instance" page with following actions:

    • IAM Role -> Select a role with "AmazonS3FullAccess" privilege.

    • "Advanced Details" -> "User data" choose "As text" and give below text.

      #!/bin/bash
      yum update -y
      yum install httpd -y
      aws s3 cp s3://${bucket_name}/${directory} /var/www/html --recursive
      service httpd start
      chkconfig httpd on
PreviousLabsNextELB Implementation

Last updated 5 years ago

Was this helpful?