|
| 1 | +{ |
| 2 | + "title": "Amazon CloudFront with API Gateway Routing using Key Value Store", |
| 3 | + "description": "Route traffic dynamically between API Gateway endpoints using CloudFront Functions and Key Value Store without redeploying infrastructure.", |
| 4 | + "language": "TypeScript", |
| 5 | + "level": "300", |
| 6 | + "framework": "AWS CDK", |
| 7 | + "introBox": { |
| 8 | + "headline": "How it works", |
| 9 | + "text": [ |
| 10 | + "This pattern demonstrates how to use Amazon CloudFront with CloudFront Functions to dynamically route traffic between multiple Amazon API Gateway endpoints.", |
| 11 | + "The routing decisions are based on values stored in CloudFront Key Value Store, allowing for flexible, configuration-driven request routing without redeploying your infrastructure.", |
| 12 | + "This example uses an equal (50:50 distribution) between both API Gateways, showcasing how to implement cell partitioning for your applications.", |
| 13 | + "The pattern deploys a CloudFront distribution, CloudFront Function, CloudFront Key Value Store, and two API Gateway endpoints." |
| 14 | + ] |
| 15 | + }, |
| 16 | + "gitHub": { |
| 17 | + "template": { |
| 18 | + "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/cloudfront-keyvaluestore-apigw-routing-cdk", |
| 19 | + "templateURL": "serverless-patterns/cloudfront-keyvaluestore-apigw-routing-cdk", |
| 20 | + "projectFolder": "cloudfront-keyvaluestore-apigw-routing-cdk", |
| 21 | + "templateFile": "lib/pattern-stack.ts" |
| 22 | + } |
| 23 | + }, |
| 24 | + "resources": { |
| 25 | + "bullets": [ |
| 26 | + { |
| 27 | + "text": "AWS Well-Architected Guide - Cell Partition", |
| 28 | + "link": "https://docs.aws.amazon.com/wellarchitected/latest/reducing-scope-of-impact-with-cell-based-architecture/cell-partition.html" |
| 29 | + }, |
| 30 | + { |
| 31 | + "text": "CloudFront Key Value Store Documentation", |
| 32 | + "link": "https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/kvs-with-functions.html" |
| 33 | + }, |
| 34 | + { |
| 35 | + "text": "CloudFront Functions Documentation", |
| 36 | + "link": "https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-functions.html" |
| 37 | + } |
| 38 | + ] |
| 39 | + }, |
| 40 | + "deploy": { |
| 41 | + "text": [ |
| 42 | + "Clone the repository: <code>git clone https://github.com/aws-samples/serverless-patterns</code>", |
| 43 | + "Change directory: <code>cd cloudfront-keyvaluestore-apigw-routing-cdk</code>", |
| 44 | + "Install dependencies: <code>npm install</code>", |
| 45 | + "Deploy the CDK stack: <code>cdk deploy</code>" |
| 46 | + ] |
| 47 | + }, |
| 48 | + "testing": { |
| 49 | + "text": [ |
| 50 | + "1. Get Key Value Store ETAG: <code>aws cloudfront-keyvaluestore describe-key-value-store --kvs-arn=[KVSTOREARN]</code>", |
| 51 | + "2. Add entries to the Key Value Store: <code>aws cloudfront-keyvaluestore update-keys --kvs-arn=[KVSTOREARN] --if-match=[ETAG] --puts '[{\"Key\": \"APIGW1URL\", \"Value\": \"[APIGATEWAY1URL]\"},{\"Key\": \"APIGW2URL\", \"Value\": \"[APIGATEWAY2URL]\"}]'</code>", |
| 52 | + "3. Access CloudFront URL: <code>curl -i -L [CLOUDFRONTDOMAINNAME]</code>", |
| 53 | + "4. The request should be redirected to either API Gateway 1 or API Gateway 2, showing a response like <code>{\"message\": \"Hello from API 1\"}</code> or <code>{\"message\": \"Hello from API 2\"}</code>", |
| 54 | + "5. Make multiple requests to observe routing between the two API Gateway endpoints." |
| 55 | + ] |
| 56 | + }, |
| 57 | + "cleanup": { |
| 58 | + "text": [ |
| 59 | + "Delete the stack: <code>cdk destroy</code>" |
| 60 | + ] |
| 61 | + }, |
| 62 | + "authors": [ |
| 63 | + { |
| 64 | + "name": "Marco Jahn", |
| 65 | + "image": "https://sessionize.com/image/e99b-400o400o2-pqR4BacUSzHrq4fgZ4wwEQ.png", |
| 66 | + "bio": "Senior Solutions Architect, Amazon Web Services", |
| 67 | + "linkedin": "marcojahn" |
| 68 | + } |
| 69 | + ], |
| 70 | + "patternArch": { |
| 71 | + "icon1": { |
| 72 | + "x": 20, |
| 73 | + "y": 50, |
| 74 | + "service": "cloudfront", |
| 75 | + "label": "Amazon CloudFront" |
| 76 | + }, |
| 77 | + "icon2": { |
| 78 | + "x": 50, |
| 79 | + "y": 50, |
| 80 | + "service": "cf-functions", |
| 81 | + "label": "CloudFront function" |
| 82 | + }, |
| 83 | + "icon3": { |
| 84 | + "x": 80, |
| 85 | + "y": 20, |
| 86 | + "service": "apigw", |
| 87 | + "label": "Amazon API Gateway 1" |
| 88 | + }, |
| 89 | + "icon4": { |
| 90 | + "x": 80, |
| 91 | + "y": 70, |
| 92 | + "service": "apigw", |
| 93 | + "label": "Amazon API Gateway 2" |
| 94 | + }, |
| 95 | + "line1": { |
| 96 | + "from": "icon1", |
| 97 | + "to": "icon2", |
| 98 | + "label": "" |
| 99 | + }, |
| 100 | + "line2": { |
| 101 | + "from": "icon2", |
| 102 | + "to": "icon3", |
| 103 | + "label": "" |
| 104 | + }, |
| 105 | + "line3": { |
| 106 | + "from": "icon2", |
| 107 | + "to": "icon4", |
| 108 | + "label": "" |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments