Skip to content

Commit 68f50b0

Browse files
authored
Document nonce
1 parent 5fc937a commit 68f50b0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,67 @@ static_site_cf.resource.node.add_dependency(api_cf.resource)
195195
## Dependencies/Miscellany
196196

197197
In order to support the latest version of the Cloudfront API, this Construct will build a Lambda Layer including the latest version of `boto3`. This requires Docker to be running and will store the layer files in `./cdk.out/layers/cf_update_deps_layer`.
198+
199+
## Forcing updates with a nonce
200+
201+
In the event that it is desirable for the custom resource to run at every deployment, a `nonce` argument can be provided to the construct. This will trigger the redeployment of the `CustomResource` but not the Lambda or related IAM policies.
202+
203+
```python
204+
from time import time
205+
206+
from constructs import Construct
207+
from cdk_cloudfront_update.constructs import CloudfrontUpdate
208+
209+
210+
class MyApi(Construct):
211+
def __init__(
212+
self,
213+
scope: Construct,
214+
id: str,
215+
distribution_arn: str,
216+
service_path_pattern: str,
217+
load_balancer_dns_name: str,
218+
**kwargs,
219+
):
220+
"""
221+
Add MyAPI service to the Cloudfront Distribution at the
222+
specified path.
223+
"""
224+
super().__init__(scope, id, **kwargs)
225+
226+
origin_id = "ApiLoadBalancer"
227+
228+
CloudfrontUpdate(
229+
self,
230+
"my-api-cf-update",
231+
distribution_arn=distribution_arn,
232+
behavior_config={
233+
"PathPattern": service_path_pattern,
234+
"TargetOriginId": origin_id,
235+
"TrustedSigners": {"Enabled": False, "Quantity": 0},
236+
"TrustedKeyGroups": {"Enabled": False, "Quantity": 0},
237+
"ViewerProtocolPolicy": "redirect-to-https",
238+
"AllowedMethods": {
239+
"Quantity": 7,
240+
"Items": [
241+
"HEAD",
242+
"DELETE",
243+
"POST",
244+
"GET",
245+
"OPTIONS",
246+
"PUT",
247+
"PATCH",
248+
],
249+
"CachedMethods": {"Quantity": 2, "Items": ["HEAD", "GET"]},
250+
},
251+
"SmoothStreaming": False,
252+
"Compress": True,
253+
"LambdaFunctionAssociations": {"Quantity": 0},
254+
"FunctionAssociations": {"Quantity": 0},
255+
"FieldLevelEncryptionId": "",
256+
"CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad", # Managed CachingDisabled Policy
257+
"OriginRequestPolicyId": "216adef6-5c7f-47e4-b989-5492eafa07d3", # Managed AllViewer Origin Request Policy
258+
},
259+
nonce=str(time())
260+
)
261+
```

0 commit comments

Comments
 (0)