使用CloudFront在AWS中创建内容分发

时间:2013-11-09 23:43:09

标签: java amazon-cloudfront

您好我正在尝试使用云前端在Java中创建两个内容发布。一个用于Flash,即RTMP,一个用于HTML5。我遇到的问题是,当我尝试通过Amazon API进行分发时,我可以选择创建其中任何一个,如何在Java中执行相同操作?

AmazonCloudFrontClient cloudfront = new AmazonCloudFrontClient(credentials);
        CreateCloudFrontOriginAccessIdentityRequest originRequest = new CreateCloudFrontOriginAccessIdentityRequest();
        originRequest.setRequestCredentials(credentials);

        Origin origin = new Origin()
        .withDomainName(bucketName+"s3.amazonaws.com")
        .withId(bucketName)
        .withS3OriginConfig(new S3OriginConfig().withOriginAccessIdentity(""));

        Origins origins = new Origins().withItems(origin);

        DistributionConfig streamingDistributionConfig = new DistributionConfig()
        .withCallerReference("unique-id-for-idempotency")
        .withComment("Streaming CloudFront distribution")
        .withDefaultRootObject("index.html")
        .withEnabled(true)
        .withOrigins(origins); 

        CreateDistributionRequest streamingDistribution = new CreateDistributionRequest()
        .withDistributionConfig(streamingDistributionConfig);           
        cloudfront.createDistribution(streamingDistribution);

1 个答案:

答案 0 :(得分:2)

刚刚解决了我自己的问题并发布了答案以防其他人需要帮助

对于流式传输

StreamingDistributionConfig streamingDistributionConfig = new StreamingDistributionConfig();
//include the with parameters 
CreateStreamingDistributionRequest streamingDistribution = new CreateStreamingDistributionRequest()
        .withStreamingDistributionConfig(streamingDistributionConfig);          
        cloudfront.createStreamingDistribution(streamingDistribution);

用于下载分发

DistributionConfig downloadingDistributionConfig = new DistributionConfig();
CreateDistributionRequest downloadingDistribution = new CreateDistributionRequest()
        .withDistributionConfig(downloadingDistributionConfig); 
        cloudfront.createDistribution(downloadingDistribution);

享受;)