Skip to main content

Run Website on AWS EC2

You may need to learn how to run your website without any help from others. Here is a way to do this.

What you need.
  • AWS Account ( you can register for Free Tier account)
Initial Plan

Firstly, I will create an AWS S3 Bucket for uploading the web content. In order to copy the content of the S3 to EC2, I need to create IAM role with s3 full access permission. Then  I will launch an AWS EC2 instance and configure the EC2 instance to run my website.

This is very simple. Let's Start.

Steps 1: Create S3 bucket

Go to services and select the S3



Create a bucket






Now click the create button



I have downloaded the basic HTML template website for this blog. you can simply upload your web content to the S3 bucket. Here I have a zip file.

click the newly created bucket and select the web content to upload




Click the upload button


Ok, now we have our web content on the S3 bucket. Let's create an IAM role with s3 full access permission.

Step 2: Create IAM Role

Now go to Security, Identity & Compliance under service and select IAM



Click the create role button



Select EC2 and click on Next:Permission





select the AmazonS3FullAccess



Click the Next:Tag 


Then Review and create the role




You have created the role. 


Step 3: Create EC2 Instance

Now we need to launch the EC2 instance. Go to Compute under Services and select EC2.








keep step 3 Configure Instance Detail and Step 4 : Add Storage Step 5: Add Tags as default



Click Review and Launch and then click launch. 



Select "create a new key pair" from the drop-down menu and name your key and hit the download key pairs and Launch the Instances. Now go to EC2 and select the instance you just create.

Select the Attach/Replace IAM role under Action


Select the Role that You Created earlier and apply.



copy the IP address and ssh to the EC2 instance using the below command in linux.




ssh -i ~/.ssh/mykey.pem ec2-user@ec2-18-232-95-17.compute-1.amazonaws.com


Now you need to install a server in order to run my website. So I have to install the relevant server using below commands

sudo su
yum install httpd -y
Now I need to download the zip file from my s3 bucket.

aws s3 cp s3://harshana-website-demo/myWeb.zip /var/www/html
Unzip the zip file 
unzip myWeb.zip
Now, I need to start the httpd server 
service httpd start
Ok, we are done.

Open the browser and go to this link  http://<ip address>/myWeb/









Comments

Popular posts from this blog

Java Increment Operations: `n++` vs `n = n + 1` vs `n += 1`

In Java, incrementing a variable by one can be done in several ways: n++ , n = n + 1 , and n += 1 . While these expressions achieve the same end result, they differ slightly in syntax and use cases. Let's explore each one and discuss their performance. 1. n++ Post-Increment Operator : Increments the value of n by 1 after its current value has been used. Common Usage : Typically used in loops and other contexts where the current value needs to be used before incrementing. int n = 5; n++; // n is now 6 2. n = n + 1 Addition Assignment : Explicitly sets n to its current value plus 1. Readability : Straightforward and clear, though slightly more verbose. int n = 5; n = n + 1; // n is now 6 3. n += 1 Compound Assignment Operator : Equivalent to n = n + 1 , but more concise. Usage : Combines addition and assignment into one step. int n = 5; n += 1; // n is

Understanding C1 and C2 Compilers in Java

Understanding C1 and C2 Compilers in Java Understanding C1 and C2 Compilers in Java In Java, the Just-In-Time (JIT) compiler is a part of the Java Virtual Machine (JVM) that improves the performance of Java applications by compiling bytecode into native machine code at runtime. The JIT compiler includes two different compilers, known as the C1 and C2 compilers, each with distinct optimization strategies and purposes. C1 Compiler (Client Compiler) The C1 compiler, also known as the client compiler, is designed for fast startup times and lower memory consumption. It performs lighter and quicker optimizations, which makes it suitable for applications that require quick startup and responsiveness. Key characteristics of the C1 compiler include: Quick Compilation: Prioritizes fast compilation times over deep optimizations. Low Overhead: Consumes less memory and resources during compilation. Profile-Guided Optimization: Ca

When To Use Indexes In MySQL

When deciding when and how to create an index in your MySQL database, it's important to consider how the data is being used. Let's say you have a database of  students . We will create it like this: CREATE TABLE `students` ( `id` int ( 11 ) NOT NULL AUTO_INCREMENT , `first_name` varchar ( 255 ) DEFAULT NULL , `last_name` varchar ( 255 ) DEFAULT NULL , `class` varchar ( 255 ) DEFAULT NULL , PRIMARY KEY ( `id` ) ) ENGINE = InnoDB Indexes are best used on columns that are frequently used in where clauses, and in any kind of sorting, such as "order by". You should also pay attention to whether or not this information will change frequently, because it will slow down your updates and inserts. Since you wont frequently be adding students, you don't have to worry about the inserts Let's say that you will be looking up the students with a web interface and the end user will be typing in the students name to find them, since r