Example usage for com.amazonaws.services.cloudfront.model GetCloudFrontOriginAccessIdentityRequest GetCloudFrontOriginAccessIdentityRequest

List of usage examples for com.amazonaws.services.cloudfront.model GetCloudFrontOriginAccessIdentityRequest GetCloudFrontOriginAccessIdentityRequest

Introduction

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

Prototype

public GetCloudFrontOriginAccessIdentityRequest(String id) 

Source Link

Document

Constructs a new GetCloudFrontOriginAccessIdentityRequest object.

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