├── .github └── PULL_REQUEST_TEMPLATE.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── aurora.yaml ├── create.sh ├── master.yaml ├── network.yaml ├── pgpool.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 | -------------------------------------------------------------------------------- /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-pgpool-example/issues), or [recently closed](https://github.com/aws-samples/amazon-aurora-pgpool-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-pgpool-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-pgpool-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 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 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Code for "A single endpoint for reads and writes with PostgreSQL-compatible Amazon Aurora RDS" 2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Amazon Aurora Pgpool example 2 | 3 | A set of CloudFormation templates that demonstrates using pgool middleware to provide a single endpoint for both the primary and read replica instances of an Amazon Aurora PostgreSQL-compatible cluster. 4 | 5 | These CloudFormation (CFN) templates deploy an Aurora RDS PostgreSQL-compatible 6 | cluster with pgpool middleware. pgpool offers a single endpoint that directs traffic 7 | to the RDS cluster endpoint for writes and the RDS reader endpoint for reads. 8 | 9 | The templates also set up a VPC with public and private subnets, security groups that 10 | limit communication, and an ELB to expose the pgpool instance externally. 11 | 12 | ## License Summary 13 | 14 | This sample code is made available under a modified MIT license. See the LICENSE file. 15 | 16 | ## Setup 17 | 18 | We assume that you have the AWS CLI installed and configured. Create an S3 bucket 19 | to contain the CFN templates. We'll refer to this as `templatebucket`. 20 | 21 | In the scripts `create.sh` and `update.sh`, review and update the parameters. You must 22 | put in your own SSH key name in the `keyname` parameter, and we strongly encourage you to 23 | change the `AllowedCidrIngress` from the default of `0.0.0.0/0`. 24 | 25 | ## Create the CFN stack 26 | 27 | Run: 28 | 29 | ./create.sh templatebucket pgpool pgpoolstack us-west-2 30 | 31 | Use your AWS region of choice if you don't want to run in `us-west-2`. 32 | 33 | ## Updating the stack 34 | 35 | You can run the following to update the stack if you change the configuration: 36 | 37 | ./update.sh templatebucket pgpool pgpoolstack us-west-2 38 | 39 | ## Using the stack 40 | 41 | Look for the stack output parameter `Endpoint`. You can use `Endpoint:5432` as your 42 | PostgreSQL-compatible connection host. 43 | -------------------------------------------------------------------------------- /aurora.yaml: -------------------------------------------------------------------------------- 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 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 | 16 | 17 | Parameters: 18 | DatabaseName: 19 | Type: String 20 | Default: pgpoolexample 21 | MinLength: 1 22 | MaxLength: 64 23 | AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*" 24 | DatabaseUser: 25 | Type: String 26 | MinLength: 1 27 | MaxLength: 16 28 | Default: pgpool 29 | AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*" 30 | DatabasePassword: 31 | Type: String 32 | MinLength: 8 33 | MaxLength: 41 34 | Default: pgp0o1Cred 35 | NoEcho: true 36 | AllowedPattern: "[a-zA-Z0-9]*" 37 | DbInstanceSize: 38 | Type: String 39 | Description: Database instance size 40 | AllowedValues: 41 | - db.r4.large 42 | - db.r4.xlarge 43 | - db.r4.2xlarge 44 | - db.r4.4xlarge 45 | - db.r4.8xlarge 46 | - db.r4.16xlarge 47 | Default: "db.r4.large" 48 | ProjectTag: 49 | Type: String 50 | Description: Tag to apply to created resources for visibility 51 | Default: PgPoolDemo 52 | SubnetPrivateA: 53 | Description: "First private subnet" 54 | Type: "AWS::EC2::Subnet::Id" 55 | SubnetPrivateB: 56 | Description: "Second private subnet" 57 | Type: "AWS::EC2::Subnet::Id" 58 | DBFirewall: 59 | Type: String 60 | Resources: 61 | DBAuroraCluster: 62 | Type: "AWS::RDS::DBCluster" 63 | DependsOn: DBClusterParams 64 | Properties: 65 | DatabaseName: !Ref DatabaseName 66 | Engine: aurora-postgresql 67 | EngineVersion: 11.9 68 | MasterUsername: !Ref DatabaseUser 69 | MasterUserPassword: !Ref DatabasePassword 70 | DBSubnetGroupName: !Ref DBSubnets 71 | DBClusterParameterGroupName: !Ref DBClusterParams 72 | VpcSecurityGroupIds: 73 | - !Ref DBFirewall 74 | Tags: 75 | - Key: Project 76 | Value: !Ref ProjectTag 77 | DBAuroraOne: 78 | Type : "AWS::RDS::DBInstance" 79 | DependsOn: DBParamGroup 80 | Properties: 81 | DBClusterIdentifier: !Ref DBAuroraCluster 82 | Engine: aurora-postgresql 83 | EngineVersion: 11.9 84 | DBInstanceClass: !Ref DbInstanceSize 85 | DBSubnetGroupName: !Ref DBSubnets 86 | DBParameterGroupName: !Ref DBParamGroup 87 | Tags: 88 | - Key: Project 89 | Value: !Ref ProjectTag 90 | DBAuroraTwo: 91 | Type : "AWS::RDS::DBInstance" 92 | DependsOn: DBParamGroup 93 | Properties: 94 | DBClusterIdentifier: !Ref DBAuroraCluster 95 | Engine: aurora-postgresql 96 | EngineVersion: 11.9 97 | DBInstanceClass: !Ref DbInstanceSize 98 | DBSubnetGroupName: !Ref DBSubnets 99 | DBParameterGroupName: !Ref DBParamGroup 100 | Tags: 101 | - Key: Project 102 | Value: !Ref ProjectTag 103 | DBAuroraThree: 104 | Type : "AWS::RDS::DBInstance" 105 | DependsOn: DBParamGroup 106 | Properties: 107 | DBClusterIdentifier: !Ref DBAuroraCluster 108 | Engine: aurora-postgresql 109 | EngineVersion: 11.9 110 | DBInstanceClass: !Ref DbInstanceSize 111 | DBSubnetGroupName: !Ref DBSubnets 112 | DBParameterGroupName: !Ref DBParamGroup 113 | Tags: 114 | - Key: Project 115 | Value: !Ref ProjectTag 116 | DBSubnets: 117 | Type: "AWS::RDS::DBSubnetGroup" 118 | Properties: 119 | DBSubnetGroupDescription: "Subnets for RDS cluster" 120 | SubnetIds: 121 | - !Ref SubnetPrivateA 122 | - !Ref SubnetPrivateB 123 | Tags: 124 | - Key: Project 125 | Value: !Ref ProjectTag 126 | DBParamGroup: 127 | Type: "AWS::RDS::DBParameterGroup" 128 | Properties: 129 | Description: Parameter group for RDS cluster 130 | Family: aurora-postgresql11 131 | Tags: 132 | - Key: Project 133 | Value: !Ref ProjectTag 134 | DBClusterParams: 135 | Type: "AWS::RDS::DBClusterParameterGroup" 136 | Properties: 137 | Description: Parameter group for RDS cluster 138 | Family: aurora-postgresql11 139 | Parameters: 140 | timezone: "UTC" 141 | Tags: 142 | - Key: Project 143 | Value: !Ref ProjectTag 144 | 145 | Outputs: 146 | DBClusterEndpoint: 147 | Description: Aurora cluster endpoint 148 | Value: !GetAtt DBAuroraCluster.Endpoint.Address 149 | DBReadEndpoint: 150 | Description: Aurora cluster read endpoint 151 | Value: !GetAtt DBAuroraCluster.ReadEndpoint.Address 152 | -------------------------------------------------------------------------------- /create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this 6 | # software and associated documentation files (the "Software"), to deal in the Software 7 | # without restriction, including without limitation the rights to use, copy, modify, 8 | # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 9 | # permit persons to whom the Software is furnished to do so. 10 | # 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 12 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 13 | # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 14 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 15 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 16 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | 18 | templatebucket=$1 19 | templateprefix=$2 20 | stackname=$3 21 | region=$4 22 | SCRIPTDIR=`dirname $0` 23 | if [ "$templatebucket" == "" ] 24 | then 25 | echo "Usage: $0