List of usage examples for com.amazonaws.services.cloudfront.model CloudFrontOriginAccessIdentity getS3CanonicalUserId
public String getS3CanonicalUserId()
The Amazon S3 canonical user ID for the origin access identity, used when giving the origin access identity read permission to an object in Amazon S3.
From source file:org.duracloud.s3task.streaming.EnableStreamingTaskRunner.java
License:Apache License
private void setBucketAccessPolicy(String bucketName, String oaIdentityId) { CloudFrontOriginAccessIdentity cfOAIdentity = cfClient .getCloudFrontOriginAccessIdentity(new GetCloudFrontOriginAccessIdentityRequest(oaIdentityId)) .getCloudFrontOriginAccessIdentity(); String s3UserId = cfOAIdentity.getS3CanonicalUserId(); StringBuilder policyText = new StringBuilder(); policyText.append("{\"Version\":\"2012-10-17\","); policyText.append("\"Id\":\"PolicyForCloudFrontPrivateContent\","); policyText.append("\"Statement\":[{"); policyText.append("\"Sid\":\"Grant CloudFront access to private content\","); policyText.append("\"Effect\":\"Allow\","); policyText.append("\"Principal\":{\"CanonicalUser\":\"" + s3UserId + "\"},"); policyText.append("\"Action\":\"s3:GetObject\","); policyText.append("\"Resource\":\"arn:aws:s3:::" + bucketName + "/*\""); policyText.append("}]}"); s3Client.setBucketPolicy(bucketName, policyText.toString()); }