Through this blog I'll provide a step-by-step guide through which you can host your static website on an AWS EC2 Instance.
So the services that we'll using are EC2 Instance and S3 Bucket (Used to store the code files).
####2. The next step is upload the code files Inside the bucket click on the upload button and upload the respective code files onto the bucket.
####3. Change permission In order for the bucket to be accessible we also need to make a change in the the permission section by modifying the bucket policy with the following code:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"
]
}
]
}
Here you need to replace DOC-EXAMPLE-BUCKET with your bucket name.
ssh -i "peterawsjan.pem" ec2-user@18.221.22.171
sudo su
Now its time to set things up, our EC2 Instance will act as an Server so for that we install httpd.
yum install httpd
Now that's done we need to pull data from our S3 bucket to the html folder of our Instance for that lets change directory.
cd /var/www/html/
To fetch data from S3 bucket we need the object url which can be found in index.html file in the S3 section of the AWS console.
wget "your object URL"
Once you fetch it the type will be .zip and you need to unzip and move
uzip "your folder name"
mv "your folder name"* .
#That's it now its time to start our server.
service httpd.service
You can access your hosted website by searching your Instances IP address.
I really hope this blog helped you host your website using EC2 Instance, Thank you.
Hello and thanks for visiting! My name is Peter Johnson, and this is my website where I share intersting blogs around technology and finance.
Post Details
- Published on Jul 1, 2022