Skip to content

Example of how to create and host a website on s3 using the commandline interface

Notifications You must be signed in to change notification settings

brianom/aws-create-s3-website-commandline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to create and host a website on AWS S3 from the commandline

This short tutorial assumes you have first downloaded the AWS commandline (CLI) tools and set it up with your AWS credentials. Once complete you should see a folder called .aws in your home folder, with your credentials in it.

Create a S3 bucket

To create a S3 bucket to store your site you must give it a unique name (if you don't it will return a warning to say that is already in use). I am going to use "seed-site"

aws s3api create-bucket --bucket seed-site

It should return:

{ "Location": "/seed-site" }

If you got to your AWS console you should now see your new bucket.

AWS-S3-screenshot

Create your website files and go to that folder. (you can use my index.html and other files available here). You can copy the files one at a time like this:

Upload files

You can use cp a lot like the regular commandline copy.

aws s3 cp index.html s3://seed-site/

returns

upload: ./index.html to s3://seed-site/index.html

Or all the files in your folder and sub folders using a recursive copy. The command line parameters I've used tell it to just copy the jpeg and html files I need. I have also made all the files publically available using "--acl public-read"

aws s3 cp . s3://seed-site/ --recursive --exclude "*" --include "*.jpg" --include "*.html" --acl public-read

You can verify they have been copied to the remote folder using a remote list.

aws s3 ls s3://seed-site/

Returns:

2017-06-07 06:38:29     329903 dead-seed.jpg
2017-06-07 06:38:29       1608 error.html
2017-06-07 06:38:29       1587 index.html
2017-06-07 06:38:29     201254 seed.jpg

Make it a website

Finally to configure this S3 bucket to serve the files as a website, run the following command (this becomes more relevant when you have a custom domain)

 aws s3 website s3://seed-site/ --index-document index.html --error-document error.html

Ta-Da: https://seed-site.s3.amazonaws.com/index.html

Next create the site with a custom domain

About

Example of how to create and host a website on s3 using the commandline interface

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages