Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebsto/tictactoe-cdk
CDK script for a multi region deployment of the TicTacToe game (available at https://github.com/sebsto/tictactoe-dynamodb)
https://github.com/sebsto/tictactoe-cdk
Last synced: 6 days ago
JSON representation
CDK script for a multi region deployment of the TicTacToe game (available at https://github.com/sebsto/tictactoe-dynamodb)
- Host: GitHub
- URL: https://github.com/sebsto/tictactoe-cdk
- Owner: sebsto
- License: mit-0
- Created: 2021-06-07T13:24:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-22T17:18:46.000Z (about 1 year ago)
- Last Synced: 2024-01-24T16:58:07.947Z (10 months ago)
- Language: CSS
- Size: 414 KB
- Stars: 6
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.html
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
README
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
CloudFormation templates for Amazon Route 53 Application Recovery Controller (ARC)
Overview
These three sample CloudFormation templates show you how to configure Amazon Route 53 Application Recovery Controller automatically.
The three templates are specific to the TicTacToe demo application deployed with a CDK script. For more information about AWS Cloud Development Kit, go to the AWS CDK documentation.
- The first template configures readiness checks. Readiness checks ensure that your recovery environment is scaled and configured to take over when needed.
- The second template configures routing controls and health checks. You use routing controls to rebalance traffic across application replicas during failures.
- The third template creates Route 53 DNS failover records. DNS failover records on health checks enable you to reroute traffic by using routing controls. (This template must be run after the first two.)
Prerequisites
Before you deploy the CloudFormation templates, download and deploy the TicTacToe demo application by using the supplied CDK application.
The three CloudFormation templates are located in the cloudformation
folder of the project.
Please make sure to install AWS CDK v2. The CDK scripts won't work with AWS CDK v1.
# Install CDK 2, if you haven't already done so
npm install -g aws-cdk@next
# Download the CDK script that allows to deploy the app
wget http://r53-application-recovery-controller-cfn-app-iad.s3-website-us-east-1.amazonaws.com/tictactoe-infra-cdk-arc-cfn-templates.zip
unzip tictactoe-infra-cdk-arc-cfn-templates.zip
cd tictactoe-cdk
pushd app
# first time only (one time operation)
npm install && cdk bootstrap
# deploy the app
cdk deploy --all --outputs-file ../out.json
popd
The application deployment takes ~10 minutes to complete. The database stack creation might take up to 10 minutes. You will be prompted 3 times for confirmation (y/n?), always answer y
. Three CloudFormation stacks are created :
-
TictactoeAppCdkStack-us-east-1
: the application stack deployed inus-east-1
region -
TictactoeAppCdkStack-us-west-2
: the application stack deployed inus-west-2
region -
TictactoeDatabaseCdkStack
: the database stack, deployed inus-west-2
and shared by the two application stacks.
Now that the application is deployed, you are ready to depploy the Route 53 Application Recovery Controler (ARC) CloudFormation templates.
CloudFormation input variables
The CloudFormation templates expect the following parameters:
-
AWS Regions: Regions where the TicTacToe AWS resources are deployed:us-east-1
andus-west-2
-
DNS hosted zone: Update line 7 of the 'scripts/Route53-create-dns-records.sh' script with a value that corresponds to your AWS environment -
DNS domain name: Update line 6 of the 'scripts/Route53-create-dns-records.sh' script with a value that corresponds to your AWS environment
If you don't have your own DNS domain hosted on Route53, you can still deploy the HealthCheck and Routing Control templates, but not the DNS failover healthcheck records template.
Readiness check template
The CloudFormation readiness check template is specific to the TicTacToe demo application deployed with a CDK script.
The TicTacToe CDK deployment script generates a file (out.json
) that contains the ARNs of resources that are required as input parameters for the template.
Parameters
This template takes the following parameters:
- The AWS Regions where the resources are located
- The demo application load balancers ARNs
- The demo application Auto Scaling group ARNs
- The demo application DynamoDB table ARN
To read the parameters and provide them as input to the template, I provide a shell script scripts/Route53-create-readiness-check.sh
. It reads out.json
and provides the appropriate values to the CloudFormation readiness check template.
The script deploys the stack in us-west-2
region by default. You can change this by editing line 19 (REGION=us-west-2
)
Resources
This template creates the following resources:
- 2 cells, one for each AWS Region
- 1 recovery group, for the whole application
- 3 resource sets, one each for the load balancers, Auto Scaling groups, and DynamoDB table
- 3 readiness checks, one for each resource set
Deployment
To deploy the readiness check template, open a terminal and type the following:
# assuming you're in the main directory of this project
cd scripts
./Route53-create-readiness-check.sh
Alternatively, to invoke CloudFormation by using the AWS CLI, issue a command similar to the following:
REGION=us-west-2
STACK_NAME=Route53ARC-ReadinessCheck
aws --region $REGION cloudformation create-stack \
--template-body file://./cloudformation/Route53-ARC-readiness-check.yaml \
--stack-name $STACK_NAME \
--parameters ParameterKey=Region1,ParameterValue=us-east-1 \
ParameterKey=Region2,ParameterValue=us-west-2 \
ParameterKey=LoadBalancer1,ParameterValue=$LOAD_BALANCER_1_ARN \
ParameterKey=LoadBalancer2,ParameterValue=$LOAD_BALANCER_2_ARN \
ParameterKey=AutoScalingGroup1,ParameterValue=$AUTO_SCALINGGROUP_1_ARN \
ParameterKey=AutoScalingGroup2,ParameterValue=$AUTO_SCALINGGROUP_2_ARN \
ParameterKey=DynamoDBTable,ParameterValue=$DYNAMODB_TABLE_ARN \
Routing control template
The CloudFormation routing Control template creates the cluster in Application Recovery Controller and other required routing control infrastructure.
Parameters
This template takes the following parameters:
- The two AWS Regions for the application cells
Resources
The template creates the following resources:
- 1 cluster
- 1 control panel
- 2 routing controls in
us-east-1
andus-west-1
- 1 safety rule, to ensure that at least one cell is active at all times
- 2 Route 53 routing control health checks
To learn about these resources and how they work, see the Amazon Route 53 Application Recovery Controller documentation.
The routing control template is independent of the readiness check template described earlier, so you can deploy the two stacks in parallel if you like.
Deployment
To deploy the routing control template, open a terminal and type the following:
# assuming you're in the main directory of this project
cd scripts
./Route53-create-routing-control.sh
Alternatively, if you want to invoke CloudFormation by using the AWS CLI, you can issue a command similar to the following:
REGION=us-west-2
STACK_NAME=Route53ARC-RoutingControl
aws --region $REGION cloudformation create-stack \
--template-body file://./Route53-ARC-routing-control.yaml \
--stack-name $STACK_NAME
DNS failover records template
You can use the DNS records template to configure the following required Route 53 DNS failover records for the routing control health checks:
- An A ALIAS PRIMARY failover record: Points to the TicTacToe demo application load balancer deployed in
us-east-1
- An A ALIAS SECONDARY failover record: Points to the TicTacToe demo application load balancer deployed in
us-west-2
After you deplopy the template, the DNS records are associated with the corresponding routing control health checks that were created earlier. The failover records enable you to use the routing controls to failover traffic in Application Recovery Controller.
Parameters
This template uses the following parameters:
- The TicTacToe demo application load balancer DNS names and Hosted Zone Ids. These are provided as output by the application CDK script that you run earlier, in the file
out.json
. - The health check ids tnat are created when you deploy the routing control template. The routing control CloudFormation stack returns these values as output.
- A Route 53 hosted zone ID. This is the domain name where you want to create the DNS records. For this demo, I hardcoded my DNS domain,
seb.go-aws.com
in the shell script, but you must use your own domain.
To read the parameters and provide them as input to the template, I provide a shell script scripts/Route53-create-dns-records.sh
. It reads out.json
and provides the appropriate values to the CloudFormation readiness check template.
WARNING
YOU MUST CHANGE THE DNS DOMAIN NAME AND DNS HOSTED ZONE ID BEFORE YOU DEPLOY THIS TEMPLATE
As noted at the top of this README, update the following values to fit your environment:
DNS hosted zone: Update line 7 of thescripts/Route53-create-dns-records.sh
script with a value that corresponds to your AWS environment
DNS domain name: Update line 6 of thescripts/Route53-create-dns-records.sh
script with a value that corresponds to your AWS environment
Deployment
To deploy the Routing Control template, open a terminal and type the following:
Alternatively, if you want to invoke CloudFormation using the AWS CLI, you can issue a command similar to the following:
REGION=us-west-2
STACK_NAME=Route53-dns-records
ROUTE53_HEALTHCHECKID_CELL1=$(aws --region $REGION cloudformation describe-stacks --stack-name Route53ARC-RoutingControl --query "Stacks[].Outputs[?OutputKey=='HealthCheckIdEast'].OutputValue" --output text)
ROUTE53_HEALTHCHECKID_CELL2=$(aws --region $REGION cloudformation describe-stacks --stack-name Route53ARC-RoutingControl --query "Stacks[].Outputs[?OutputKey=='HealthCheckIdWest'].OutputValue" --output text)
aws --region $REGION CloudFormation create-stack \
--template-body file://./cloudformation/Route53-DNS-records.yaml \
--stack-name $STACK_NAME \
--parameters ParameterKey=LoadBalancerDNSNameEast,ParameterValue=$LOAD_BALANCER_1_DNS \
ParameterKey=LoadBalancerDNSNameWest,ParameterValue=$LOAD_BALANCER_2_DNS \
ParameterKey=LoadBalancerHostedZoneEast,ParameterValue=$LOAD_BALANCER_HOSTEDZONE_EAST \
ParameterKey=LoadBalancerHostedZoneWest,ParameterValue=$LOAD_BALANCER_HOSTEDZONE_WEST \
ParameterKey=DNSHostedZone,ParameterValue=$DNS_HOSTED_ZONE_ID \
ParameterKey=DNSDomainName,ParameterValue=$DNS_HOSTED_ZONE_NAME \
ParameterKey=DNSHealthcheckIdEast,ParameterValue=$ROUTE53_HEALTHCHECKID_CELL1 \
ParameterKey=DNSHealthcheckIdWest,ParameterValue=$ROUTE53_HEALTHCHECKID_CELL2
Question or feedback?
Send your questions or feedback to [email protected]