Search code examples
javaamazon-web-servicesaws-sdkaws-sdk-java-2.0aws-sdk-java

No method for setObjectAcl in AWS Java SDK v2.x


I am upgrading a legacy java application that used AWS SDK v1.5 for S3 operations, and one of the functions it had to do was to change an objects ACL, from private to public-read, based on certain conditions. The v1.5 AmazonS3 had a method for this, simple as:

s3client.setObjectAcl(bucketName, s3Key, acl);

But it appears that feature or capability doesn't exist in v2.21.2. I've looked through all the posted examples and documentation, and found a rather complex example of how to change the ACL for a bucket, but I need to be able to set a single object acl to public-read or back to private, not the whole bucket.

How do I do this in AWS SDK v2.21.x?


Solution

  • In v2, they renamed some of the methods to match API action names:

    To provide SDK support for the many services that AWS owns, the AWS SDKs make extensive use of code generation. In 1.11.x, all service clients are generated, except for the S3 client. This frequently results in a disconnect between how non-Java AWS SDKs and IAM policies refer to an S3 operation (e.g., DeleteBucketReplicationConfiguration), and how the Java AWS SDK would refer to that same operation (DeleteBucketReplication). This made creating IAM policies and switching to other SDKs difficult, because the equivalent string was not always well documented.

    In 2.x, S3 is generated like every other service, ensuring the operation names, inputs, and outputs will always match those of other SDKs and IAM.

    You're looking for putObjectAcl, which is a wrapper for PutObjectAcl API action.