Webserver Implementation
Purpose
Launching a webserver
Steps
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"
Preserve key pair file Creating a SSH folder (could be everywhere) to store key pair file
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.
Switch user to make package update and web server installed
Adding a index page. Turning on the web server and browsing to the instance ip should see the result.
Add web server as a routine when instance is activated.
(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.
(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.
Last updated