├── .gitignore ├── test ├── Gemfile └── app.rb ├── images ├── aws-elasticache-cluster-mode-dashboard.png ├── aws-elasticache-cluster-mode-architecture.png └── aws-elasticache-cluster-mode-read-results.png ├── .github └── PULL_REQUEST_TEMPLATE.md ├── artillery ├── Dockerfile └── config.yml ├── CODE_OF_CONDUCT.md ├── LICENSE-SUMMARY ├── LICENSE-SAMPLECODE ├── CONTRIBUTING.md ├── README.md ├── LICENSE └── template.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | packaged.yaml 2 | .DS_Store 3 | .aws-sam 4 | Rakefile 5 | -------------------------------------------------------------------------------- /test/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem "redis", "~> 4.1" 4 | 5 | gem "faker", "~> 1.9" 6 | 7 | gem "hiredis", "~> 0.6.3" 8 | -------------------------------------------------------------------------------- /images/aws-elasticache-cluster-mode-dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-elasticache-cluster-mode/HEAD/images/aws-elasticache-cluster-mode-dashboard.png -------------------------------------------------------------------------------- /images/aws-elasticache-cluster-mode-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-elasticache-cluster-mode/HEAD/images/aws-elasticache-cluster-mode-architecture.png -------------------------------------------------------------------------------- /images/aws-elasticache-cluster-mode-read-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-elasticache-cluster-mode/HEAD/images/aws-elasticache-cluster-mode-read-results.png -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 7 | -------------------------------------------------------------------------------- /artillery/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:10-alpine 2 | 3 | VOLUME /artillery 4 | WORKDIR /artillery 5 | 6 | RUN npm install -g artillery --ignore-scripts 7 | 8 | COPY config.yml config.yml 9 | 10 | ENTRYPOINT ["artillery"] 11 | CMD ["run", "config.yml"] 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /LICENSE-SUMMARY: -------------------------------------------------------------------------------- 1 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | The documentation is made available under the Creative Commons Attribution-ShareAlike 4.0 International License. See the LICENSE file. 4 | 5 | The sample code within this documentation is made available under the MIT-0 license. See the LICENSE-SAMPLECODE file. 6 | -------------------------------------------------------------------------------- /artillery/config.yml: -------------------------------------------------------------------------------- 1 | config: 2 | target: 'http://internal-aws-e-LoadB-1BMCTPB4DLADI-50923873.us-east-2.elb.amazonaws.com' 3 | phases: 4 | - duration: 1200 5 | arrivalRate: 20 6 | rampTo: 150 7 | name: "Warm up" 8 | - duration: 600 9 | arrivalRate: 50 10 | rampTo: 300 11 | name: "Higher load" 12 | - duration: 1200 13 | arrivalRate: 20 14 | rampTo: 150 15 | name: "Cool Down" 16 | scenarios: 17 | - flow: 18 | - get: 19 | url: '/' 20 | -------------------------------------------------------------------------------- /LICENSE-SAMPLECODE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | software and associated documentation files (the "Software"), to deal in the Software 5 | without restriction, including without limitation the rights to use, copy, modify, 6 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 10 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 11 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 12 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 13 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 14 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /test/app.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Executes operations against Redis cluster, logging response times. 3 | # 4 | 5 | require 'redis' 6 | require 'redis/distributed' 7 | require 'redis/connection/hiredis' 8 | 9 | require 'benchmark' 10 | require 'securerandom' 11 | require 'faker' 12 | require 'json' 13 | 14 | REDIS_ENDPOINT = ENV['ELASTICACHE_ENDPOINT'] 15 | REDIS_PORT = ENV['ELASTICACHE_PORT'].to_i 16 | 17 | SESSION_KEY = 'session_' 18 | 19 | @redis = nil 20 | 21 | def write_data(session_id) 22 | name = Faker::Name.name 23 | email = Faker::Internet.email 24 | ip_address = Faker::Internet.ip_v4_address 25 | company = Faker::Company.name 26 | job = Faker::Job.title 27 | 28 | Benchmark.measure { 29 | @redis.hmset(session_id, 30 | 'name', name, 31 | 'email', email, 32 | 'ip_address', ip_address, 33 | 'company', company, 34 | 'job', job) 35 | } 36 | end 37 | 38 | def read_data(session_id) 39 | Benchmark.measure { 40 | @redis.hgetall(session_id).to_json 41 | } 42 | end 43 | 44 | def log_result(request_id, connection_result, write_result, read_result) 45 | msg = { 46 | type: 'ECL', 47 | requestId: request_id, 48 | connection: connection_result.real, 49 | write: write_result.real, 50 | read: read_result.real 51 | } 52 | puts msg.to_json 53 | end 54 | 55 | def handler(event:, context:) 56 | p "Caller Request ID: #{event['request_id']}" if !event['request_id'].nil? 57 | 58 | begin 59 | connection_result = Benchmark.measure { 60 | # create a new connection to the cluster on every call 61 | @redis = Redis.new(cluster: ["redis://#{REDIS_ENDPOINT}"]) 62 | } 63 | 64 | uuid = SecureRandom.uuid 65 | session_id = "#{SESSION_KEY}:#{uuid}" 66 | 67 | write_data = write_data(session_id) 68 | read_data = read_data(session_id) 69 | 70 | log_result(context.aws_request_id, connection_result, write_data, read_data) 71 | rescue Error => e 72 | msg = { 73 | type: 'ECL-ERROR', 74 | timestamp: Time.now.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'), 75 | requestId: request_id, 76 | error: e.message 77 | } 78 | p msg.to_json 79 | return { error: e.message } 80 | end 81 | 82 | { 83 | statusCode: 200, 84 | statusDescription: '200 Ok', 85 | isBase64Encoded: false, 86 | headers: { 87 | 'Content-Type': 'application/json' 88 | }, 89 | body: { write: write_data, read: read_data }.to_json 90 | } 91 | end -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Guidelines for contributing 2 | 3 | Thank you for your interest in contributing to AWS documentation! We greatly value feedback and contributions from our community. 4 | 5 | Please read through this document before you submit any pull requests or issues. It will help us work together more effectively. 6 | 7 | ## What to expect when you contribute 8 | 9 | When you submit a pull request, our team is notified and will respond as quickly as we can. We'll do our best to work with you to ensure that your pull request adheres to our style and standards. If we merge your pull request, we might make additional edits later for style or clarity. 10 | 11 | The AWS documentation source files on GitHub aren't published directly to the official documentation website. If we merge your pull request, we'll publish your changes to the documentation website as soon as we can, but they won't appear immediately or automatically. 12 | 13 | We look forward to receiving your pull requests for: 14 | 15 | * New content you'd like to contribute (such as new code samples or tutorials) 16 | * Inaccuracies in the content 17 | * Information gaps in the content that need more detail to be complete 18 | * Typos or grammatical errors 19 | * Suggested rewrites that improve clarity and reduce confusion 20 | 21 | **Note:** We all write differently, and you might not like how we've written or organized something currently. We want that feedback. But please be sure that your request for a rewrite is supported by the previous criteria. If it isn't, we might decline to merge it. 22 | 23 | ## How to contribute 24 | 25 | To contribute, send us a pull request. For small changes, such as fixing a typo or adding a link, you can use the [GitHub Edit Button](https://blog.github.com/2011-04-26-forking-with-the-edit-button/). For larger changes: 26 | 27 | 1. [Fork the repository](https://help.github.com/articles/fork-a-repo/). 28 | 2. In your fork, make your change in a branch that's based on this repo's **master** branch. 29 | 3. Commit the change to your fork, using a clear and descriptive commit message. 30 | 4. [Create a pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/), answering any questions in the pull request form. 31 | 32 | Before you send us a pull request, please be sure that: 33 | 34 | 1. You're working from the latest source on the **master** branch. 35 | 2. You check [existing open](https://github.com/awsdocs/aws-elasticache-cluster-mode/pulls), and [recently closed](https://github.com/awsdocs/aws-elasticache-cluster-mode/pulls?q=is%3Apr+is%3Aclosed), pull requests to be sure that someone else hasn't already addressed the problem. 36 | 3. You [create an issue](https://github.com/awsdocs/aws-elasticache-cluster-mode/issues/new) before working on a contribution that will take a significant amount of your time. 37 | 38 | For contributions that will take a significant amount of time, [open a new issue](https://github.com/awsdocs/aws-elasticache-cluster-mode/issues/new) to pitch your idea before you get started. Explain the problem and describe the content you want to see added to the documentation. Let us know if you'll write it yourself or if you'd like us to help. We'll discuss your proposal with you and let you know whether we're likely to accept it. We don't want you to spend a lot of time on a contribution that might be outside the scope of the documentation or that's already in the works. 39 | 40 | ## Finding contributions to work on 41 | 42 | If you'd like to contribute, but don't have a project in mind, look at the [open issues](https://github.com/awsdocs/aws-elasticache-cluster-mode/issues) in this repository for some ideas. Any issues with the [help wanted](https://github.com/awsdocs/aws-elasticache-cluster-mode/labels/help%20wanted) or [enhancement](https://github.com/awsdocs/aws-elasticache-cluster-mode/labels/enhancement) labels are a great place to start. 43 | 44 | In addition to written content, we really appreciate new examples and code samples for our documentation, such as examples for different platforms or environments, and code samples in additional languages. 45 | 46 | ## Code of conduct 47 | 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For more information, see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact [opensource-codeofconduct@amazon.com](mailto:opensource-codeofconduct@amazon.com) with any additional questions or comments. 49 | 50 | ## Security issue notifications 51 | 52 | If you discover a potential security issue, please notify AWS Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public issue on GitHub. 53 | 54 | ## Licensing 55 | 56 | See the [LICENSE](https://github.com/awsdocs/aws-elasticache-cluster-mode/blob/master/LICENSE) file for this project's licensing. We will ask you to confirm the licensing of your contribution. We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Working with Cluster Mode on Amazon ElastiCache for Redis 2 | 3 | This project demonstrates and measures the scaling behavior of [Amazon ElastiCache](https://aws.amazon.com/elasticache/) for Redis with Cluster Mode. ElastiCache provides a fully managed, in-memory data store that can be used for a variety of use cases. Cluster Mode allows for horizontal scaling of your ElastiCache for Redis cluster, allowing higher write activity and storage capacity. Cluster Mode also does not require a restart for scaling, nor complex changes to your application code (if any changes at all). 4 | 5 | For this project, we have created the simple test harness shown in the diagram below. The test harness includes a new ElastiCache for Redis cluster with Cluster Mode enabled. The new cluster will start with one shard and a node type of `cache.r5.large`. We'll use an AWS Lambda function to read and write data to the cluster. The function will capture response times for those operations and write results to Amazon CloudWatch. A popular load testing tool, [Artillery](https://artillery.io), running in an AWS Fargate Task, will be used to drive traffic to an Application Load Balancer, invoking the function. 6 | 7 | ![Project Architecture](./images/aws-elasticache-cluster-mode-architecture.png) 8 | 9 | ## Prerequisites 10 | 11 | This project requires the following prerequisite tools to build and deploy code: 12 | 13 | * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) 14 | * [Docker](https://www.docker.com/) 15 | * [AWS Serverless Application Model CLI (AWS SAM CLI)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) 16 | 17 | For Docker and SAM CLI, follow the platform-specific instructions for your environment (e.g. Mac, Windows, Linux). 18 | 19 | ## Deploy CloudFormation stack 20 | 21 | With the above prerequisites installed, we can now move to deploying the test stack. You will first need an Amazon S3 Bucket to be used by the SAM CLI to deploy artifacts (be sure to replace `` with a unique name for your bucket): 22 | 23 | ``` bash 24 | $ aws s3 mb s3:// 25 | ``` 26 | 27 | Next, let's deploy the project code using the SAM CLI: 28 | 29 | ``` bash 30 | # Build the Lambda function and dependencies (note this can take a few minutes) 31 | $ sam build --use-container 32 | 33 | # Package the function and dependencies 34 | $ sam package --output-template-file packaged.yaml \ 35 | --s3-bucket 36 | 37 | # Deploy... 38 | $ sam deploy --template-file packaged.yaml \ 39 | --stack-name aws-elasticache-cluster-mode \ 40 | --capabilities CAPABILITY_NAMED_IAM 41 | ``` 42 | 43 | Review [template.yaml](./template.yaml) for details on the AWS resources created here, including ElastiCache, VPC, Lambda, and Fargate components. We use CloudFormation with Servelerss Application Model transforms to manage all of the resources required for the project. 44 | 45 | ## Update Artillery Config 46 | 47 | After the CloudFormation stack deployment completes, query for the internal DNS name of the Application Load Balancer (ALB) created to front the Lambda function. To generate load for our test, Artillery will send HTTP requests to the ALB which in turn invokes the function. 48 | 49 | ``` bash 50 | $ aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 51 | --query 'Stacks[*].Outputs[?OutputKey==`LoadBalancerDns`].OutputValue' \ 52 | --output text 53 | ``` 54 | 55 | Copy the return value from the above command and update the target value on line 2 of `artillery/config.yml` as follows. Be sure to save the file before moving on. 56 | 57 | ### artillery/config.yml 58 | 59 | ``` yaml 60 | config: 61 | target: 'http://internal-aws-my-load-balancer.us-east-1.elb.amazonaws.com' 62 | 63 | ... 64 | ``` 65 | 66 | We have built a 50 minute test scenario composed of three Artillery phases here, though you could modify to design other test scenarios with higher loads, etc. See [Artillery documentation](https://artillery.io/docs/script-reference/) for details. 67 | 68 | ## Build and Push Artillery Test Harness 69 | 70 | Next, we will build the and publish our Artillery container to the Amazon Elastic Container Registry (ECR). When we initiate our test procedure below, Fargate will pull the latest version of the container from ECR. 71 | 72 | ``` bash 73 | # Login to AWS ECR 74 | $ $(aws ecr get-login --no-include-email) 75 | 76 | # Build and push artillery 77 | $ export REPO=$(aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 78 | --query 'Stacks[*].Outputs[?OutputKey==`ArtilleryRepository`].OutputValue' \ 79 | --output text) 80 | $ docker build -t elasticache-artillery artillery/ 81 | $ docker tag elasticache-artillery:latest $REPO:latest 82 | $ docker push $REPO:latest 83 | ``` 84 | 85 | If you modify `config.yml` following this initial build, be sure to build and push to ECR again using the same steps as above. 86 | 87 | ## Visit CloudWatch Logs Dashboard 88 | 89 | Lastly, before starting the test procedure, open a pre-built Amazon CloudWatch Dashboard in your favorite browser to keep an eye on ElastiCache and Lambda metrics: 90 | 91 | ``` bash 92 | # Get the URL for the CloudWatch Dashboard 93 | $ aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 94 | --query 'Stacks[*].Outputs[?OutputKey==`CloudWatchDashboard`].OutputValue' \ 95 | --output text 96 | ``` 97 | 98 | Copy resulting URL and open in your favorite browser. 99 | 100 | > The dashboard in this project makes use of [CloudWatch Logs Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html). For detais on the syntax of these queries, see [CloudWatch Logs Query Syntax](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html). 101 | 102 | ## Initiate Test Sequence 103 | 104 | We're now ready to launch our test. We'll start by gathering the Security Group, Subnets, and Cluster name to be used for our Artillery tasks. With that data, we can launch the tasks to begin to generate load on the ElastiCache cluster. Here, we launch three tasks, though you could increase the number (up to 10) or decrease as well. 105 | 106 | ``` bash 107 | # Grab some data 108 | $ export SG=$(aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 109 | --query 'Stacks[*].Outputs[?OutputKey==`ArtillerySecurityGroup`].OutputValue' \ 110 | --output text) 111 | 112 | $ export SUBNETS=$(aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 113 | --query 'Stacks[*].Outputs[?OutputKey==`PrivateSubnets`].OutputValue' \ 114 | --output text) 115 | 116 | $ export CLUSTER=$(aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 117 | --query 'Stacks[*].Outputs[?OutputKey==`ArtilleryCluster`].OutputValue' \ 118 | --output text) 119 | 120 | # Run Artillery Fargate task 121 | $ aws ecs run-task \ 122 | --cluster $CLUSTER \ 123 | --task-definition aws-elasticache-cluster-mode-task \ 124 | --count 3 \ 125 | --launch-type FARGATE \ 126 | --network-configuration "awsvpcConfiguration={subnets=[$SUBNETS],securityGroups=[$SG],assignPublicIp=DISABLED}" 127 | 128 | ``` 129 | 130 | After launching the Fargate tasks, jump back to the CloudWatch Dashboard to watch load start to build on ElastiCache. 131 | 132 | ## Scale ElastiCache Cluster 133 | 134 | Wait approximately 15 minutes after starting the Artillery tasks, then horizontally scale the ElastiCache cluster by adding a second shard as follows ([docs](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/redis-cluster-resharding-online.html#redis-cluster-resharding-online-add-cli)): 135 | 136 | ``` bash 137 | $ export ECCLUSTER=$(aws cloudformation describe-stacks --stack-name aws-elasticache-cluster-mode \ 138 | --query 'Stacks[*].Outputs[?OutputKey==`RedisCluster`].OutputValue' \ 139 | --output text) 140 | 141 | $ aws elasticache modify-replication-group-shard-configuration \ 142 | --replication-group-id $ECCLUSTER \ 143 | --node-group-count 2 \ 144 | --apply-immediately 145 | ``` 146 | 147 | It will take several minutes for the new shard to be created and then a few more minutes for ElastiCache to automatically rebalance the keyspace between the old and new shards. In the dashboard, you will be able to see the new shard come in to service and begin to accept connections. 148 | 149 | ![CloudWatch Dashboard](./images/aws-elasticache-cluster-mode-dashboard.png) 150 | 151 | At the bottom of the dashboard, review the latency metrics collected by the Lambda function. Notice that neither reads, writes, nor connection latencies are dramatically impacted by the scaling operations, nor did we need to incur a restart. The read latency results of one of our test runs is as follows; notice that ElastiCache for Redis is both fast and consistent: 152 | 153 | ![Read Latency Test Results](./images/aws-elasticache-cluster-mode-read-results.png) 154 | 155 | ## Cleaning Up 156 | 157 | When finished, you can cleanup the AWS resources used in this project: 158 | 159 | ``` bash 160 | $ aws cloudformation delete-stack --stack-name aws-elasticache-cluster-mode 161 | ``` 162 | 163 | ## License Summary 164 | 165 | The documentation is made available under the Creative Commons Attribution-ShareAlike 4.0 International License. See the LICENSE file. 166 | 167 | The sample code within this documentation is made available under the MIT-0 license. See the LICENSE-SAMPLECODE file. 168 | 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution-ShareAlike 4.0 International Public License 2 | 3 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 4 | 5 | Section 1 – Definitions. 6 | 7 | a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 8 | 9 | b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 10 | 11 | c. BY-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License. 12 | 13 | d. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 14 | 15 | e. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 16 | 17 | f. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 18 | 19 | g. License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike. 20 | 21 | h. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 22 | 23 | i. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 24 | 25 | j. Licensor means the individual(s) or entity(ies) granting rights under this Public License. 26 | 27 | k. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 28 | 29 | l. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 30 | 31 | m. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 32 | 33 | Section 2 – Scope. 34 | 35 | a. License grant. 36 | 37 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 38 | 39 | A. reproduce and Share the Licensed Material, in whole or in part; and 40 | 41 | B. produce, reproduce, and Share Adapted Material. 42 | 43 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 44 | 45 | 3. Term. The term of this Public License is specified in Section 6(a). 46 | 47 | 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 48 | 49 | 5. Downstream recipients. 50 | 51 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 52 | 53 | B. Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 54 | 55 | C. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 56 | 57 | 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 58 | 59 | b. Other rights. 60 | 61 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 62 | 63 | 2. Patent and trademark rights are not licensed under this Public License. 64 | 65 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. 66 | 67 | Section 3 – License Conditions. 68 | 69 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 70 | 71 | a. Attribution. 72 | 73 | 1. If You Share the Licensed Material (including in modified form), You must: 74 | 75 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 76 | 77 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 78 | 79 | ii. a copyright notice; 80 | 81 | iii. a notice that refers to this Public License; 82 | 83 | iv. a notice that refers to the disclaimer of warranties; 84 | 85 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 86 | 87 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 88 | 89 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 90 | 91 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 92 | 93 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 94 | 95 | b. ShareAlike.In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 96 | 97 | 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License. 98 | 99 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 100 | 101 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 102 | 103 | Section 4 – Sui Generis Database Rights. 104 | 105 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 106 | 107 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; 108 | 109 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 110 | 111 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 112 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 113 | 114 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 115 | 116 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. 117 | 118 | b. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 119 | 120 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 121 | 122 | Section 6 – Term and Termination. 123 | 124 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 125 | 126 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 127 | 128 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 129 | 130 | 2. upon express reinstatement by the Licensor. 131 | 132 | c. For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 133 | 134 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 135 | 136 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 137 | 138 | Section 7 – Other Terms and Conditions. 139 | 140 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 141 | 142 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 143 | 144 | Section 8 – Interpretation. 145 | 146 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 147 | 148 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 149 | 150 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 151 | 152 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 153 | -------------------------------------------------------------------------------- /template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: AWS ElatiCache for Redis - Cluster Mode Demonstration 4 | 5 | Parameters: 6 | ProjectName: 7 | Type: String 8 | Default: aws-elasticache-cluster-mode 9 | 10 | ElasticacheInstanceClass: 11 | Type: String 12 | Default: cache.r5.large #cache.t2.micro 13 | 14 | Globals: 15 | Function: 16 | Runtime: ruby2.5 17 | Handler: app.handler 18 | MemorySize: 1024 19 | Timeout: 15 20 | Tracing: Active 21 | Tags: 22 | Project: !Ref ProjectName 23 | 24 | Mappings: 25 | SubnetConfig: 26 | VPC: 27 | CIDR: '10.0.0.0/16' 28 | Private1: 29 | CIDR: '10.0.0.0/24' 30 | Private2: 31 | CIDR: '10.0.1.0/24' 32 | Lambda1: 33 | CIDR: '10.0.2.0/24' 34 | Lambda2: 35 | CIDR: '10.0.3.0/24' 36 | Public1: 37 | CIDR: '10.0.4.0/24' 38 | 39 | Resources: 40 | # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticache-replicationgroup.html 41 | RedisCluster: 42 | Type: AWS::ElastiCache::ReplicationGroup 43 | Properties: 44 | AutoMinorVersionUpgrade: true 45 | # enable Cluster Mode 46 | CacheParameterGroupName: default.redis5.0.cluster.on 47 | CacheNodeType: !Ref ElasticacheInstanceClass 48 | CacheSubnetGroupName: !Ref RedisSubnetGroup 49 | Engine: redis 50 | EngineVersion: 5.0.4 51 | NumNodeGroups: 1 52 | Port: 6379 53 | ReplicasPerNodeGroup: 1 54 | ReplicationGroupDescription: Sample Redis group for scaling 55 | SecurityGroupIds: 56 | - !Ref RedisSecurityGroup 57 | Tags: 58 | - Key: Project 59 | Value: !Ref ProjectName 60 | 61 | RedisSubnetGroup: 62 | Type: AWS::ElastiCache::SubnetGroup 63 | Properties: 64 | Description: Redis subnet group 65 | SubnetIds: 66 | - !Ref PrivateSubnet1 67 | - !Ref PrivateSubnet2 68 | 69 | RedisSecurityGroup: 70 | Type: AWS::EC2::SecurityGroup 71 | Properties: 72 | VpcId: !Ref VPC 73 | GroupDescription: Enable Redis access 74 | SecurityGroupIngress: 75 | - IpProtocol: tcp 76 | FromPort: 6379 77 | ToPort: 6379 78 | SourceSecurityGroupId: !Ref LambdaSecurityGroup 79 | Tags: 80 | - Key: Project 81 | Value: !Ref ProjectName 82 | 83 | # 84 | # Test API 85 | # 86 | TestFunction: 87 | Type: AWS::Serverless::Function 88 | Properties: 89 | Description: > 90 | Sets and gets data from ElastiCache cluster, recording response 91 | times in CloudWatch. 92 | CodeUri: test/ 93 | Policies: 94 | - VPCAccessPolicy: {} 95 | VpcConfig: 96 | SecurityGroupIds: 97 | - !Ref LambdaSecurityGroup 98 | SubnetIds: 99 | - !Ref LambdaSubnet1 100 | - !Ref LambdaSubnet2 101 | Environment: 102 | Variables: 103 | ELASTICACHE_ENDPOINT: !GetAtt RedisCluster.ConfigurationEndPoint.Address 104 | ELASTICACHE_PORT: !GetAtt RedisCluster.ConfigurationEndPoint.Port 105 | Tags: 106 | Project: !Ref ProjectName 107 | 108 | LambdaSecurityGroup: 109 | Type: AWS::EC2::SecurityGroup 110 | Properties: 111 | VpcId: !Ref VPC 112 | GroupDescription: Enable Redis access 113 | Tags: 114 | - Key: Project 115 | Value: !Ref ProjectName 116 | 117 | LoadBalancer: 118 | Type: AWS::ElasticLoadBalancingV2::LoadBalancer 119 | Properties: 120 | Scheme: internal 121 | Subnets: 122 | - !Ref LambdaSubnet1 123 | - !Ref LambdaSubnet2 124 | SecurityGroups: 125 | - !Ref LoadBalancerSecurityGroup 126 | Tags: 127 | - Key: Project 128 | Value: !Ref ProjectName 129 | 130 | TargetGroup: 131 | Type: AWS::ElasticLoadBalancingV2::TargetGroup 132 | DependsOn: TestFunctionInvokePermission 133 | Properties: 134 | TargetType: lambda 135 | Targets: 136 | - Id: !GetAtt TestFunction.Arn 137 | Tags: 138 | - Key: Project 139 | Value: !Ref ProjectName 140 | 141 | HttpListener: 142 | Type: AWS::ElasticLoadBalancingV2::Listener 143 | Properties: 144 | DefaultActions: 145 | - TargetGroupArn: !Ref TargetGroup 146 | Type: forward 147 | LoadBalancerArn: !Ref LoadBalancer 148 | Port: 80 149 | Protocol: HTTP 150 | 151 | LoadBalancerSecurityGroup: 152 | Type: AWS::EC2::SecurityGroup 153 | Properties: 154 | GroupDescription: Load balancer security group 155 | VpcId: !Ref VPC 156 | SecurityGroupIngress: 157 | - IpProtocol: tcp 158 | FromPort: 80 159 | ToPort: 80 160 | CidrIp: !FindInMap ['SubnetConfig', 'VPC', 'CIDR'] 161 | Tags: 162 | - Key: Project 163 | Value: !Ref ProjectName 164 | 165 | TestFunctionInvokePermission: 166 | Type: AWS::Lambda::Permission 167 | Properties: 168 | FunctionName: !GetAtt TestFunction.Arn 169 | Action: 'lambda:InvokeFunction' 170 | Principal: elasticloadbalancing.amazonaws.com 171 | 172 | # 173 | # Fargate 174 | # 175 | ArtilleryRepository: 176 | Type: AWS::ECR::Repository 177 | Properties: 178 | RepositoryName: !Sub "${ProjectName}-artillery" 179 | 180 | ArtilleryCluster: 181 | Type: AWS::ECS::Cluster 182 | Properties: 183 | ClusterName: !Sub "${ProjectName}-artillery" 184 | 185 | ArtilleryTaskDefinition: 186 | Type: AWS::ECS::TaskDefinition 187 | Properties: 188 | Family: !Sub "${ProjectName}-task" 189 | NetworkMode: awsvpc 190 | Cpu: "1024" 191 | Memory: 3GB 192 | RequiresCompatibilities: 193 | - FARGATE 194 | ExecutionRoleArn: !GetAtt TaskExecutionRole.Arn 195 | ContainerDefinitions: 196 | - Name: !Sub "${ProjectName}-artillery" 197 | Essential: true 198 | Image: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ArtilleryRepository}:latest 199 | LogConfiguration: 200 | LogDriver: awslogs 201 | Options: 202 | awslogs-group: !Ref LogGroup 203 | awslogs-region: !Ref AWS::Region 204 | awslogs-stream-prefix: ecs 205 | 206 | ArtillerySecurityGroup: 207 | Type: AWS::EC2::SecurityGroup 208 | Properties: 209 | VpcId: !Ref VPC 210 | GroupDescription: Enable Redis access 211 | Tags: 212 | - Key: Project 213 | Value: !Ref ProjectName 214 | 215 | TaskExecutionRole: 216 | Type: AWS::IAM::Role 217 | Properties: 218 | AssumeRolePolicyDocument: 219 | Statement: 220 | - Effect: Allow 221 | Principal: 222 | Service: "ecs-tasks.amazonaws.com" 223 | Action: "sts:AssumeRole" 224 | Path: "/" 225 | ManagedPolicyArns: 226 | - "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy" 227 | 228 | LogGroup: 229 | Type: AWS::Logs::LogGroup 230 | Properties: 231 | LogGroupName: !Sub "/ecs/${ProjectName}-task" 232 | 233 | # 234 | # Networking 235 | # 236 | VPC: 237 | Type: AWS::EC2::VPC 238 | Properties: 239 | EnableDnsSupport: true 240 | EnableDnsHostnames: true 241 | CidrBlock: !FindInMap ['SubnetConfig', 'VPC', 'CIDR'] 242 | Tags: 243 | - Key: Name 244 | Value: !Sub "${ProjectName}-vpc" 245 | - Key: Project 246 | Value: !Ref ProjectName 247 | 248 | PrivateSubnet1: 249 | Type: AWS::EC2::Subnet 250 | Properties: 251 | AvailabilityZone: 252 | Fn::Select: 253 | - 0 254 | - Fn::GetAZs: !Ref AWS::Region 255 | VpcId: !Ref VPC 256 | CidrBlock: !FindInMap ['SubnetConfig', 'Private1', 'CIDR'] 257 | Tags: 258 | - Key: Name 259 | Value: !Sub "${ProjectName}-private-subnet-1" 260 | - Key: Project 261 | Value: !Ref ProjectName 262 | 263 | PrivateSubnet2: 264 | Type: AWS::EC2::Subnet 265 | Properties: 266 | AvailabilityZone: 267 | Fn::Select: 268 | - 1 269 | - Fn::GetAZs: !Ref AWS::Region 270 | VpcId: !Ref VPC 271 | CidrBlock: !FindInMap ['SubnetConfig', 'Private2', 'CIDR'] 272 | Tags: 273 | - Key: Name 274 | Value: !Sub "${ProjectName}-private-subnet-2" 275 | - Key: Project 276 | Value: !Ref ProjectName 277 | 278 | PublicSubnet1: 279 | Type: AWS::EC2::Subnet 280 | Properties: 281 | AvailabilityZone: 282 | Fn::Select: 283 | - 1 284 | - Fn::GetAZs: !Ref AWS::Region 285 | VpcId: !Ref VPC 286 | CidrBlock: !FindInMap ['SubnetConfig', 'Public1', 'CIDR'] 287 | Tags: 288 | - Key: Name 289 | Value: !Sub "${ProjectName}-public-subnet-1" 290 | - Key: Project 291 | Value: !Ref ProjectName 292 | 293 | LambdaSubnet1: 294 | Type: AWS::EC2::Subnet 295 | Properties: 296 | AvailabilityZone: 297 | Fn::Select: 298 | - 0 299 | - Fn::GetAZs: !Ref AWS::Region 300 | VpcId: !Ref VPC 301 | CidrBlock: !FindInMap ['SubnetConfig', 'Lambda1', 'CIDR'] 302 | Tags: 303 | - Key: Name 304 | Value: !Sub "${ProjectName}-lambda-subnet-1" 305 | - Key: Project 306 | Value: !Ref ProjectName 307 | 308 | LambdaSubnet2: 309 | Type: AWS::EC2::Subnet 310 | Properties: 311 | AvailabilityZone: 312 | Fn::Select: 313 | - 1 314 | - Fn::GetAZs: !Ref AWS::Region 315 | VpcId: !Ref VPC 316 | CidrBlock: !FindInMap ['SubnetConfig', 'Lambda2', 'CIDR'] 317 | Tags: 318 | - Key: Name 319 | Value: !Sub "${ProjectName}-lambda-subnet-2" 320 | - Key: Project 321 | Value: !Ref ProjectName 322 | 323 | InternetGateway: 324 | Type: AWS::EC2::InternetGateway 325 | 326 | GatewayAttachement: 327 | Type: AWS::EC2::VPCGatewayAttachment 328 | Properties: 329 | VpcId: !Ref VPC 330 | InternetGatewayId: !Ref InternetGateway 331 | 332 | PublicRouteTable: 333 | Type: AWS::EC2::RouteTable 334 | Properties: 335 | VpcId: !Ref VPC 336 | 337 | PublicRoute: 338 | Type: AWS::EC2::Route 339 | DependsOn: GatewayAttachement 340 | Properties: 341 | RouteTableId: !Ref PublicRouteTable 342 | DestinationCidrBlock: "0.0.0.0/0" 343 | GatewayId: !Ref InternetGateway 344 | 345 | PublicSubnet1RouteTableAssociation: 346 | Type: AWS::EC2::SubnetRouteTableAssociation 347 | Properties: 348 | SubnetId: !Ref PublicSubnet1 349 | RouteTableId: !Ref PublicRouteTable 350 | 351 | NatGatewayAttachment: 352 | Type: AWS::EC2::EIP 353 | DependsOn: GatewayAttachement 354 | Properties: 355 | Domain: vpc 356 | 357 | NatGateway: 358 | Type: AWS::EC2::NatGateway 359 | Properties: 360 | AllocationId: !GetAtt NatGatewayAttachment.AllocationId 361 | SubnetId: !Ref PublicSubnet1 362 | 363 | PrivateRouteTable: 364 | Type: AWS::EC2::RouteTable 365 | Properties: 366 | VpcId: !Ref VPC 367 | 368 | PrivateRoute: 369 | Type: AWS::EC2::Route 370 | Properties: 371 | RouteTableId: !Ref PrivateRouteTable 372 | DestinationCidrBlock: "0.0.0.0/0" 373 | NatGatewayId: !Ref NatGateway 374 | 375 | PrivateRouteTable1Association: 376 | Type: AWS::EC2::SubnetRouteTableAssociation 377 | Properties: 378 | RouteTableId: !Ref PrivateRouteTable 379 | SubnetId: !Ref PrivateSubnet1 380 | 381 | PrivateRouteTable2Association: 382 | Type: AWS::EC2::SubnetRouteTableAssociation 383 | Properties: 384 | RouteTableId: !Ref PrivateRouteTable 385 | SubnetId: !Ref PrivateSubnet2 386 | 387 | # 388 | # CloudWatch 389 | # 390 | CloudWatchDashboard: 391 | Type: AWS::CloudWatch::Dashboard 392 | Properties: 393 | DashboardBody: !Sub | 394 | { 395 | "start": "-PT1H", 396 | "periodOverride": "inherit", 397 | "widgets": [ 398 | { 399 | "type": "text", 400 | "x": 0, 401 | "y": 0, 402 | "width": 24, 403 | "height": 1, 404 | "properties": { 405 | "markdown": "# Redis Metrics" 406 | } 407 | }, 408 | { 409 | "type": "metric", 410 | "x": 0, 411 | "y": 1, 412 | "width": 8, 413 | "height": 6, 414 | "properties": { 415 | "metrics": [ 416 | [ "AWS/ElastiCache", "BytesUsedForCache", "CacheClusterId", "${RedisCluster}-0001-001" ], 417 | [ "...", "${RedisCluster}-0002-001" ] 418 | ], 419 | "view": "timeSeries", 420 | "stacked": true, 421 | "region": "${AWS::Region}", 422 | "stat": "Average", 423 | "period": 30, 424 | "title": "Bytes Used for Cache by Node" 425 | } 426 | }, 427 | { 428 | "type": "metric", 429 | "x": 8, 430 | "y": 1, 431 | "width": 8, 432 | "height": 6, 433 | "properties": { 434 | "metrics": [ 435 | [ "AWS/ElastiCache", "NewConnections", "CacheClusterId", "${RedisCluster}-0001-001" ], 436 | [ "...", "${RedisCluster}-0002-001" ], 437 | [ ".", "CurrConnections", ".", "${RedisCluster}-0001-001" ], 438 | [ "...", "${RedisCluster}-0002-001" ] 439 | ], 440 | "view": "timeSeries", 441 | "stacked": false, 442 | "region": "${AWS::Region}", 443 | "stat": "Average", 444 | "period": 30, 445 | "title": "New and Current Connections by Node" 446 | } 447 | }, 448 | { 449 | "type": "metric", 450 | "x": 16, 451 | "y": 1, 452 | "width": 8, 453 | "height": 6, 454 | "properties": { 455 | "metrics": [ 456 | [ "AWS/ElastiCache", "CurrItems", "CacheClusterId", "${RedisCluster}-0001-001" ], 457 | [ "...", "${RedisCluster}-0002-001" ] 458 | ], 459 | "view": "timeSeries", 460 | "stacked": true, 461 | "region": "${AWS::Region}", 462 | "stat": "Average", 463 | "period": 30, 464 | "title": "Current Items by Node" 465 | } 466 | }, 467 | { 468 | "type": "metric", 469 | "x": 0, 470 | "y": 7, 471 | "width": 8, 472 | "height": 6, 473 | "properties": { 474 | "metrics": [ 475 | [ "AWS/ElastiCache", "CPUUtilization", "CacheClusterId", "${RedisCluster}-0001-001" ], 476 | [ "...", "${RedisCluster}-0002-001" ] 477 | ], 478 | "view": "timeSeries", 479 | "stacked": false, 480 | "region": "${AWS::Region}", 481 | "stat": "Average", 482 | "period": 30, 483 | "title": "CPU Utilization by Node" 484 | } 485 | }, 486 | { 487 | "type": "metric", 488 | "x": 8, 489 | "y": 7, 490 | "width": 8, 491 | "height": 6, 492 | "properties": { 493 | "metrics": [ 494 | [ "AWS/ElastiCache", "Evictions", "CacheClusterId", "${RedisCluster}-0001-001" ], 495 | [ "...", "${RedisCluster}-0002-001" ] 496 | ], 497 | "view": "timeSeries", 498 | "stacked": false, 499 | "region": "${AWS::Region}", 500 | "stat": "Average", 501 | "period": 30, 502 | "title": "Evictions by Node" 503 | } 504 | }, 505 | { 506 | "type": "metric", 507 | "x": 16, 508 | "y": 7, 509 | "width": 8, 510 | "height": 6, 511 | "properties": { 512 | "metrics": [ 513 | [ "AWS/ElastiCache", "SwapUsage", "CacheClusterId", "${RedisCluster}-0001-001" ], 514 | [ "...", "${RedisCluster}-0002-001" ] 515 | ], 516 | "view": "timeSeries", 517 | "stacked": false, 518 | "region": "${AWS::Region}", 519 | "stat": "Average", 520 | "period": 30, 521 | "title": "Swap Usage by Node" 522 | } 523 | }, 524 | 525 | { 526 | "type": "text", 527 | "x": 0, 528 | "y": 13, 529 | "width": 24, 530 | "height": 1, 531 | "properties": { 532 | "markdown": "# Lambda Metrics" 533 | } 534 | }, 535 | { 536 | "type": "metric", 537 | "x": 0, 538 | "y": 14, 539 | "width": 12, 540 | "height": 6, 541 | "properties": { 542 | "metrics": [ 543 | [ "AWS/Lambda", "Invocations", "FunctionName", "${TestFunction}", "Resource", "${TestFunction}" ] 544 | ], 545 | "view": "timeSeries", 546 | "stacked": false, 547 | "region": "${AWS::Region}", 548 | "stat": "SampleCount", 549 | "period": 30, 550 | "title": "Invocations" 551 | } 552 | }, 553 | { 554 | "type": "metric", 555 | "x": 12, 556 | "y": 14, 557 | "width": 12, 558 | "height": 6, 559 | "properties": { 560 | "metrics": [ 561 | [ "AWS/Lambda", "Throttles", "FunctionName", "${TestFunction}", "Resource", "${TestFunction}" ], 562 | [ ".", "Errors", "..." ] 563 | ], 564 | "view": "timeSeries", 565 | "stacked": false, 566 | "region": "${AWS::Region}", 567 | "stat": "Sum", 568 | "period": 30, 569 | "title": "Throttles & Errors" 570 | } 571 | }, 572 | 573 | { 574 | "type": "text", 575 | "x": 0, 576 | "y": 21, 577 | "width": 24, 578 | "height": 1, 579 | "properties": { 580 | "markdown": "# ALB Metrics" 581 | } 582 | }, 583 | { 584 | "type": "metric", 585 | "x": 0, 586 | "y": 22, 587 | "width": 12, 588 | "height": 6, 589 | "properties": { 590 | "metrics": [ 591 | [ "AWS/ApplicationELB", "NewConnectionCount", "LoadBalancer", "${LoadBalancer.LoadBalancerFullName}" ], 592 | [ ".", "RequestCount", ".", "." ] 593 | ], 594 | "view": "timeSeries", 595 | "stacked": false, 596 | "region": "${AWS::Region}", 597 | "stat": "Sum", 598 | "period": 30, 599 | "title": "Connections & Requests" 600 | } 601 | }, 602 | { 603 | "type": "metric", 604 | "x": 12, 605 | "y": 22, 606 | "width": 12, 607 | "height": 6, 608 | "properties": { 609 | "metrics": [ 610 | [ "AWS/ApplicationELB", "HTTPCode_ELB_5XX_Count", "LoadBalancer", "${LoadBalancer.LoadBalancerFullName}" ], 611 | [ ".", "HTTPCode_Target_5XX_Count", ".", "." ] 612 | ], 613 | "view": "timeSeries", 614 | "stacked": false, 615 | "region": "${AWS::Region}", 616 | "stat": "Sum", 617 | "period": 30, 618 | "title": "Errors" 619 | } 620 | }, 621 | 622 | { 623 | "type": "text", 624 | "x": 0, 625 | "y": 29, 626 | "width": 24, 627 | "height": 1, 628 | "properties": { 629 | "markdown": "# Latency Metrics" 630 | } 631 | }, 632 | { 633 | "type": "log", 634 | "x": 0, 635 | "y": 30, 636 | "width": 24, 637 | "height": 6, 638 | "properties": { 639 | "query": "SOURCE '/aws/lambda/${TestFunction}' | filter type = \"ECL\"\n| stats count(requestId), avg(write), max(write), min(write), pct(write, 50), pct(write, 90), pct(write, 95) by bin(30s)", 640 | "region": "${AWS::Region}", 641 | "title": "Write Metrics" 642 | } 643 | }, 644 | { 645 | "type": "log", 646 | "x": 0, 647 | "y": 36, 648 | "width": 24, 649 | "height": 6, 650 | "properties": { 651 | "query": "SOURCE '/aws/lambda/${TestFunction}' | filter type = \"ECL\"\n| stats count(requestId), avg(read), max(read), min(read), pct(read, 50), pct(read, 90), pct(read, 95) by bin(30s)", 652 | "region": "${AWS::Region}", 653 | "title": "Read Metrics" 654 | } 655 | }, 656 | { 657 | "type": "log", 658 | "x": 0, 659 | "y": 42, 660 | "width": 24, 661 | "height": 6, 662 | "properties": { 663 | "query": "SOURCE '/aws/lambda/${TestFunction}' | filter type = \"ECL\"\n| stats count(requestId), avg(read), max(connection), min(connection), pct(connection, 50), pct(connection, 90), pct(connection, 95) by bin(30s)", 664 | "region": "${AWS::Region}", 665 | "title": "Connection Metrics" 666 | } 667 | } 668 | ] 669 | } 670 | 671 | 672 | Outputs: 673 | RedisCluster: 674 | Description: Name of Redis Cluster 675 | Value: !Ref RedisCluster 676 | 677 | RedisPrimaryEndpoint: 678 | Description: Redis Primary Endpoint 679 | Value: !GetAtt RedisCluster.ConfigurationEndPoint.Address 680 | 681 | LoadBalancerDns: 682 | Description: DNS name for Load Balancer 683 | Value: !Sub "http://${LoadBalancer.DNSName}" 684 | 685 | ArtilleryRepository: 686 | Description: ECR Repository for Artillery image 687 | Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ArtilleryRepository} 688 | 689 | CloudWatchDashboard: 690 | Description: Name of CloudWatch Dashboard 691 | Value: !Sub "https://${AWS::Region}.console.aws.amazon.com/cloudwatch/home?region=${AWS::Region}#dashboards:name=${CloudWatchDashboard}" 692 | 693 | PrivateSubnets: 694 | Description: Array of private subnets 695 | Value: !Sub "${PrivateSubnet1},${PrivateSubnet2}" 696 | 697 | ArtillerySecurityGroup: 698 | Description: Security Group for Artillery test harness 699 | Value: !Ref ArtillerySecurityGroup 700 | 701 | ArtilleryTaskDefinition: 702 | Description: Task definition for Artillery 703 | Value: !Ref ArtilleryTaskDefinition 704 | 705 | ArtilleryCluster: 706 | Description: ECS Cluster for Artillery 707 | Value: !Ref ArtilleryCluster 708 | --------------------------------------------------------------------------------