Search code examples
amazon-web-servicesamazon-s3aws-sdkaws-java-sdk

How to change Storage Class on AWS S3 object via java sdk


I am new to AWS, I need to set Storage Class for an existed object in s3 bucket. How can I change the storage class of an Object in S3 using the java SDK


Solution

  • there is no need to use deprecated method in any case. in my case in need to update an existing object:

       AmazonS3Client s3Client =  (AmazonS3Client)AmazonS3ClientBuilder.standard()
                    .withRegion(clientRegion)
                    .withCredentials(new ProfileCredentialsProvider())
                    .build();
      CopyObjectRequest copyRequest = new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey)
            .withStorageClass(StorageClass.ReducedRedundancy);
            s3Client.copyObject(copyRequest);