简体   繁体   中英

How to get S3 objects created by current user in AWS SDK (Ruby on Rails)?

使用 AWS SDK,是否可以通过编程方式获取特定用户(当前用户)创建的所有存储桶对象的列表?

This will help you:

require 'aws-sdk-s3'  # v2: require 'aws-sdk'

region = 'us-west-2'
s3 = Aws::S3::Resource.new(region: region)

s3.buckets.limit(50).each do |b|
  puts "#{b.name}"
end

Source

Also, this will list the objects of a bucket:

s3_bucket.objects.with_prefix('folder_name').collect(&:key)

With version 2 it is:

s3_bucket.objects(prefix: 'folder_name').collect(&:key)

Source

Combination of both will help you achieve your goal.

It is not possible to identify the "user" who created an object.

When an API call is made to Amazon S3 to upload/create an object, the credentials are checked to confirm that they are permitted to perform the operation. Once this has been confirmed, the object that is created is "owned" by the AWS Account, not a specific user within the account.

You could Enable Object-Level Logging for an S3 Bucket , but this only outputs log information. It does not associate an object with a user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM