获取桶策略

您可以使用 getBucketPolicy 接口获取桶策略。以下代码展示如何获取一个桶的策略:

String bucketName = "<your-bucket-name>";
try {
    BucketPolicy bucketPolicy = s3.getBucketPolicy(bucketName);
    String policyText = bucketPolicy.getPolicyText();
    System.out.println(policyText);
} catch (AmazonServiceException e) {
    System.err.println(e.getErrorMessage());
}