[{"data":1,"prerenderedAt":81},["ShallowReactive",2],{"pattern-cloudfront-keyvaluestore-apigw-routing-cdk":3},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":10,"deploy":12,"description":18,"extension":19,"framework":20,"gitHub":21,"highlight":6,"introBox":27,"language":34,"level":35,"meta":36,"patternArch":37,"resources":61,"s3URL":6,"services":6,"stem":72,"testing":73,"videoId":6,"__hash__":80},"patterns\u002Fpatterns\u002Fcloudfront-keyvaluestore-apigw-routing-cdk.json","Amazon CloudFront with Amazon API Gateway Routing using Key Value Store",null,{"text":8},[9],"Delete the stack: \u003Ccode>cdk destroy\u003C\u002Fcode>",[11],"content\u002Fcontributors\u002Fmarco-jahn.json",{"text":13},[14,15,16,17],"Clone the repository: \u003Ccode>git clone https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u003C\u002Fcode>","Change directory: \u003Ccode>cd cloudfront-keyvaluestore-apigw-routing-cdk\u003C\u002Fcode>","Install dependencies: \u003Ccode>npm install\u003C\u002Fcode>","Deploy the CDK stack: \u003Ccode>cdk deploy\u003C\u002Fcode>","Route traffic dynamically between API Gateway endpoints using CloudFront Functions and Key Value Store without redeploying infrastructure.","json","AWS CDK",{"template":22},{"repoURL":23,"templateURL":24,"projectFolder":25,"templateFile":26},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u002Ftree\u002Fmain\u002Fcloudfront-keyvaluestore-apigw-routing-cdk","serverless-patterns\u002Fcloudfront-keyvaluestore-apigw-routing-cdk","cloudfront-keyvaluestore-apigw-routing-cdk","lib\u002Fpattern-stack.ts",{"headline":28,"text":29},"How it works",[30,31,32,33],"This pattern demonstrates how to use Amazon CloudFront with CloudFront Functions to dynamically route traffic between multiple Amazon API Gateway endpoints.","The routing decisions are based on values stored in CloudFront Key Value Store, allowing for flexible, configuration-driven request routing without redeploying your infrastructure.","This example uses an equal (50:50 distribution) between both API Gateways, showcasing how to implement cell partitioning for your applications.","The pattern deploys a CloudFront distribution, CloudFront Function, CloudFront Key Value Store, and two API Gateway endpoints.","TypeScript","300",{},{"icon1":38,"icon2":43,"icon3":46,"icon4":50,"line1":53,"line2":57,"line3":59},{"x":39,"y":40,"service":41,"label":42},20,50,"cloudfront","Amazon CloudFront",{"x":40,"y":40,"service":44,"label":45},"cf-functions","CloudFront function",{"x":47,"y":39,"service":48,"label":49},80,"apigw","Amazon API Gateway 1",{"x":47,"y":51,"service":48,"label":52},70,"Amazon API Gateway 2",{"from":54,"to":55,"label":56},"icon1","icon2","",{"from":55,"to":58,"label":56},"icon3",{"from":55,"to":60,"label":56},"icon4",{"bullets":62},[63,66,69],{"text":64,"link":65},"AWS Well-Architected Guide - Cell Partition","https:\u002F\u002Fdocs.aws.amazon.com\u002Fwellarchitected\u002Flatest\u002Freducing-scope-of-impact-with-cell-based-architecture\u002Fcell-partition.html",{"text":67,"link":68},"CloudFront Key Value Store Documentation","https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonCloudFront\u002Flatest\u002FDeveloperGuide\u002Fkvs-with-functions.html",{"text":70,"link":71},"CloudFront Functions Documentation","https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonCloudFront\u002Flatest\u002FDeveloperGuide\u002Fcloudfront-functions.html","patterns\u002Fcloudfront-keyvaluestore-apigw-routing-cdk",{"text":74},[75,76,77,78,79],"1. Get Key Value Store ETAG: \u003Ccode>aws cloudfront-keyvaluestore describe-key-value-store --kvs-arn=[KVSTOREARN]\u003C\u002Fcode>","2. Add entries to the Key Value Store: \u003Ccode>aws cloudfront-keyvaluestore update-keys --kvs-arn=[KVSTOREARN] --if-match=[ETAG] --puts '[{\"Key\": \"APIGW1URL\", \"Value\": \"[APIGATEWAY1URL]\"},{\"Key\": \"APIGW2URL\", \"Value\": \"[APIGATEWAY2URL]\"}]'\u003C\u002Fcode>","3. Access CloudFront URL: \u003Ccode>curl -i -L [CLOUDFRONTDOMAINNAME]\u003C\u002Fcode>","4. The request should be redirected to either API Gateway 1 or API Gateway 2, showing a response like \u003Ccode>{\"message\": \"Hello from API 1\"}\u003C\u002Fcode> or \u003Ccode>{\"message\": \"Hello from API 2\"}\u003C\u002Fcode>","5. Make multiple requests to observe routing between the two API Gateway endpoints.","OjyTPGWUifzwDaYqU9ZjvBOBvo-sqyBQxKoY19xdKIc",1780514997258]