Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

s3 presigned url for access to entire folder

I have an s3 bucket that has individual folders that contain different websites. I would like to generate a presigned url for access to a specific folder, however I would like to have the url allow access to all objects in that folder. Is this possible?

I'm using the ruby aws-sdk gem v2.

My existing code looks like this

  def get_object_url(bucket_name, object_name)
    res = Aws::S3::Resource::new
    obj = res.bucket(bucket_name).object(object_name)
    exp = 1.day
    url = obj.presigned_url(:get, {
                           expires_in: exp,
                           virtual_host: true
                       })
    url
  end

passing the folder name as object_name doesn't work.

like image 729
denodster Avatar asked Oct 06 '15 16:10

denodster


People also ask

How do I give access to a specific directory in S3 bucket?

If the IAM user and S3 bucket belong to the same AWS account, then you can grant the user access to a specific bucket folder using an IAM policy. As long as the bucket policy doesn't explicitly deny the user access to the folder, you don't need to update the bucket policy if access is granted by the IAM policy.

When should I use Presigned URL S3?

Pre-signed URLs are used to provide short-term access to a private object in your S3 bucket. They work by appending an AWS Access Key, expiration time, and Sigv4 signature as query parameters to the S3 object. There are two common use cases when you may want to use them: Simple, occasional sharing of private files.

How does Presigned URL work S3?

S3 pre-signed URLs are a form of an S3 URL that temporarily grants restricted access to a single S3 object to perform a single operation — either PUT or GET — for a predefined time limit. To break it down: It is secure — the URL is signed using an AWS access key.

How do I get a Presigned URL?

To generate a presigned URL using the AWS Management ConsoleIn the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for. On the Actions menu, choose Share with a presigned URL.


3 Answers

No, S3 doesn't really have a true concept of a folder. The folders are "created" using segments of the object paths. They do not exist independently of objects.

like image 142
datasage Avatar answered Sep 28 '22 19:09

datasage


I recently had this problem and i could find a solution with custom policies for signed URL using cloudfront.

Has some pros and cons, the main one is that u dont need to sign for each object so is much more faster if you need to share many objects. But it goes like outside of aws traffic.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-custom-policy.html

like image 26
Fabián Bertetto Avatar answered Sep 28 '22 20:09

Fabián Bertetto


My workaround will be to compress files and folder structure into an archive (like zip) and just upload that single object (file) to the presigned URL.

like image 3
Jacob Avatar answered Sep 28 '22 18:09

Jacob