ruby/example_code/s3/s3_get_bucket_object_acls.rb
def list_object_acls(s3_client, bucket_name, object_key)
  response = s3_client.get_object_acl(bucket: bucket_name, key: object_key)
  if response.grants.count.zero?
    puts 'No ACLs for this object.'
  else
    puts
    puts "Owner       #{response.owner.display_name}"
    puts
    response.grants.each do |grant|
      grantee = grant.grantee
      if grantee.type == 'Group'
        puts 'Grantee     GROUP'
        puts 'URI         ' + grantee.uri
      else
        if grantee.display_name.nil?
          puts 'Grantee     EVERYONE'
        else
          puts 'Grantee     ' + grantee.display_name
        end
        if grantee.id.nil?
          puts 'ID          NONE'
        else
          puts 'ID          ' + grantee.id
        end
      end
      puts 'Permission  ' + grant.permission
      puts
    end
  end
rescue StandardError => e
  puts "Error getting bucket ACLs: #{e.message}"
end
# Prerequisites:
#
# - An Amazon S3 bucket.
# - An object in the bucket.
#
# @param s3_client [Aws::S3::Client] An initialized Amazon S3 client.
# @param bucket_name [String] The name of the bucket.
# @param object_key [String] The name of the object.
# @return [String] Information about the ACLs.
# @example
#   list_object_acls(
#     Aws::S3::Client.new(region: 'us-west-2'),
#     'doc-example-bucket',
#     'my-file.txt'
#   )

An Amazon S3 bucket.
An object in the bucket.
An Amazon S3 bucket . An object in the bucket .
def list_object_acls(s3_client, bucket_name, object_key)
  response = s3_client.get_object_acl(bucket: bucket_name, key: object_key)
  if response.grants.count.zero?
    puts 'No ACLs for this object.'
  else
    puts
    puts "Owner       #{response.owner.display_name}"
    puts
    response.grants.each do |grant|
      grantee = grant.grantee
      if grantee.type == 'Group'
        puts 'Grantee     GROUP'
        puts 'URI         ' + grantee.uri
      else
        if grantee.display_name.nil?
          puts 'Grantee     EVERYONE'
        else
          puts 'Grantee     ' + grantee.display_name
        end
        if grantee.id.nil?
          puts 'ID          NONE'
        else
          puts 'ID          ' + grantee.id
        end
      end
      puts 'Permission  ' + grant.permission
      puts
    end
  end
rescue StandardError => e
  puts "Error getting bucket ACLs: #{e.message}"
end
def list_object_acls ( s3_client , bucket_name , object_key ) response = s3_client . get_object_acl ( bucket : bucket_name , key : object_key ) if response . grants . count . zero? puts 'No ACLs for this object.' else puts puts "Owner       #{response.owner.display_name}" puts response . grants . each do | grant | grantee = grant . grantee if grantee . type == 'Group' puts 'Grantee     GROUP' puts 'URI         ' + grantee . uri else if grantee . display_name . nil? puts 'Grantee     EVERYONE' else puts 'Grantee     ' + grantee . display_name end if grantee . id . nil? puts 'ID          NONE' else puts 'ID          ' + grantee . id end end puts 'Permission  ' + grant . permission puts end end rescue StandardError => e puts "Error getting bucket ACLs: #{e.message}" end
Prerequisites:
 An Amazon S3 bucket.
Prerequisites : An Amazon S3 bucket .
Information about the ACLs.
Information about the ACLs .
String
s3_client
An initialized Amazon S3 client.
An initialized Amazon S3 client .
bucket_name
The name of the bucket.
The name of the bucket .
object_key
The name of the object.
The name of the object .
example
list_object_acls( Aws::S3::Client.new(region: 'us-west-2'), 'doc-example-bucket', 'my-file.txt' )
list_object_acls ( Aws :: S3 :: Client . new ( region : ' us - west - 2 ' ) ' doc - example - bucket ' ' my - file . txt ' )