Search in sources :

Example 1 with GetBucketPolicyRequest

use of software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest in project aws-doc-sdk-examples by awsdocs.

the class GetBucketPolicy method getPolicy.

// snippet-start:[s3.java2.get_bucket_policy.main]
public static String getPolicy(S3Client s3, String bucketName) {
    String policyText = "";
    System.out.format("Getting policy for bucket: \"%s\"\n\n", bucketName);
    GetBucketPolicyRequest policyReq = GetBucketPolicyRequest.builder().bucket(bucketName).build();
    try {
        GetBucketPolicyResponse policyRes = s3.getBucketPolicy(policyReq);
        policyText = policyRes.policy();
        return policyText;
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) GetBucketPolicyRequest(software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest) GetBucketPolicyResponse(software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse)

Aggregations

GetBucketPolicyRequest (software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest)1 GetBucketPolicyResponse (software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse)1 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)1