ONCE A DAY

HELPING OTHERS EVERY DAY

Thank you for being here.

I created Once A Day during my graduate studies to share what I was learning with the rest of the world. Its a Ruby On Rails application on heroku. After hundreds of posts, this project has become an integral part of my life. My late mother wanted me to help out others as much as I could and Once a Day as a platform helps me accomplish this. Even if I am able to help one person, it is a blessing.
Through the navbar above, you can browse through all my posts for free, buy reusable code plugins and components through my gumroad store (I provide free support and maintainance), hire me as a mentor on mentorcruise or just browse though my youtube videos on coding or working out.

If you feel Once a Day was helpful to you and want to help, you can donate here.

Best,
Saurav Prakash
Son, Engineer, Brother


FEATURED POST

AWS S3- HOW TO SHARE FILES STORED IN AN AWS PUBLIC BUCKET

By: Saurav

2020-11-09 07:23:00 UTC

A simple problem indeed but has moving parts which takes sometime to get it to work. Keep in mind making a bucket public might suit your use case but more than you think, you don't need to give everyone on the internet permissions to view your files. You can always set policies and permissions for clients and your bucket to allow for the data transmission.

But suppose you have a bucket where you have files or folders which you want to make available publicly (without need for setting aws cli config)

Steps


1. You set up public access on all objects (Programmatically or through web interface)
2. Then on the bucket, under Your Bucket > Permissions > Access control list (ACL) > you set Objects and Bucket ACL as indicated below.
3. Also set the block public access policy as off as indicated below.

Screen shot 2020 11 08 at 11.36.39 pm

Screen shot 2020 11 08 at 11.36.31 pm

4. Finally add the following policy to the bucket as shown below (SID is optional). The policies allow any one to list your bucket and get each object.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::your-bucket-name/*",
                "arn:aws:s3:::your-bucket-name"
            ]
        }
    ]
}

Now, let's talk about how to access it.
Note: I tried aws cli and used cp command with the above setup and I had issues. It makes sense since we are not providing objects but a bucket which needs to by synced.

Therefore, the right commands for any one to list and download your files are:

To List: aws s3 ls s3://your-bucket-name/folder_name/ --no-sign-request 

To Download (Sync): aws s3 sync s3://your-bucket-name/folder_name/ ~/projects/folder_name/ --no-sign-request

Do note the --no-sign-request flag added. This makes sure that your client does not need to configure AWS CLI before accessing your files, which is IMO truly public.

A great use case would be when you need to share huge numbers of heavy files with someone else. You set up like this and they run the above command or automate it using cron job. It will make sure they always get any future files uploaded to your S3 public bucket.

Owned & Maintained by Saurav Prakash

If you like what you see, you can help me cover server costs or buy me a cup of coffee though donation :)