aws_cloudfront_cache_policy Resource
Use the aws_cloudfront_cache_policy
InSpec audit resource to test properties of a single specific AWS CloudFront cache policy.
The AWS::CloudFront::CachePolicy
resource describes the CloudFront cache policy.
Install
This resource is available in the Chef InSpec AWS resource pack.
For information on configuring your AWS environment for Chef InSpec and creating an InSpec profile that uses the InSpec AWS resource pack, see the Chef InSpec documentation on the AWS cloud platform.
Syntax
Ensure that the custom resource exists.
describe aws_cloudfront_cache_policy(id: 'ID') do
it { should exist }
end
Parameters
id
(required)The unique identifier for the cache policy.
For additional information, see the [AWS documentation on AWS CloudFormation cache policy.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-cache policy.html).
Properties
id
- The unique identifier for the cache policy.
last_modified_time
- The date and time when the cache policy was last modified.
cache_policy_config.comment
- A comment to describe the cache policy.
cache_policy_config.name
- A unique name to identify the cache policy.
cache_policy_config.default_ttl
- The default amount of time, in seconds, that you want objects to stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.
cache_policy_config.max_ttl
- The maximum amount of time, in seconds, that objects stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.
cache_policy_config.min_ttl
- The minimum amount of time, in seconds, that you want objects to stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.enable_accept_encoding_gzip
- A flag that can affect whether the Accept-Encoding HTTP header is included in the cache key and included in requests that CloudFront sends to the origin.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.enable_accept_encoding_brotli
- A flag that can affect whether the Accept-Encoding HTTP header is included in the cache key and included in requests that CloudFront sends to the origin.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.headers_config.header_behavior
- Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.headers_config.headers.quantity
- The number of header names in the Items list.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.headers_config.headers.items
- A list of HTTP header names.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.cookies_config.cookie_behavior
- Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.cookies_config.cookies.quantity
- The number of cookie names in the Items list.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.cookies_config.cookies.items
- A list of cookie names.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.query_strings_config.query_string_behavior
- Determines whether any URL query strings in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.query_strings_config.query_strings.quantity
- The number of query string names in the Items list.
cache_policy_config.parameters_in_cache_key_and_forwarded_to_origin.query_strings_config.query_strings.items
- A list of query string names.
Examples
Ensure a ID is available.
describe aws_cloudfront_cache_policy(id: 'ID') do
its('id') { should eq 'ID' }
end
Verify the max TTL of the policy.
describe aws_cloudfront_cache_policy(id: 'ID') do
its('cache_policy_config.max_ttl') { should eq 1 }
end
Matchers
For a full list of available matchers, see our Universal Matchers page.This resource has the following special matchers.
exist
Use should
to test that the entity exists.
describe aws_cloudfront_cache_policy(id: 'ID') do
it { should exist }
end
Use should_not
to test the entity does not exist.
describe aws_cloudfront_cache_policy(id: 'ID') do
it { should_not exist }
end
be_available
Use should
to check if the entity is available.
describe aws_cloudfront_cache_policy(id: 'ID') do
it { should be_available }
end
AWS Permissions
Your Principal will need the CloudFront:Client:GetCachePolicyResult
action with Effect
set to Allow
.