├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── aurora.yaml ├── create.sh ├── master.yaml ├── network.yaml ├── proxy-sql.png ├── proxysql.yaml ├── secgroups.yaml └── update.sh /.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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Diagrams for ProxySQL Blog .pptx 2 | ~$Diagrams for ProxySQL Blog.pptx 3 | .github 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/aws-samples/amazon-aurora-proxysql-example/issues), or [recently closed](https://github.com/aws-samples/amazon-aurora-proxysql-example/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws-samples/amazon-aurora-proxysql-example/labels/help%20wanted) issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](https://github.com/aws-samples/amazon-aurora-proxysql-example/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 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 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to 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 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Code for "A single endpoint for reads and writes with MySql-compatible Amazon Aurora RDS" 2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Amazon Aurora ProxySQL example 2 | 3 | ![Amazon Aurora ProxySQL Example](proxy-sql.png) 4 | 5 | A set of CloudFormation templates that demonstrates using ProxySQL middleware to provide a single endpoint for both the primary and read replica instances of an Amazon Aurora MySql-compatible cluster. 6 | 7 | These CloudFormation (CFN) templates deploy an Aurora RDS MySql-compatible 8 | cluster with proxysql middleware. ProxySQL offers a single endpoint that directs traffic 9 | to the RDS cluster endpoint for writes and the RDS reader endpoint for reads. 10 | 11 | The templates also set up a VPC with public and private subnets, security groups that 12 | limit communication, and an ELB to expose the proxysql instance externally. 13 | 14 | ## License Summary 15 | 16 | This sample code is made available under a modified MIT license. See the LICENSE file. 17 | 18 | ## Setup 19 | 20 | We assume that you have the AWS CLI installed and configured. Create an S3 bucket 21 | to contain the CFN templates. We'll refer to this as `templatebucket`. 22 | 23 | In the scripts `create.sh` and `update.sh`, review and update the parameters. You must 24 | put in your own SSH key name in the `keyname` parameter, and we strongly encourage you to 25 | change the `AllowedCidrIngress` from the default of `0.0.0.0/0`. 26 | 27 | ## Create the CFN stack 28 | 29 | Run: 30 | 31 | ./create.sh templatebucket proxysql proxysqlstack us-west-2 32 | 33 | Use your AWS region of choice if you don't want to run in `us-west-2`. 34 | 35 | ## Updating the stack 36 | 37 | You can run the following to update the stack if you change the configuration: 38 | 39 | ./update.sh templatebucket proxysql proxysqlstack us-west-2 40 | 41 | ## Using the stack 42 | 43 | Look for the stack output parameter `Endpoint`. You can use `Endpoint:3306` as your 44 | MySql-compatible connection host. 45 | 46 | ## License Summary 47 | 48 | This sample code is made available under a modified MIT license. See the LICENSE file. 49 | -------------------------------------------------------------------------------- /aurora.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | AWSTemplateFormatVersion: "2010-09-09" 5 | 6 | Parameters: 7 | DatabaseName: 8 | Type: String 9 | Default: proxysqlexample 10 | MinLength: 1 11 | MaxLength: 64 12 | AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*" 13 | DatabaseUser: 14 | Type: String 15 | MinLength: 1 16 | MaxLength: 16 17 | Default: proxysql 18 | AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*" 19 | DatabasePassword: 20 | Type: String 21 | MinLength: 8 22 | MaxLength: 41 23 | Default: pr0xySQL01Cred 24 | NoEcho: true 25 | AllowedPattern: "[a-zA-Z0-9]*" 26 | DbInstanceSize: 27 | Type: String 28 | Description: Database instance size 29 | AllowedValues: 30 | - db.r5.large 31 | - db.r5.xlarge 32 | - db.r5.2xlarge 33 | - db.r5.4xlarge 34 | - db.r5.8xlarge 35 | - db.r5.16xlarge 36 | Default: "db.r5.large" 37 | ProjectTag: 38 | Type: String 39 | Description: Tag to apply to created resources for visibility 40 | Default: ProxySQLDemo 41 | SubnetPrivateA: 42 | Description: "First private subnet" 43 | Type: "AWS::EC2::Subnet::Id" 44 | SubnetPrivateB: 45 | Description: "Second private subnet" 46 | Type: "AWS::EC2::Subnet::Id" 47 | DBFirewall: 48 | Type: String 49 | Resources: 50 | DBAuroraCluster: 51 | Type: "AWS::RDS::DBCluster" 52 | DependsOn: DBClusterParams 53 | Properties: 54 | DatabaseName: !Ref DatabaseName 55 | Engine: aurora-mysql 56 | MasterUsername: !Ref DatabaseUser 57 | MasterUserPassword: !Ref DatabasePassword 58 | DBSubnetGroupName: !Ref DBSubnets 59 | DBClusterParameterGroupName: !Ref DBClusterParams 60 | VpcSecurityGroupIds: 61 | - !Ref DBFirewall 62 | Tags: 63 | - Key: Project 64 | Value: !Ref ProjectTag 65 | DBAuroraOne: 66 | Type : "AWS::RDS::DBInstance" 67 | DependsOn: DBParamGroup 68 | Properties: 69 | DBClusterIdentifier: !Ref DBAuroraCluster 70 | Engine: aurora-mysql 71 | DBInstanceClass: !Ref DbInstanceSize 72 | DBSubnetGroupName: !Ref DBSubnets 73 | DBParameterGroupName: !Ref DBParamGroup 74 | Tags: 75 | - Key: Project 76 | Value: !Ref ProjectTag 77 | DBAuroraTwo: 78 | Type : "AWS::RDS::DBInstance" 79 | DependsOn: DBParamGroup 80 | Properties: 81 | DBClusterIdentifier: !Ref DBAuroraCluster 82 | Engine: aurora-mysql 83 | DBInstanceClass: !Ref DbInstanceSize 84 | DBSubnetGroupName: !Ref DBSubnets 85 | DBParameterGroupName: !Ref DBParamGroup 86 | Tags: 87 | - Key: Project 88 | Value: !Ref ProjectTag 89 | DBAuroraThree: 90 | Type : "AWS::RDS::DBInstance" 91 | DependsOn: DBParamGroup 92 | Properties: 93 | DBClusterIdentifier: !Ref DBAuroraCluster 94 | Engine: aurora-mysql 95 | DBInstanceClass: !Ref DbInstanceSize 96 | DBSubnetGroupName: !Ref DBSubnets 97 | DBParameterGroupName: !Ref DBParamGroup 98 | Tags: 99 | - Key: Project 100 | Value: !Ref ProjectTag 101 | DBSubnets: 102 | Type: "AWS::RDS::DBSubnetGroup" 103 | Properties: 104 | DBSubnetGroupDescription: "Subnets for RDS cluster" 105 | SubnetIds: 106 | - !Ref SubnetPrivateA 107 | - !Ref SubnetPrivateB 108 | Tags: 109 | - Key: Project 110 | Value: !Ref ProjectTag 111 | DBParamGroup: 112 | Type: "AWS::RDS::DBParameterGroup" 113 | Properties: 114 | Description: Moodle Parameter Group 115 | Family: aurora-mysql5.7 116 | Parameters: 117 | innodb_file_format: Barracuda 118 | innodb_large_prefix: 1 119 | Tags: 120 | - Key: Project 121 | Value: !Ref ProjectTag 122 | DBClusterParams: 123 | Type: "AWS::RDS::DBClusterParameterGroup" 124 | Properties: 125 | Parameters: 126 | innodb_file_per_table: 1 127 | character_set_database: utf8mb4 128 | Family: aurora-mysql5.7 129 | Description: Moodle Cluster Parameter Group 130 | Tags: 131 | - Key: Project 132 | Value: !Ref ProjectTag 133 | 134 | 135 | Outputs: 136 | DBClusterEndpoint: 137 | Description: Aurora cluster endpoint 138 | Value: !GetAtt DBAuroraCluster.Endpoint.Address 139 | DBReadEndpoint: 140 | Description: Aurora cluster read endpoint 141 | Value: !GetAtt DBAuroraCluster.ReadEndpoint.Address 142 | -------------------------------------------------------------------------------- /create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | # SPDX-License-Identifier: MIT-0 5 | 6 | templatebucket=$1 7 | templateprefix=$2 8 | stackname=$3 9 | region=$4 10 | SCRIPTDIR=`dirname $0` 11 | if [ "$templatebucket" == "" ] 12 | then 13 | echo "Usage: $0