https://docs.aws.amazon.com/AmazonS3/latest/dev/HostingWebsiteOnS3Setup.html
I will try to create such a website via aws cli - so that this can be automated:
(The installation of aws cli is shown here)
# aws s3api create-bucket --bucket my.webtest --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1 { "Location": "http://my.webtest.s3.amazonaws.com/" }
Then create a website.json file:
$ cat website.json { "IndexDocument": { "Suffix": "index.html" }, "ErrorDocument": { "Key": "error.html" } }
and run
$ aws s3api put-bucket-website --bucket my.webtest --website-configuration file://website.json
After that the web console should show:
and
Next step is to create the file policy.json:
$ cat policy.json { "Version":"2012-10-17", "Statement":[{ "Sid":"PublicReadForGetBucketObjects", "Effect":"Allow", "Principal": "*", "Action":["s3:GetObject"], "Resource":["arn:aws:s3:::my-webtest/*" ] } ] }
and run
aws s3api put-bucket-policy --bucket my.webtest --policy file://policy.json
You can check via:
Via the web console:$ aws s3api get-bucket-policy --bucket my.webtest { "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"PublicReadForGetBucketObjects\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::my.webtest/*\"}]}" }
Then upload you html page:
$ aws s3 cp TestWebPage.html s3://my.webtest/index.htmlupload: ./TestWebPage.html to s3://my.webtest/index.html
And here we go:
That was easy. Ok - a DNS resolution via Amazon route 53 is missing, but with these commands you are able to deploy a static website without clicking around...
Postings related to AWS:
- Amazon Web Services: A Start into AWS
- AWS: Running a docker-image with ECS
- AWS: Running a docker-image with ECS (part 2)
- AWS: Running a docker-image with ECS (part 3): Stop it!
- AWS: Networking - Virtual Privat Cloud
- AWS: Billing - how to delete a route 53
- AWS: Installing aws cli (Amazon Web Service Commandline)
No comments:
Post a Comment