Skip to content

Commit 5ede456

Browse files
authored
feat(cloudfront): associate key value stores to functions (#28571)
CloudFormation now supports specifying [`KeyValueStoreAssocations`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-function-keyvaluestoreassociation.html) on a `AWS::CloudFront::Function`. This adds that support to the CDK. Even though the field is plural (in CloudFormation and the API), [a function can have one value store](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/kvs-with-functions-associate.html) so the implementation here tries to provide a nicer API around that. If a Key Value Store is specified, the function will default to `js-2.0` instead of `js-1.0`. Behavior for existing functions is retained. Additionally, an error is thrown if 1.0 is used. Closes #28377. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2801355 commit 5ede456

13 files changed

+655
-4
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/asset.9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-association.assets.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"Resources": {
3+
"TestKeyValueStore8D0C09A2": {
4+
"Type": "AWS::CloudFront::KeyValueStore",
5+
"Properties": {
6+
"Comment": "A test Key Value Store for CloudFront",
7+
"ImportSource": {
8+
"SourceArn": {
9+
"Fn::Join": [
10+
"",
11+
[
12+
"arn:",
13+
{
14+
"Ref": "AWS::Partition"
15+
},
16+
":s3:::",
17+
{
18+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
19+
},
20+
"/9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json"
21+
]
22+
]
23+
},
24+
"SourceType": "S3"
25+
},
26+
"Name": "integfunctionkeyvaluestoreassociationTestKeyValueStoreA8304A36"
27+
}
28+
},
29+
"TestFunction22AD90FC": {
30+
"Type": "AWS::CloudFront::Function",
31+
"Properties": {
32+
"AutoPublish": true,
33+
"FunctionCode": "code",
34+
"FunctionConfig": {
35+
"Comment": "TestKvFunction",
36+
"KeyValueStoreAssociations": [
37+
{
38+
"KeyValueStoreARN": {
39+
"Fn::GetAtt": [
40+
"TestKeyValueStore8D0C09A2",
41+
"Arn"
42+
]
43+
}
44+
}
45+
],
46+
"Runtime": "cloudfront-js-2.0"
47+
},
48+
"Name": "TestKvFunction"
49+
}
50+
}
51+
},
52+
"Parameters": {
53+
"BootstrapVersion": {
54+
"Type": "AWS::SSM::Parameter::Value<String>",
55+
"Default": "/cdk-bootstrap/hnb659fds/version",
56+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
57+
}
58+
},
59+
"Rules": {
60+
"CheckBootstrapVersion": {
61+
"Assertions": [
62+
{
63+
"Assert": {
64+
"Fn::Not": [
65+
{
66+
"Fn::Contains": [
67+
[
68+
"1",
69+
"2",
70+
"3",
71+
"4",
72+
"5"
73+
],
74+
{
75+
"Ref": "BootstrapVersion"
76+
}
77+
]
78+
}
79+
]
80+
},
81+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
82+
}
83+
]
84+
}
85+
}
86+
}

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json

+119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)