AWS::CloudFront::CachePolicy and AWS::CloudFront::OriginRequestPolicy
1. Title
AWS::CloudFront::CachePolicy AWS::CloudFront::OriginRequestPolicy
2. Scope of request
Last week, CloudFront introduced reusable cache policies and origin request policies and deprecated the previous way of specifying these behaviors through the distribution configuration. I imagine the CloudFormation team is already aware of this change since the corresponding documentation in in CloudFormation is already up to date.
3. Expected behavior
The required parameters should probably stick with what the CreateCachePolicy and CreateOriginRequestPolicy API calls require, I think there's not much room for discussion regarding this.
Both of these should somehow return their ID to use along with the AWS::CloudFront::Distribution resource, otherwise there would be no meaning in including these resources in the first place.
4. Suggest specific test cases
When creating a new distribution with AWS::CloudFront::Distribution you would probably want to specify its cache policy and origin request policy along with it, as most have done up until now with the legacy way of specifying these parameters.
It's not a very good practice to hard-code the IDs of the cache policy and origin request policy, especially since if you use the same stack for multi-account deployments you would want to avoid both hard-coded values and parameters altogether, and the only option you would be left with would be to create an AWS::AccountId-based mapping with each account's cache policy/origin request policy ID, which as I'm sure you're aware, can lead to problems if your AccountID starts with a zero and you have to package your template before deploying it (awscli team I'm looking at you).
5. Helpful Links to speed up research and evaluation
Relevant CloudFront developer guide documentation
Relevant CloudFront API documentation for cache policies (CreateCachePolicy, UpdateCachePolicy and DeleteCachePolicy)
Relevant CloudFront API documentation for origin request policies (CreateOriginRequestPolicy, UpdateOriginRequestPolicy and DeleteOriginRequestPolicy)
CloudFormation documentation page for AWS::CloudFront::Distribution DefaultCacheBehavior, which is already up to date regarding these changes.
6. Category
Networking & Content Delivery
AWS::CloudFront
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/ReleaseHistory.html
I know this isn't a support channel (and I have a ticket open anyway) but I tried this today in eu-west-1 and us-east-1 and both times received an Invalid request provided message. Should this be working?
Ditto ap-southeast-2.
2020-09-14T03:20:42.598000+00:00 CloudFrontCachePolicy CREATE_FAILED
Invalid request provided: AWS::CloudFront::CachePolicy
{"CachePolicyConfig":<snip>}
I Just ran into the same issue (eu-central-1).
And while you're on it, please implement Brotli on the the AWS::CloudFront::CachePolicy ParametersInCacheKeyAndForwardedToOrigin type (EnableAcceptEncodingBrotli).
Is there a workaround for this? cachepolicy is not working in ap-southeast-1
Yep would like also to have EnableAcceptEncodingBrotli working 🙏
For those experiencing the Invalid request provided error, one thing to try is to check the Name of the CachePolicy; remove any spaces or special characters, and keep it alphanumeric. That unblocked me.
This seems to be fully supported and working now 👍
I'm getting failure with the following policy on us-east-1:
DefaultCachePolicy:
Type: 'AWS::CloudFront::CachePolicy'
Properties:
CachePolicyConfig:
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 1
Name: 'web-default-cache-policy'
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: 'none'
EnableAcceptEncodingBrotli: true
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: 'none'
QueryStringsConfig:
QueryStringBehavior: 'none'
AppCloudFrontDistribution:
Type: 'AWS::CloudFront::Distribution'
Properties:
DistributionConfig:
DefaultCacheBehavior:
CachePolicyId: !Ref DefaultCachePolicy
Compress: true
Does that look right? Is it a bug w/aws?
The error I get during change_set_execute is: Internal error reported from downstream service during operation

I had the same error. Turned out that minTtl was larger than maxTtl, which caused the error. Also, defaultTtl must be larger than minTtl.
I was getting Internal error reported from downstream service during operation 'AWS::CloudFront::CachePolicy' and solved it by making sure its Name was unique. If you have multiple distributions they each need a unique cache policy name or reference to a shared resource.
@burritoIand Make sure you dont already have a policy with that name, take a look in CloudFront. I had encountered a similar error and I figure out I already had a policy with same name.
@BogdanDarius thanks for the suggestion, I just checked and it only has the default policies. I also tried adding the stackname to the name param per @gpoitch but no dice!

@burritoIand can you share your yaml file maybe?
hey @BogdanDarius, will paste again:
DefaultCachePolicy:
Type: 'AWS::CloudFront::CachePolicy'
Properties:
CachePolicyConfig:
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 1
Name: !Sub 'CachePolicy-${AWS::StackName}'
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: 'none'
EnableAcceptEncodingBrotli: true
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: 'none'
QueryStringsConfig:
QueryStringBehavior: 'none'
When my build is running it successfully creates the changeset, but then fails during "CHANGE_SET_EXECUTE" with above error. I've been sort of background tinkering with this but I suppose I could try to create the policy using the cli and see if I get any more information on the error? Not sure how to get more info than "error reported downstream"
It'd be great if Name could be omitted to autogenerate a name.
Would love to find out if it there is indeed a bug preventing creating the cache policy with cloudformation...
Hit another issue with OriginRequestPolicy. HeaderBehavior set to allViewerAndWhitelistCloudFront fails with "Invalid request provided". Other values seem to work.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-originrequestpolicy-headersconfig.html#cfn-cloudfront-originrequestpolicy-headersconfig-headerbehavior
I also hit the Internal error reported from downstream service during operation 'AWS::CloudFront::OriginRequestPolicy' error.
Turns our I did not have the necessary cloudfront:CreateOriginRequestPolicy etc IAM rules in place.
@elgordino that was it! thank you