|
| 1 | +--- |
| 2 | +subcategory: "CloudFront" |
| 3 | +layout: "aws" |
| 4 | +page_title: "AWS: aws_cloudfront_create_invalidation" |
| 5 | +description: |- |
| 6 | + Invalidates CloudFront distribution cache for specified paths. |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +<!-- Please do not edit this file, it is generated. --> |
| 11 | +# Action: aws_cloudfront_create_invalidation |
| 12 | + |
| 13 | +~> **Note:** `aws_cloudfront_create_invalidation` is in beta. Its interface and behavior may change as the feature evolves, and breaking changes are possible. It is offered as a technical preview without compatibility guarantees until Terraform 1.14 is generally available. |
| 14 | + |
| 15 | +Invalidates CloudFront distribution cache for specified paths. This action creates an invalidation request and waits for it to complete. |
| 16 | + |
| 17 | +For information about CloudFront cache invalidation, see the [Amazon CloudFront Developer Guide](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html). For specific information about creating invalidation requests, see the [CreateInvalidation](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateInvalidation.html) page in the Amazon CloudFront API Reference. |
| 18 | + |
| 19 | +~> **Note:** CloudFront invalidation requests can take several minutes to complete. This action will wait for the invalidation to finish before continuing. You can only have a limited number of invalidation requests in progress at any given time. |
| 20 | + |
| 21 | +## Example Usage |
| 22 | + |
| 23 | +### Basic Usage |
| 24 | + |
| 25 | +```python |
| 26 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 27 | +from cdktf import TerraformResourceLifecycle |
| 28 | +from constructs import Construct |
| 29 | +from cdktf import DataResource, TerraformStack |
| 30 | +# |
| 31 | +# Provider bindings are generated by running `cdktf get`. |
| 32 | +# See https://cdk.tf/provider-generation for more details. |
| 33 | +# |
| 34 | +from imports.aws.cloudfront_distribution import CloudfrontDistribution |
| 35 | +class MyConvertedCode(TerraformStack): |
| 36 | + def __init__(self, scope, name, *, defaultCacheBehavior, enabled, origin, restrictions, viewerCertificate): |
| 37 | + super().__init__(scope, name) |
| 38 | + CloudfrontDistribution(self, "example", |
| 39 | + default_cache_behavior=default_cache_behavior, |
| 40 | + enabled=enabled, |
| 41 | + origin=origin, |
| 42 | + restrictions=restrictions, |
| 43 | + viewer_certificate=viewer_certificate |
| 44 | + ) |
| 45 | + terraform_data_example = DataResource(self, "example_1", |
| 46 | + input="trigger-invalidation", |
| 47 | + lifecycle=TerraformResourceLifecycle( |
| 48 | + action_trigger=[{ |
| 49 | + "actions": [aws_cloudfront_create_invalidation.example], |
| 50 | + "events": [before_create, before_update] |
| 51 | + } |
| 52 | + ] |
| 53 | + ) |
| 54 | + ) |
| 55 | + # This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match. |
| 56 | + terraform_data_example.override_logical_id("example") |
| 57 | +``` |
| 58 | + |
| 59 | +### Invalidate Specific Paths |
| 60 | + |
| 61 | +```python |
| 62 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 63 | +from constructs import Construct |
| 64 | +from cdktf import TerraformStack |
| 65 | +class MyConvertedCode(TerraformStack): |
| 66 | + def __init__(self, scope, name): |
| 67 | + super().__init__(scope, name) |
| 68 | +``` |
| 69 | + |
| 70 | +### With Custom Caller Reference |
| 71 | + |
| 72 | +```python |
| 73 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 74 | +from constructs import Construct |
| 75 | +from cdktf import TerraformStack |
| 76 | +class MyConvertedCode(TerraformStack): |
| 77 | + def __init__(self, scope, name): |
| 78 | + super().__init__(scope, name) |
| 79 | +``` |
| 80 | + |
| 81 | +### CI/CD Pipeline Integration |
| 82 | + |
| 83 | +Use this action in your deployment pipeline to invalidate cache after updating static assets: |
| 84 | + |
| 85 | +```python |
| 86 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 87 | +from cdktf import TerraformResourceLifecycle |
| 88 | +from constructs import Construct |
| 89 | +from cdktf import DataResource, TerraformStack |
| 90 | +class MyConvertedCode(TerraformStack): |
| 91 | + def __init__(self, scope, name): |
| 92 | + super().__init__(scope, name) |
| 93 | + DataResource(self, "deploy_complete", |
| 94 | + depends_on=[assets], |
| 95 | + input=deployment_id, |
| 96 | + lifecycle=TerraformResourceLifecycle( |
| 97 | + action_trigger=[{ |
| 98 | + "actions": [aws_cloudfront_create_invalidation.post_deploy], |
| 99 | + "events": [before_create, before_update] |
| 100 | + } |
| 101 | + ] |
| 102 | + ) |
| 103 | + ) |
| 104 | +``` |
| 105 | + |
| 106 | +### Environment-Specific Invalidation |
| 107 | + |
| 108 | +```python |
| 109 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 110 | +from constructs import Construct |
| 111 | +from cdktf import TerraformStack |
| 112 | +class MyConvertedCode(TerraformStack): |
| 113 | + def __init__(self, scope, name): |
| 114 | + super().__init__(scope, name) |
| 115 | +``` |
| 116 | + |
| 117 | +## Argument Reference |
| 118 | + |
| 119 | +This action supports the following arguments: |
| 120 | + |
| 121 | +* `distribution_id` - (Required) ID of the CloudFront distribution to invalidate cache for. Must be a valid CloudFront distribution ID (e.g., E1GHKQ2EXAMPLE). |
| 122 | +* `paths` - (Required) List of file paths or patterns to invalidate. Use `/*` to invalidate all files. Supports specific files (`/index.html`), directory wildcards (`/images/*`), or all files (`/*`). Maximum of 3000 paths per invalidation request. Note: The first 1,000 invalidation paths per month are free, additional paths are charged per path. |
| 123 | +* `caller_reference` - (Optional) Unique identifier for the invalidation request. If not provided, one will be generated automatically. Maximum length of 128 characters. |
| 124 | +* `timeout` - (Optional) Timeout in seconds to wait for the invalidation to complete. Defaults to 900 seconds (15 minutes). Must be between 60 and 3600 seconds. Invalidation requests typically take 5-15 minutes to process. |
| 125 | + |
| 126 | +<!-- cache-key: cdktf-0.20.8 input-3ba7a7c91d667076b84a198aec1af23be5ea0b6720335d79dd76c24a938c6515 --> |
0 commit comments