May's Blog

Hi! I moved my website to s3 + cloudflare for SSL certificate. Do you want to know how? I will show you:

First you will need to create new storage so Login to your AWS console as admin.

Create Bucket

Click on services and then select S3 from storage section.

On page click on Create Bucket in right corner and:

Update bucket properties

You will see bucket lists so select you bucket and from bucket page select Properties tab

Update Permissions

Select second tab Permissions scroll down to Bucket Policy click Edit and paste following policy.

 1{
 2    "Version": "2012-10-17",
 3    "Statement": [
 4        {
 5            "Sid": "Public",
 6            "Effect": "Allow",
 7            "Principal": "*",
 8            "Action": "s3:GetObject",
 9            "Resource": "<change-me-to-youw-ARN>/*"
10        }
11    ]
12}

Thats all for bucket configuration. Now you will need to create user who will be allowd to write content to you bucket.

Deployment user

So search for Identity and Access management IAM and open it.

Create Policy

First you will need to create policy. Find Policies in left menu and open it.

 1{
 2    "Version": "2012-10-17",
 3    "Statement": [
 4        {
 5            "Effect": "Allow",
 6            "Action": [
 7                "s3:ListAllMyBuckets"
 8            ],
 9            "Resource": "arn:aws:s3:::*"
10        },
11        {
12            "Effect": "Allow",
13            "Action": [
14                "s3:ListBucket",
15                "s3:GetBucketLocation"
16            ],
17            "Resource": "<change-me-to-youw-ARN>"
18        },
19        {
20            "Effect": "Allow",
21            "Action": [
22                "s3:PutObject",
23                "s3:PutObjectAcl",
24                "s3:GetObject",
25                "s3:GetObjectAcl",
26                "s3:DeleteObject"
27            ],
28            "Resource": "<change-me-to-youw-ARN>/*"
29        }
30    ]
31}

Important thing you will see "Resource": "<change-me-to-youw-ARN>" and "Resource": "<change-me-to-youw-ARN>/*" this is correct do not remove the /* on second one.

Create User

On left menu select Users and click on Add user

OK Thats All for settings on AWS. Next step is to configure our domain in Cloudflare

Add Domain to cloudflare

Login to cloudflare and click to + Add a site

Configure DNS rules

Ok if you are back you have configured domain name. So click on it and select 3rd tab DNS

Create second rule

Configure SSL/tls

Select 4th tab SSL/TLS

Select Edge certificates from tab

Setting up page rules

Next and last thing is to redirect our naked domain domain.tld to www.domain.tld.

So select 10th tab Page Rules

Done

Sot that all for prepare AWS + Cloudflare to your static website.

Bonus

To deploy website to AWS you can use minio-cli Minio with following script manually or you can use CI/CD

1mc config host add cdn https://s3.amazonaws.com <access-id> <secret-access-key> --api s3v4
2mc cp -r paath/to/website/files cdn/bucket-name

Now just navigate to your new website and enjoy. :)

Photo by Billy Huynh on Unsplash

#Tutorial