Example usage for com.amazonaws.services.cloudfront.model CloudFrontOriginAccessIdentity getS3CanonicalUserId

List of usage examples for com.amazonaws.services.cloudfront.model CloudFrontOriginAccessIdentity getS3CanonicalUserId

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront.model CloudFrontOriginAccessIdentity getS3CanonicalUserId.

Prototype


public String getS3CanonicalUserId() 

Source Link

Document

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.

Usage

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());
}