title: Cloudformation S3 bucket principal for Cloudfront
body: <p>I'm trying to create a Yaml template for cloudfront distribution on S3 bucket.
  I'm stuck on how to add <code>principal</code> on <code>BucketPolicy</code>. </p>
  
  <p>I want to know how to replace the <code>XXXXXXXXXXX</code> on CloudFront Origin Access Identity XXXXXXXXXXX in principal for a cloudfront that will be generate by deploying the template.</p>
  
  <p>Also is there a way to add the html, css sync procedure (which I'm doing through aws cli now) on yaml template? </p>
  
  <p>Please let me know.
  TIA</p>
  
  <pre><code> AWSTemplateFormatVersion: 2010-09-09
   Resources:
     Bucket:
       Type: 'AWS::S3::Bucket'
       Properties:
         BucketName: pridesys.webbucket
         AccessControl: Private 
         WebsiteConfiguration:
           IndexDocument: index.html
  
     BucketPolicy:
       Type: AWS::S3::BucketPolicy
       Properties:
         Bucket: !Ref Bucket
         PolicyDocument:
           Id: ReportPolicy
           Version: "2012-10-17"
           Statement:
             - Sid: "1"
               Effect: Allow
               Action: "s3:GetObject"
               Principal:
                 AWS: "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXX"
               Resource: !Join ['', ['arn:aws:s3:::', !Ref Bucket, '/*']]
  
     Distro:
       Type: 'AWS::CloudFront::Distribution'
       Properties:
         DistributionConfig:
           Origins:
             - DomainName: !GetAtt Bucket.DomainName
               Id: foo
               S3OriginConfig: {}
            Enabled: True
           DefaultRootObject: index.html
           DefaultCacheBehavior:
             ForwardedValues:
               QueryString: False
             TargetOriginId: foo
             ViewerProtocolPolicy: allow-all
  </code></pre>