From 1d7cd7940093d28a4a938ebf1a8388813d1a8e29 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Wed, 3 Jan 2024 20:47:31 -0500 Subject: [PATCH 1/7] feat(cloudfront): associate key value stores to functions --- ...efaultTestDeployAssert1F41BE04.assets.json | 19 ++ ...aultTestDeployAssert1F41BE04.template.json | 36 +++ ...0affe8fd26234f67dcf2e93db5142bc2991a1.json | 12 + .../cdk.out | 1 + ...ion-key-value-store-assocation.assets.json | 32 +++ ...n-key-value-store-assocation.template.json | 102 ++++++++ .../integ.json | 12 + .../manifest.json | 125 +++++++++ .../tree.json | 245 ++++++++++++++++++ ...eg.function-key-value-store-association.ts | 23 ++ .../aws-cloudfront/lib/function.ts | 31 ++- .../aws-cloudfront/test/function.test.ts | 109 +++++++- 12 files changed, 743 insertions(+), 4 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/asset.9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json new file mode 100644 index 0000000000000..eb7a96fb24cea --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/asset.9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/asset.9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json new file mode 100644 index 0000000000000..c5999fd9d8723 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/asset.9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json @@ -0,0 +1,12 @@ +{ + "data":[ + { + "key":"key1", + "value":"value" + }, + { + "key":"key2", + "value":"value" + } + ] +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json new file mode 100644 index 0000000000000..63afcbb2a2cdc --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json @@ -0,0 +1,32 @@ +{ + "version": "36.0.0", + "files": { + "9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1": { + "source": { + "path": "asset.9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "8cd51bc32be5868f31c493a1b55db8768f9445c51a8aefbf2904c93e064c22f9": { + "source": { + "path": "integ-function-key-value-store-assocation.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "8cd51bc32be5868f31c493a1b55db8768f9445c51a8aefbf2904c93e064c22f9.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json new file mode 100644 index 0000000000000..144bb883abf9f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json @@ -0,0 +1,102 @@ +{ + "Resources": { + "TestKeyValueStore8D0C09A2": { + "Type": "AWS::CloudFront::KeyValueStore", + "Properties": { + "Comment": "A test Key Value Store for CloudFront", + "ImportSource": { + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":s3:::", + { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "/9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json" + ] + ] + }, + "SourceType": "S3" + }, + "Name": "integfunctionkeyvaluestoreassocationTestKeyValueStoreAA209C02" + } + }, + "TestKeyValueStore25F61F0F5": { + "Type": "AWS::CloudFront::KeyValueStore", + "Properties": { + "Name": "integfunctionkeyvaluestoreassocationTestKeyValueStore2A09DC08D" + } + }, + "TestFunction22AD90FC": { + "Type": "AWS::CloudFront::Function", + "Properties": { + "AutoPublish": true, + "FunctionCode": "code", + "FunctionConfig": { + "Comment": { + "Fn::Join": [ + "", + [ + { + "Ref": "AWS::Region" + }, + "integfunctreassocationTestFunctionEC38B947" + ] + ] + }, + "Runtime": "cloudfront-js-1.0" + }, + "Name": { + "Fn::Join": [ + "", + [ + { + "Ref": "AWS::Region" + }, + "integfunctreassocationTestFunctionEC38B947" + ] + ] + } + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json new file mode 100644 index 0000000000000..667a3fe038ebb --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "FunctionKeyValueStoreAssocation/DefaultTest": { + "stacks": [ + "integ-function-key-value-store-assocation" + ], + "assertionStack": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert", + "assertionStackName": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json new file mode 100644 index 0000000000000..429ef4bacd476 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json @@ -0,0 +1,125 @@ +{ + "version": "36.0.0", + "artifacts": { + "integ-function-key-value-store-assocation.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integ-function-key-value-store-assocation.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integ-function-key-value-store-assocation": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "integ-function-key-value-store-assocation.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/8cd51bc32be5868f31c493a1b55db8768f9445c51a8aefbf2904c93e064c22f9.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integ-function-key-value-store-assocation.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "integ-function-key-value-store-assocation.assets" + ], + "metadata": { + "/integ-function-key-value-store-assocation/TestKeyValueStore/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestKeyValueStore8D0C09A2" + } + ], + "/integ-function-key-value-store-assocation/TestKeyValueStore2/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestKeyValueStore25F61F0F5" + } + ], + "/integ-function-key-value-store-assocation/TestFunction/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "TestFunction22AD90FC" + } + ], + "/integ-function-key-value-store-assocation/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-function-key-value-store-assocation/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-function-key-value-store-assocation" + }, + "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets" + ], + "metadata": { + "/FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json new file mode 100644 index 0000000000000..9b7f99dd53a89 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json @@ -0,0 +1,245 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "integ-function-key-value-store-assocation": { + "id": "integ-function-key-value-store-assocation", + "path": "integ-function-key-value-store-assocation", + "children": { + "TestKeyValueStore": { + "id": "TestKeyValueStore", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore", + "children": { + "ImportSource": { + "id": "ImportSource", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore/ImportSource", + "children": { + "Stage": { + "id": "Stage", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore/ImportSource/Stage", + "constructInfo": { + "fqn": "aws-cdk-lib.AssetStaging", + "version": "0.0.0" + } + }, + "AssetBucket": { + "id": "AssetBucket", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore/ImportSource/AssetBucket", + "constructInfo": { + "fqn": "aws-cdk-lib.aws_s3.BucketBase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_s3_assets.Asset", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudFront::KeyValueStore", + "aws:cdk:cloudformation:props": { + "comment": "A test Key Value Store for CloudFront", + "importSource": { + "sourceType": "S3", + "sourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":s3:::", + { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "/9c0f502203ec9d802046021b8a20affe8fd26234f67dcf2e93db5142bc2991a1.json" + ] + ] + } + }, + "name": "integfunctionkeyvaluestoreassocationTestKeyValueStoreAA209C02" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.CfnKeyValueStore", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.KeyValueStore", + "version": "0.0.0" + } + }, + "TestKeyValueStore2": { + "id": "TestKeyValueStore2", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore2", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-function-key-value-store-assocation/TestKeyValueStore2/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudFront::KeyValueStore", + "aws:cdk:cloudformation:props": { + "name": "integfunctionkeyvaluestoreassocationTestKeyValueStore2A09DC08D" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.CfnKeyValueStore", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.KeyValueStore", + "version": "0.0.0" + } + }, + "TestFunction": { + "id": "TestFunction", + "path": "integ-function-key-value-store-assocation/TestFunction", + "children": { + "Resource": { + "id": "Resource", + "path": "integ-function-key-value-store-assocation/TestFunction/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudFront::Function", + "aws:cdk:cloudformation:props": { + "autoPublish": true, + "functionCode": "code", + "functionConfig": { + "comment": { + "Fn::Join": [ + "", + [ + { + "Ref": "AWS::Region" + }, + "integfunctreassocationTestFunctionEC38B947" + ] + ] + }, + "runtime": "cloudfront-js-1.0" + }, + "name": { + "Fn::Join": [ + "", + [ + { + "Ref": "AWS::Region" + }, + "integfunctreassocationTestFunctionEC38B947" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.Function", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "integ-function-key-value-store-assocation/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "integ-function-key-value-store-assocation/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "FunctionKeyValueStoreAssocation": { + "id": "FunctionKeyValueStoreAssocation", + "path": "FunctionKeyValueStoreAssocation", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "FunctionKeyValueStoreAssocation/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "FunctionKeyValueStoreAssocation/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts new file mode 100644 index 0000000000000..3d33b7e792983 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts @@ -0,0 +1,23 @@ +import * as path from 'node:path'; +import * as cdk from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'integ-function-key-value-store-assocation'); + +const store = new cloudfront.KeyValueStore(stack, 'TestKeyValueStore', { + comment: 'A test Key Value Store for CloudFront', + source: cloudfront.ImportSource.fromAsset(path.join(__dirname, 'test-import-source.json')), +}); +const store2 = new cloudfront.KeyValueStore(stack, 'TestKeyValueStore2'); +new cloudfront.Function(stack, 'TestFunction', { + code: cloudfront.FunctionCode.fromInline('code'), + keyValueStores: [store, store2], +}); + +new IntegTest(app, 'FunctionKeyValueStoreAssocation', { + testCases: [stack], +}); + +app.synth(); diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts index 71b874adb1934..99f235facfeb6 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts @@ -1,6 +1,7 @@ import * as fs from 'fs'; import { Construct } from 'constructs'; import { CfnFunction } from './cloudfront.generated'; +import { IKeyValueStore } from './key-value-store'; import { IResource, Names, Resource, Stack } from '../../core'; /** @@ -132,9 +133,19 @@ export interface FunctionProps { /** * The runtime environment for the function. - * @default FunctionRuntime.JS_1_0 + * @default FunctionRuntime.JS_1_0 (unless `keyValueStore` is specified, then `FunctionRuntime.JS_2_0`) */ readonly runtime?: FunctionRuntime; + + /** + * The Key Value Store(s) to associate with this function. + * + * In order to associate a Key Value Store, the `runtime` must be + * `cloudfront-js-2.0` or newer. + * + * @default no key value store is associated + */ + readonly keyValueStores?: IKeyValueStore[]; } /** @@ -179,7 +190,14 @@ export class Function extends Resource implements IFunction { this.functionName = props.functionName ?? this.generateName(); - this.functionRuntime = props.runtime?.value ?? FunctionRuntime.JS_1_0.value; + const defaultFunctionRuntime = props.keyValueStores?.length ? FunctionRuntime.JS_2_0.value : FunctionRuntime.JS_1_0.value; + this.functionRuntime = props.runtime?.value ?? defaultFunctionRuntime; + + if (props.keyValueStores?.length && this.functionRuntime === FunctionRuntime.JS_1_0.value) { + throw new Error( + `Key Value Stores cannot be associated to functions using the ${this.functionRuntime} runtime`, + ); + } const resource = new CfnFunction(this, 'Resource', { autoPublish: true, @@ -187,6 +205,7 @@ export class Function extends Resource implements IFunction { functionConfig: { comment: props.comment ?? this.functionName, runtime: this.functionRuntime, + keyValueStoreAssociations: this.buildKeyValueStoreProperties(props), }, name: this.functionName, }); @@ -202,6 +221,14 @@ export class Function extends Resource implements IFunction { } return name; } + + private buildKeyValueStoreProperties(props: FunctionProps): CfnFunction.KeyValueStoreAssociationProperty[] | undefined { + if (!props.keyValueStores?.length) { + return undefined; + } + + return props.keyValueStores.map(({ keyValueStoreArn }) => ({ keyValueStoreArn })); + } } /** diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts index 142559b07ea7c..4123424e25dde 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts @@ -1,7 +1,7 @@ import * as path from 'path'; -import { Template } from '../../assertions'; +import { Template, Match } from '../../assertions'; import { App, Stack } from '../../core'; -import { Function, FunctionCode, FunctionRuntime } from '../lib'; +import { Function, FunctionCode, FunctionRuntime, KeyValueStore } from '../lib'; describe('CloudFront Function', () => { @@ -188,4 +188,109 @@ describe('CloudFront Function', () => { }, }); }); + + describe('key value store association', () => { + test('minimal example', () => { + const stack = new Stack(); + const keyValueStore = new KeyValueStore(stack, 'TestStore'); + + new Function(stack, 'TestFn', { + code: FunctionCode.fromInline('code'), + keyValueStores: [keyValueStore], + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { + FunctionConfig: { + Runtime: 'cloudfront-js-2.0', + KeyValueStoreAssociations: [{ + KeyValueStoreARN: stack.resolve(keyValueStore.keyValueStoreArn), + }], + }, + }); + }); + + test('rejects key value store with v1.0 runtime', () => { + const stack = new Stack(); + const keyValueStore = new KeyValueStore(stack, 'TestStore'); + + expect(() => new Function(stack, 'TestFn', { + code: FunctionCode.fromInline('code'), + keyValueStores: [keyValueStore], + runtime: FunctionRuntime.JS_1_0, + })).toThrow(/Key Value Stores cannot be associated to functions using the .* runtime/); + }); + + test('defaults to js-2.0 runtime with key value store', () => { + const stack = new Stack(); + const keyValueStore = new KeyValueStore(stack, 'TestStore'); + + new Function(stack, 'TestFn', { + code: FunctionCode.fromInline('code'), + keyValueStores: [keyValueStore], + runtime: undefined, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { + FunctionConfig: { + Runtime: 'cloudfront-js-2.0', + }, + }); + }); + + test('works with js-2.0 runtime specified', () => { + const stack = new Stack(); + const keyValueStore = new KeyValueStore(stack, 'TestStore'); + + new Function(stack, 'TestFn', { + code: FunctionCode.fromInline('code'), + keyValueStores: [keyValueStore], + runtime: FunctionRuntime.JS_2_0, + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { + FunctionConfig: { + Runtime: 'cloudfront-js-2.0', + KeyValueStoreAssociations: [{ + KeyValueStoreARN: stack.resolve(keyValueStore.keyValueStoreArn), + }], + }, + }); + }); + + test('empty list is equivalent to not specifying', () => { + const stack = new Stack(); + + new Function(stack, 'TestFn', { + code: FunctionCode.fromInline('code'), + runtime: FunctionRuntime.JS_2_0, + keyValueStores: [], + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { + FunctionConfig: { + KeyValueStoreAssociations: Match.absent(), + }, + }); + }); + + test('multiple key value stores can be specified', () => { + const stack = new Stack(); + const store1 = new KeyValueStore(stack, 'TestStore1'); + const store2 = new KeyValueStore(stack, 'TestStore2'); + + new Function(stack, 'TestFn', { + code: FunctionCode.fromInline('code'), + keyValueStores: [store1, store2], + }); + + Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { + FunctionConfig: { + KeyValueStoreAssociations: [ + { KeyValueStoreARN: stack.resolve(store1.keyValueStoreArn) }, + { KeyValueStoreARN: stack.resolve(store2.keyValueStoreArn) }, + ], + }, + }); + }); + }); }); From c4c136d33761b281e546bcafe32de230b1166e72 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Wed, 3 Jan 2024 21:01:10 -0500 Subject: [PATCH 2/7] Update README for function association --- packages/aws-cdk-lib/aws-cloudfront/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/aws-cdk-lib/aws-cloudfront/README.md b/packages/aws-cdk-lib/aws-cloudfront/README.md index 333367b4ec176..b1a976113380e 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/README.md +++ b/packages/aws-cdk-lib/aws-cloudfront/README.md @@ -558,6 +558,19 @@ const store = new cloudfront.KeyValueStore(this, 'KeyValueStore', { }); ``` +The Key Value Store can then be associated to a function using the `cloudfront-js-2.0` runtime +or newer: + +```ts +const store = new cloudfront.KeyValueStore(this, 'KeyValueStore'); +new cloudfront.Function(this, 'Function', { + code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'), + // Note that JS_2_0 must be used for Key Value Store support + runtime: cloudfront.FunctionRuntime.JS_2_0, + keyValueStores: [store], +}); +``` + ### Logging You can configure CloudFront to create log files that contain detailed information about every user request that CloudFront receives. From 4825740af00526a075a19a89347696e3b92343b1 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Mon, 8 Jan 2024 17:44:39 -0500 Subject: [PATCH 3/7] Fix linter error --- packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts index 4123424e25dde..8136ce0128085 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts @@ -259,7 +259,7 @@ describe('CloudFront Function', () => { test('empty list is equivalent to not specifying', () => { const stack = new Stack(); - + new Function(stack, 'TestFn', { code: FunctionCode.fromInline('code'), runtime: FunctionRuntime.JS_2_0, From 8728e419b9acf860f42694277b6ac57f39f64af8 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Tue, 9 Jan 2024 21:49:36 -0500 Subject: [PATCH 4/7] Allow only one associated KV store --- ...ion-key-value-store-assocation.assets.json | 4 +- ...n-key-value-store-assocation.template.json | 42 ++++--------- .../manifest.json | 8 +-- .../tree.json | 60 ++++--------------- ...eg.function-key-value-store-association.ts | 4 +- .../aws-cloudfront/lib/function.ts | 18 ++---- .../aws-cloudfront/test/function.test.ts | 32 ++-------- 7 files changed, 42 insertions(+), 126 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json index 63afcbb2a2cdc..847deb62b1dcd 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json @@ -14,7 +14,7 @@ } } }, - "8cd51bc32be5868f31c493a1b55db8768f9445c51a8aefbf2904c93e064c22f9": { + "62034410a7875b30801467b3919077211d42e469b115e1449c5e0687e72866d3": { "source": { "path": "integ-function-key-value-store-assocation.template.json", "packaging": "file" @@ -22,7 +22,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "8cd51bc32be5868f31c493a1b55db8768f9445c51a8aefbf2904c93e064c22f9.json", + "objectKey": "62034410a7875b30801467b3919077211d42e469b115e1449c5e0687e72866d3.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json index 144bb883abf9f..957702e094787 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json @@ -26,42 +26,26 @@ "Name": "integfunctionkeyvaluestoreassocationTestKeyValueStoreAA209C02" } }, - "TestKeyValueStore25F61F0F5": { - "Type": "AWS::CloudFront::KeyValueStore", - "Properties": { - "Name": "integfunctionkeyvaluestoreassocationTestKeyValueStore2A09DC08D" - } - }, "TestFunction22AD90FC": { "Type": "AWS::CloudFront::Function", "Properties": { "AutoPublish": true, "FunctionCode": "code", "FunctionConfig": { - "Comment": { - "Fn::Join": [ - "", - [ - { - "Ref": "AWS::Region" - }, - "integfunctreassocationTestFunctionEC38B947" - ] - ] - }, - "Runtime": "cloudfront-js-1.0" + "Comment": "TestKvFunction", + "KeyValueStoreAssociations": [ + { + "KeyValueStoreARN": { + "Fn::GetAtt": [ + "TestKeyValueStore8D0C09A2", + "Arn" + ] + } + } + ], + "Runtime": "cloudfront-js-2.0" }, - "Name": { - "Fn::Join": [ - "", - [ - { - "Ref": "AWS::Region" - }, - "integfunctreassocationTestFunctionEC38B947" - ] - ] - } + "Name": "TestKvFunction" } } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json index 429ef4bacd476..ba391730c6a9d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/8cd51bc32be5868f31c493a1b55db8768f9445c51a8aefbf2904c93e064c22f9.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/62034410a7875b30801467b3919077211d42e469b115e1449c5e0687e72866d3.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -40,12 +40,6 @@ "data": "TestKeyValueStore8D0C09A2" } ], - "/integ-function-key-value-store-assocation/TestKeyValueStore2/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "TestKeyValueStore25F61F0F5" - } - ], "/integ-function-key-value-store-assocation/TestFunction/Resource": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json index 9b7f99dd53a89..e27bf43872061 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json @@ -78,30 +78,6 @@ "version": "0.0.0" } }, - "TestKeyValueStore2": { - "id": "TestKeyValueStore2", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore2", - "children": { - "Resource": { - "id": "Resource", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore2/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::CloudFront::KeyValueStore", - "aws:cdk:cloudformation:props": { - "name": "integfunctionkeyvaluestoreassocationTestKeyValueStore2A09DC08D" - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudfront.CfnKeyValueStore", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_cloudfront.KeyValueStore", - "version": "0.0.0" - } - }, "TestFunction": { "id": "TestFunction", "path": "integ-function-key-value-store-assocation/TestFunction", @@ -115,30 +91,20 @@ "autoPublish": true, "functionCode": "code", "functionConfig": { - "comment": { - "Fn::Join": [ - "", - [ - { - "Ref": "AWS::Region" - }, - "integfunctreassocationTestFunctionEC38B947" - ] - ] - }, - "runtime": "cloudfront-js-1.0" - }, - "name": { - "Fn::Join": [ - "", - [ - { - "Ref": "AWS::Region" - }, - "integfunctreassocationTestFunctionEC38B947" - ] + "comment": "TestKvFunction", + "runtime": "cloudfront-js-2.0", + "keyValueStoreAssociations": [ + { + "keyValueStoreArn": { + "Fn::GetAtt": [ + "TestKeyValueStore8D0C09A2", + "Arn" + ] + } + } ] - } + }, + "name": "TestKvFunction" } }, "constructInfo": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts index 3d33b7e792983..8cbf6cbcd281d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts @@ -10,10 +10,10 @@ const store = new cloudfront.KeyValueStore(stack, 'TestKeyValueStore', { comment: 'A test Key Value Store for CloudFront', source: cloudfront.ImportSource.fromAsset(path.join(__dirname, 'test-import-source.json')), }); -const store2 = new cloudfront.KeyValueStore(stack, 'TestKeyValueStore2'); new cloudfront.Function(stack, 'TestFunction', { + functionName: 'TestKvFunction', code: cloudfront.FunctionCode.fromInline('code'), - keyValueStores: [store, store2], + keyValueStore: store, }); new IntegTest(app, 'FunctionKeyValueStoreAssocation', { diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts index 99f235facfeb6..23f33b9367aab 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts @@ -138,14 +138,14 @@ export interface FunctionProps { readonly runtime?: FunctionRuntime; /** - * The Key Value Store(s) to associate with this function. + * The Key Value Store to associate with this function. * * In order to associate a Key Value Store, the `runtime` must be * `cloudfront-js-2.0` or newer. * * @default no key value store is associated */ - readonly keyValueStores?: IKeyValueStore[]; + readonly keyValueStore?: IKeyValueStore; } /** @@ -190,10 +190,10 @@ export class Function extends Resource implements IFunction { this.functionName = props.functionName ?? this.generateName(); - const defaultFunctionRuntime = props.keyValueStores?.length ? FunctionRuntime.JS_2_0.value : FunctionRuntime.JS_1_0.value; + const defaultFunctionRuntime = props.keyValueStore ? FunctionRuntime.JS_2_0.value : FunctionRuntime.JS_1_0.value; this.functionRuntime = props.runtime?.value ?? defaultFunctionRuntime; - if (props.keyValueStores?.length && this.functionRuntime === FunctionRuntime.JS_1_0.value) { + if (props.keyValueStore && this.functionRuntime === FunctionRuntime.JS_1_0.value) { throw new Error( `Key Value Stores cannot be associated to functions using the ${this.functionRuntime} runtime`, ); @@ -205,7 +205,7 @@ export class Function extends Resource implements IFunction { functionConfig: { comment: props.comment ?? this.functionName, runtime: this.functionRuntime, - keyValueStoreAssociations: this.buildKeyValueStoreProperties(props), + keyValueStoreAssociations: props.keyValueStore ? [{ keyValueStoreArn: props.keyValueStore?.keyValueStoreArn }] : undefined, }, name: this.functionName, }); @@ -221,14 +221,6 @@ export class Function extends Resource implements IFunction { } return name; } - - private buildKeyValueStoreProperties(props: FunctionProps): CfnFunction.KeyValueStoreAssociationProperty[] | undefined { - if (!props.keyValueStores?.length) { - return undefined; - } - - return props.keyValueStores.map(({ keyValueStoreArn }) => ({ keyValueStoreArn })); - } } /** diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts index 8136ce0128085..7c48d9528dce2 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts @@ -196,7 +196,7 @@ describe('CloudFront Function', () => { new Function(stack, 'TestFn', { code: FunctionCode.fromInline('code'), - keyValueStores: [keyValueStore], + keyValueStore, }); Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { @@ -215,8 +215,8 @@ describe('CloudFront Function', () => { expect(() => new Function(stack, 'TestFn', { code: FunctionCode.fromInline('code'), - keyValueStores: [keyValueStore], runtime: FunctionRuntime.JS_1_0, + keyValueStore, })).toThrow(/Key Value Stores cannot be associated to functions using the .* runtime/); }); @@ -226,8 +226,8 @@ describe('CloudFront Function', () => { new Function(stack, 'TestFn', { code: FunctionCode.fromInline('code'), - keyValueStores: [keyValueStore], runtime: undefined, + keyValueStore, }); Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { @@ -243,8 +243,8 @@ describe('CloudFront Function', () => { new Function(stack, 'TestFn', { code: FunctionCode.fromInline('code'), - keyValueStores: [keyValueStore], runtime: FunctionRuntime.JS_2_0, + keyValueStore, }); Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { @@ -257,13 +257,13 @@ describe('CloudFront Function', () => { }); }); - test('empty list is equivalent to not specifying', () => { + test('no value is used in CloudFormation when unspecified in CDK', () => { const stack = new Stack(); new Function(stack, 'TestFn', { code: FunctionCode.fromInline('code'), runtime: FunctionRuntime.JS_2_0, - keyValueStores: [], + keyValueStore: undefined, }); Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { @@ -272,25 +272,5 @@ describe('CloudFront Function', () => { }, }); }); - - test('multiple key value stores can be specified', () => { - const stack = new Stack(); - const store1 = new KeyValueStore(stack, 'TestStore1'); - const store2 = new KeyValueStore(stack, 'TestStore2'); - - new Function(stack, 'TestFn', { - code: FunctionCode.fromInline('code'), - keyValueStores: [store1, store2], - }); - - Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { - FunctionConfig: { - KeyValueStoreAssociations: [ - { KeyValueStoreARN: stack.resolve(store1.keyValueStoreArn) }, - { KeyValueStoreARN: stack.resolve(store2.keyValueStoreArn) }, - ], - }, - }); - }); }); }); From 3552f4a903b06d7386038baae1d57330c16de861 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Tue, 9 Jan 2024 22:41:16 -0500 Subject: [PATCH 5/7] Update README.md --- packages/aws-cdk-lib/aws-cloudfront/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-cloudfront/README.md b/packages/aws-cdk-lib/aws-cloudfront/README.md index b1a976113380e..6c9aa2d3a461c 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/README.md +++ b/packages/aws-cdk-lib/aws-cloudfront/README.md @@ -567,7 +567,7 @@ new cloudfront.Function(this, 'Function', { code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'), // Note that JS_2_0 must be used for Key Value Store support runtime: cloudfront.FunctionRuntime.JS_2_0, - keyValueStores: [store], + keyValueStore: store, }); ``` From d2206508bcf0507ff7a2cce76aa9ef1fc8edf117 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Sun, 21 Jan 2024 13:07:24 -0500 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: k.goto <24818752+go-to-k@users.noreply.github.com> --- .../aws-cdk-lib/aws-cloudfront/lib/function.ts | 4 ++-- .../aws-cloudfront/test/function.test.ts | 17 ----------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts index 23f33b9367aab..bdf72350b689e 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts @@ -143,7 +143,7 @@ export interface FunctionProps { * In order to associate a Key Value Store, the `runtime` must be * `cloudfront-js-2.0` or newer. * - * @default no key value store is associated + * @default - no key value store is associated */ readonly keyValueStore?: IKeyValueStore; } @@ -205,7 +205,7 @@ export class Function extends Resource implements IFunction { functionConfig: { comment: props.comment ?? this.functionName, runtime: this.functionRuntime, - keyValueStoreAssociations: props.keyValueStore ? [{ keyValueStoreArn: props.keyValueStore?.keyValueStoreArn }] : undefined, + keyValueStoreAssociations: props.keyValueStore ? [{ keyValueStoreArn: props.keyValueStore.keyValueStoreArn }] : undefined, }, name: this.functionName, }); diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts index 7c48d9528dce2..5e17a59362535 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts @@ -220,23 +220,6 @@ describe('CloudFront Function', () => { })).toThrow(/Key Value Stores cannot be associated to functions using the .* runtime/); }); - test('defaults to js-2.0 runtime with key value store', () => { - const stack = new Stack(); - const keyValueStore = new KeyValueStore(stack, 'TestStore'); - - new Function(stack, 'TestFn', { - code: FunctionCode.fromInline('code'), - runtime: undefined, - keyValueStore, - }); - - Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', { - FunctionConfig: { - Runtime: 'cloudfront-js-2.0', - }, - }); - }); - test('works with js-2.0 runtime specified', () => { const stack = new Stack(); const keyValueStore = new KeyValueStore(stack, 'TestStore'); From 7cb1d9695d9a7c6d62465409528772fb8a37dc74 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Tue, 23 Jan 2024 20:32:04 -0500 Subject: [PATCH 7/7] Fix typo in integ stack name --- ...faultTestDeployAssert986D766D.assets.json} | 2 +- ...ultTestDeployAssert986D766D.template.json} | 0 ...n-key-value-store-association.assets.json} | 6 +-- ...key-value-store-association.template.json} | 2 +- .../integ.json | 8 ++-- .../manifest.json | 42 +++++++++---------- .../tree.json | 42 +++++++++---------- ...eg.function-key-value-store-association.ts | 4 +- 8 files changed, 53 insertions(+), 53 deletions(-) rename packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/{FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json => FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets.json} (86%) rename packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/{FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json => FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.template.json} (100%) rename packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/{integ-function-key-value-store-assocation.assets.json => integ-function-key-value-store-association.assets.json} (81%) rename packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/{integ-function-key-value-store-assocation.template.json => integ-function-key-value-store-association.template.json} (95%) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets.json similarity index 86% rename from packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets.json index eb7a96fb24cea..3720ef61a8e2c 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets.json @@ -3,7 +3,7 @@ "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { - "path": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json", + "path": "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.template.json", "packaging": "file" }, "destinations": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.template.json similarity index 100% rename from packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.template.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json b/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 similarity index 81% rename from packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json rename to 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 index 847deb62b1dcd..78f78472e1e24 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.assets.json +++ b/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 @@ -14,15 +14,15 @@ } } }, - "62034410a7875b30801467b3919077211d42e469b115e1449c5e0687e72866d3": { + "5ab0a11edcee54ef5956720528876fb90b8a0b2b8e51c40c5bdca486bf681ba1": { "source": { - "path": "integ-function-key-value-store-assocation.template.json", + "path": "integ-function-key-value-store-association.template.json", "packaging": "file" }, "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "62034410a7875b30801467b3919077211d42e469b115e1449c5e0687e72866d3.json", + "objectKey": "5ab0a11edcee54ef5956720528876fb90b8a0b2b8e51c40c5bdca486bf681ba1.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-association.template.json similarity index 95% rename from packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-association.template.json index 957702e094787..7c57353b9fefb 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-assocation.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ-function-key-value-store-association.template.json @@ -23,7 +23,7 @@ }, "SourceType": "S3" }, - "Name": "integfunctionkeyvaluestoreassocationTestKeyValueStoreAA209C02" + "Name": "integfunctionkeyvaluestoreassociationTestKeyValueStoreA8304A36" } }, "TestFunction22AD90FC": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json index 667a3fe038ebb..156ca2a1a40d2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/integ.json @@ -1,12 +1,12 @@ { "version": "36.0.0", "testCases": { - "FunctionKeyValueStoreAssocation/DefaultTest": { + "FunctionKeyValueStoreAssociation/DefaultTest": { "stacks": [ - "integ-function-key-value-store-assocation" + "integ-function-key-value-store-association" ], - "assertionStack": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert", - "assertionStackName": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04" + "assertionStack": "FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert", + "assertionStackName": "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D" } } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json index ba391730c6a9d..2a4dd6b9a9353 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/manifest.json @@ -1,28 +1,28 @@ { "version": "36.0.0", "artifacts": { - "integ-function-key-value-store-assocation.assets": { + "integ-function-key-value-store-association.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "integ-function-key-value-store-assocation.assets.json", + "file": "integ-function-key-value-store-association.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "integ-function-key-value-store-assocation": { + "integ-function-key-value-store-association": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "integ-function-key-value-store-assocation.template.json", + "templateFile": "integ-function-key-value-store-association.template.json", "terminationProtection": false, "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/62034410a7875b30801467b3919077211d42e469b115e1449c5e0687e72866d3.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5ab0a11edcee54ef5956720528876fb90b8a0b2b8e51c40c5bdca486bf681ba1.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "integ-function-key-value-store-assocation.assets" + "integ-function-key-value-store-association.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", @@ -31,49 +31,49 @@ } }, "dependencies": [ - "integ-function-key-value-store-assocation.assets" + "integ-function-key-value-store-association.assets" ], "metadata": { - "/integ-function-key-value-store-assocation/TestKeyValueStore/Resource": [ + "/integ-function-key-value-store-association/TestKeyValueStore/Resource": [ { "type": "aws:cdk:logicalId", "data": "TestKeyValueStore8D0C09A2" } ], - "/integ-function-key-value-store-assocation/TestFunction/Resource": [ + "/integ-function-key-value-store-association/TestFunction/Resource": [ { "type": "aws:cdk:logicalId", "data": "TestFunction22AD90FC" } ], - "/integ-function-key-value-store-assocation/BootstrapVersion": [ + "/integ-function-key-value-store-association/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/integ-function-key-value-store-assocation/CheckBootstrapVersion": [ + "/integ-function-key-value-store-association/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "integ-function-key-value-store-assocation" + "displayName": "integ-function-key-value-store-association" }, - "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets": { + "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets.json", + "file": "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04": { + "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.template.json", + "templateFile": "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.template.json", "terminationProtection": false, "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", @@ -82,7 +82,7 @@ "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets" + "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", @@ -91,23 +91,23 @@ } }, "dependencies": [ - "FunctionKeyValueStoreAssocationDefaultTestDeployAssert1F41BE04.assets" + "FunctionKeyValueStoreAssociationDefaultTestDeployAssert986D766D.assets" ], "metadata": { - "/FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/BootstrapVersion": [ + "/FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + "/FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert" + "displayName": "FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert" }, "Tree": { "type": "cdk:tree", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json index e27bf43872061..dd3459c6f09c3 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.js.snapshot/tree.json @@ -4,21 +4,21 @@ "id": "App", "path": "", "children": { - "integ-function-key-value-store-assocation": { - "id": "integ-function-key-value-store-assocation", - "path": "integ-function-key-value-store-assocation", + "integ-function-key-value-store-association": { + "id": "integ-function-key-value-store-association", + "path": "integ-function-key-value-store-association", "children": { "TestKeyValueStore": { "id": "TestKeyValueStore", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore", + "path": "integ-function-key-value-store-association/TestKeyValueStore", "children": { "ImportSource": { "id": "ImportSource", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore/ImportSource", + "path": "integ-function-key-value-store-association/TestKeyValueStore/ImportSource", "children": { "Stage": { "id": "Stage", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore/ImportSource/Stage", + "path": "integ-function-key-value-store-association/TestKeyValueStore/ImportSource/Stage", "constructInfo": { "fqn": "aws-cdk-lib.AssetStaging", "version": "0.0.0" @@ -26,7 +26,7 @@ }, "AssetBucket": { "id": "AssetBucket", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore/ImportSource/AssetBucket", + "path": "integ-function-key-value-store-association/TestKeyValueStore/ImportSource/AssetBucket", "constructInfo": { "fqn": "aws-cdk-lib.aws_s3.BucketBase", "version": "0.0.0" @@ -40,7 +40,7 @@ }, "Resource": { "id": "Resource", - "path": "integ-function-key-value-store-assocation/TestKeyValueStore/Resource", + "path": "integ-function-key-value-store-association/TestKeyValueStore/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::CloudFront::KeyValueStore", "aws:cdk:cloudformation:props": { @@ -64,7 +64,7 @@ ] } }, - "name": "integfunctionkeyvaluestoreassocationTestKeyValueStoreAA209C02" + "name": "integfunctionkeyvaluestoreassociationTestKeyValueStoreA8304A36" } }, "constructInfo": { @@ -80,11 +80,11 @@ }, "TestFunction": { "id": "TestFunction", - "path": "integ-function-key-value-store-assocation/TestFunction", + "path": "integ-function-key-value-store-association/TestFunction", "children": { "Resource": { "id": "Resource", - "path": "integ-function-key-value-store-assocation/TestFunction/Resource", + "path": "integ-function-key-value-store-association/TestFunction/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::CloudFront::Function", "aws:cdk:cloudformation:props": { @@ -120,7 +120,7 @@ }, "BootstrapVersion": { "id": "BootstrapVersion", - "path": "integ-function-key-value-store-assocation/BootstrapVersion", + "path": "integ-function-key-value-store-association/BootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" @@ -128,7 +128,7 @@ }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", - "path": "integ-function-key-value-store-assocation/CheckBootstrapVersion", + "path": "integ-function-key-value-store-association/CheckBootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" @@ -140,17 +140,17 @@ "version": "0.0.0" } }, - "FunctionKeyValueStoreAssocation": { - "id": "FunctionKeyValueStoreAssocation", - "path": "FunctionKeyValueStoreAssocation", + "FunctionKeyValueStoreAssociation": { + "id": "FunctionKeyValueStoreAssociation", + "path": "FunctionKeyValueStoreAssociation", "children": { "DefaultTest": { "id": "DefaultTest", - "path": "FunctionKeyValueStoreAssocation/DefaultTest", + "path": "FunctionKeyValueStoreAssociation/DefaultTest", "children": { "Default": { "id": "Default", - "path": "FunctionKeyValueStoreAssocation/DefaultTest/Default", + "path": "FunctionKeyValueStoreAssociation/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0" @@ -158,11 +158,11 @@ }, "DeployAssert": { "id": "DeployAssert", - "path": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert", + "path": "FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert", "children": { "BootstrapVersion": { "id": "BootstrapVersion", - "path": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/BootstrapVersion", + "path": "FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" @@ -170,7 +170,7 @@ }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", - "path": "FunctionKeyValueStoreAssocation/DefaultTest/DeployAssert/CheckBootstrapVersion", + "path": "FunctionKeyValueStoreAssociation/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts index 8cbf6cbcd281d..b11a3cc47c131 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.function-key-value-store-association.ts @@ -4,7 +4,7 @@ import { IntegTest } from '@aws-cdk/integ-tests-alpha'; import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; const app = new cdk.App(); -const stack = new cdk.Stack(app, 'integ-function-key-value-store-assocation'); +const stack = new cdk.Stack(app, 'integ-function-key-value-store-association'); const store = new cloudfront.KeyValueStore(stack, 'TestKeyValueStore', { comment: 'A test Key Value Store for CloudFront', @@ -16,7 +16,7 @@ new cloudfront.Function(stack, 'TestFunction', { keyValueStore: store, }); -new IntegTest(app, 'FunctionKeyValueStoreAssocation', { +new IntegTest(app, 'FunctionKeyValueStoreAssociation', { testCases: [stack], });