Skip to content

Commit ce1209a

Browse files
authored
docs(cloudfront): add example to update Cloudfront publickey (#34729)
### Issue # (if applicable) Related to #15301. ### Reason for this change Users wanted a more detailed guide on how to update the `encodedKey`. ### Description of changes Add an example to show how to update the key, replaced `logical id` by `id` for more clarity. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 856e3b1 commit ce1209a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/aws-cdk-lib/aws-cloudfront/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,24 @@ When using a CloudFront PublicKey, only the `comment` field can be updated after
12521252
Resource handler returned message: "Invalid request provided: AWS::CloudFront::PublicKey"
12531253
```
12541254

1255-
To update the `encodedKey`, you must change the logical ID of the public key resource in your template. This causes CloudFormation to create a new `cloudfront.PublicKey` resource and delete the old one during the next deployment.
1255+
To update the `encodedKey`, you must change the ID of the public key resource in your template. This causes CloudFormation to create a new `cloudfront.PublicKey` resource and delete the old one during the next deployment.
1256+
1257+
Example:
1258+
1259+
```ts
1260+
// Step 1: Original deployment
1261+
const originalKey = new cloudfront.PublicKey(this, 'MyPublicKeyV1', {
1262+
encodedKey: '...', // contents of original public_key.pem file
1263+
});
1264+
```
1265+
1266+
Regenerate a new key and change the construct id in the code:
1267+
```ts
1268+
// Step 2: In a subsequent deployment, create a new key with a different ID
1269+
const updatedKey = new cloudfront.PublicKey(this, 'MyPublicKeyV2', {
1270+
encodedKey: '...', // contents of new public_key.pem file
1271+
});
1272+
```
12561273

12571274

12581275
See:

0 commit comments

Comments
 (0)