This is a project for CDK development with TypeScript. The aim is to scale an ECS cluster based on the queue size from a Redis (Elasticache) cluster.
- Clone the repo
- Install packages (npm install)
- Update the bin/fargate_scale.ts file with your AWS account and region
Right now the lambda that can GET/SET values in Elasticache (and then after GET it will set the Cloudwatch metric) Can be kicked off with test events of the format below. Basically, the SET can set the value of anything. The GET will grab "value" from Elasticache for the given key and then the string value is set to an integer and used to update the Cloudwatch metric (this is what scales the ECS tasks).
{ "params":{ "key": "queuename", "value": "10000", "type": "set" } }
{ "params":{ "key": "queuename", "type": "get" } }
- Fargate behind an ALB (in 3 different availability zones)
- Elasticache on EC2 (in one specific availability zone)
- Custom Cloudwatch metric to scale on (queue size)
- Lambda to access the Elasticache cluster and output the custom metric to Cloudwatch
- Interface endpoint that allows the Lambda (in private subnet) to reach out to Cloudwatch
git cloneclone this reponpm installinstall all of the packages needednpx aws-cdk deploydeploy this stack to your default AWS account/regionnpx aws-cdk diffcompare deployed stack with current statenpx aws-cdk synthemits the synthesized CloudFormation template