Host a Static Website on Amazon S3 through AWS CLI
Objectives:
After completing this project, you should be able to:
Run AWS CLI commands that use IAM and Amazon S3 services.
Deploy a static website to an S3 bucket.
Pre-requisites:
AWS Free Tier Account
AWS Access Key
Task 1: Connect to an Amazon Linux EC2 instance using EC2 Instance Connect
please follow https://www.adevopsday.com/create-an-instance-to-run-linux-ubuntu-on-aws-cloud/
Task 2: Configure the AWS CLI
aws configure
At the prompt, configure the following:
AWS Access Key ID: Copy and paste the value for AccessKey
AWS Secret Access Key: Copy and paste the value for SecretKey
Default region name: us-west-2(select as per choice)
Default output format: json
Task 3: Create an S3 bucket using the AWS CLI
aws s3api create-bucket --bucket techbhairavi --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2
output should be like
{
"Location": "http://techbhairavi.s3.amazonaws.com/"
}
Task 4: Create a new IAM user that has full access to Amazon S3
aws iam create-user --user-name bhairavi
Create a login profile for the new user by using the following command:
aws iam create-login-profile --user-name bhairavi --password Training123!
Task 5: Adjust S3 bucket permissions
The bhairavi user does not have Amazon S3 access to the bucket that you created, so you might see an error for Access to this bucket.
To find the AWS managed policy that grants full access to Amazon S3, run the following command:
aws iam list-policies --query "Policies[?contains(PolicyName,'S3')]"
To grant the bhairavi user full access to the S3 bucket
aws iam attach-user-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --user-name techbhairavi
On the AWS Management Console, on the Amazon S3 console, choose your bucket name.
Go to permissions, under Block public access (bucket settings), choose Edit
Deselect/UnSelect Block all public access
Choose Save changes (confirm on the prompt)
On to permissions tab, under Object Ownership, choose Edit
Choose ACLs enabled
Choose I acknowledge that ACLs will be restored.
Choose Save changes
Task 6: Upload file to Amazon S3 by using the AWS CLI
aws s3 website s3://techbhairavi/ --index-document index.html
index.html is an HTML file that serves as the home page for a website. Usually, index.html is automatically opened when visitors enter the domain. An example of an index.html file might contain the following code
To verify that the files were uploaded,
aws s3 ls techbhairavi
On the AWS Management Console, on the Amazon S3 console, choose your bucket name.
Choose the Properties tab. At the bottom of the this tab, note that Static website hosting is Enabled. R
Task 7: Verify Website
Under Static website hosting, note the Endpoint.
The Endpoint is the Amazon S3 website endpoint for your bucket. After you finish configuring your bucket as a static website, you can use this endpoint to test your website. To open the URL on a new page, choose the Bucket website endpoint URL that displays.
Here you go...!!!!!!! yipee your basic website is live. AWS S3 is chargeable service so don't forgot to delete the resources in your AWS Free Tier Account after Practice.
Please follow and subscribe for further notifications.
Thank you!
Bhairavi
Subscribe to my newsletter
Read articles from Bhairavi Waghele directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by