Share Open Data Amazon S3

Introduction

As discussed in my previous article, S3 is safe, secure and highly scalable object storage in AWS cloud. In fact, there are many use cases for S3. In case we want to share a data set to the world, we actually can share in S3 without using any web servers.

Create an S3 Bucket

Go to S3 page then create bucket.

Type an unique bucket name and uncheck “Block all public access”.

Scroll down and create bucket.

Configure Static WebSite Hosting

Download our sample file here. Unzip the file after download.

Click on the bucket, then click Upload.

Choose Add files and upload the content of sample-files folder.

Upload it.

Select properties.

Scroll down we will see “Static website hosting”, then we click edit.

Select Enable, type index.html and error.html in index document and error document, then save changes.

Now we can see the endpoint here, we can click it but it will show forbidden because we do not give enough right.

In Permissions, click Edit under Bucket policy.

place the below policy and save changes. Reminded that please change to your own ARN.

{
    "Version": "2012-10-17",
    "Id": "Policy1606640377747",
    "Statement": [
        {
            "Sid": "Stmt1606640353536",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::Bucket/*"
        }
    ]
}

Enable CORS

In index.html, we use JavaScript to dynamically read the contents of the bucket and display a list of objects to visitors. Thus, we have to enable Cross-Origin Resources Sharing (CORS).

Back to Permission tab, click Edit under CORS.

We place the below code into the editor and save it.

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "MaxAgeSeconds": 3000
    }
]

Also in the permission, we click edit under ACL.

Check list and read option for everyone, then confirm and save changes.

Now copy the endpoint URL and browse it.

We are able to get our open data now.

Cleanup

We just have to empty and delete the bucket.

Leave a Reply