cdk-aurora-globaldatabase is an AWS CDK construct library that provides Cross Region Create Global Aurora RDS Databases.
Project description
cdk-aurora-globaldatabase
cdk-aurora-globaldatabase
is an AWS CDK construct library that allows you to create Amazon Aurora Global Databases with AWS CDK in Typescript or Python.
Why
Amazon Aurora Global Databases is designed for multi-regional Amazon Aurora Database clusters that span across different AWS regions. Due to the lack of native cloudformation support, it has been very challenging to build with cloudformation or AWS CDK with the upstream aws-rds
construct.
cdk-aurora-globaldatabase
aims to offload the heavy-lifting and helps you provision and deploy cross-regional Amazon Aurora Global Databases simply with just a few CDK statements.
Install
Use the npm dist tag to opt in CDKv1 or CDKv2:
// for CDKv2
npm install cdk-aurora-globaldatabase
or
npm install cdk-aurora-globaldatabase@latest
// for CDKv1
npm install cdk-aurora-globaldatabase@cdkv1
⛔️ Please do not use cdk v1, because lot of db engine version already not been update in @aws-cdk/aws-rds upstream. ⛔️
Now Try It !!!
Sample for Mysql
import { GlobalAuroraRDSMaster, InstanceTypeEnum, GlobalAuroraRDSSlaveInfra } from 'cdk-aurora-globaldatabase';
import { App, Stack, CfnOutput } from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
// new app .
const mockApp = new App();
// setting two region env config .
const envSingapro = { account: process.env.CDK_DEFAULT_ACCOUNT, region: 'ap-southeast-1' };
const envTokyo = { account: process.env.CDK_DEFAULT_ACCOUNT, region: 'ap-northeast-1' };
// create stack main .
const stackM = new Stack(mockApp, 'testing-stackM',{env: envTokyo});
const vpcPublic = new ec2.Vpc(stackM,'defaultVpc',{
natGateways: 0,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 26,
name: 'masterVPC2',
subnetType: ec2.SubnetType.PUBLIC,
}],
});
const globaldbM = new GlobalAuroraRDSMaster(stackM, 'globalAuroraRDSMaster',{
instanceType: InstanceTypeEnum.R5_LARGE,
vpc: vpcPublic,
rdsPassword: '1qaz2wsx',
});
globaldbM.rdsCluster.connections.allowDefaultPortFrom(ec2.Peer.ipv4(`${process.env.MYIP}/32`))
// create stack slave infra or you can give your subnet group.
const stackS = new Stack(mockApp, 'testing-stackS',{env: envSingapro});
const vpcPublic2 = new ec2.Vpc(stackS,'defaultVpc2',{
natGateways: 0,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 26,
name: 'secondVPC2',
subnetType: ec2.SubnetType.PUBLIC,
}],
});
const globaldbS = new GlobalAuroraRDSSlaveInfra(stackS, 'slaveregion',{vpc: vpcPublic2,subnetType:ec2.SubnetType.PUBLIC });
// so we need to wait stack slave created first .
stackM.addDependency(stackS)
new CfnOutput(stackM, 'password', { value: globaldbM.rdsPassword });
// add second region cluster
globaldbM.addRegionalCluster(stackM,'addregionalrds',{
region: 'ap-southeast-1',
dbSubnetGroupName: globaldbS.dbSubnetGroup.dbSubnetGroupName,
});
Sample for Postgres
import { GlobalAuroraRDSMaster, InstanceTypeEnum, GlobalAuroraRDSSlaveInfra } from 'cdk-aurora-globaldatabase';
import { App, Stack, CfnOutput } from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as _rds from 'aws-cdk-lib/aws-rds';
const mockApp = new App();
const envSingapro = { account: process.env.CDK_DEFAULT_ACCOUNT, region: 'ap-southeast-1' };
const envTokyo = { account: process.env.CDK_DEFAULT_ACCOUNT, region: 'ap-northeast-1' };
const stackM = new Stack(mockApp, 'testing-stackM',{env: envTokyo});
const vpcPublic = new ec2.Vpc(stackM,'defaultVpc',{
natGateways: 0,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 26,
name: 'masterVPC2',
subnetType: ec2.SubnetType.PUBLIC,
}],
});
// Note if you use postgres , need to give the same value in engineVersion and dbClusterpPG's engine .
const globaldbM = new GlobalAuroraRDSMaster(stackM, 'globalAuroraRDSMaster',{
instanceType: InstanceTypeEnum.R5_LARGE,
vpc: vpcPublic,
rdsPassword: '1qaz2wsx',
engineVersion: _rds.DatabaseClusterEngine.auroraPostgres({
version: _rds.AuroraPostgresEngineVersion.VER_12_11}),
dbClusterpPG: new _rds.ParameterGroup(stackM, 'dbClusterparametergroup', {
engine: _rds.DatabaseClusterEngine.auroraPostgres({
version: _rds.AuroraPostgresEngineVersion.VER_12_11,
}),
parameters: {
'rds.force_ssl': '1',
'rds.log_retention_period': '10080',
'auto_explain.log_min_duration': '5000',
'auto_explain.log_verbose': '1',
'timezone': 'UTC+8',
'shared_preload_libraries': 'auto_explain,pg_stat_statements,pg_hint_plan,pgaudit',
'log_connections': '1',
'log_statement': 'ddl',
'log_disconnections': '1',
'log_lock_waits': '1',
'log_min_duration_statement': '5000',
'log_rotation_age': '1440',
'log_rotation_size': '102400',
'random_page_cost': '1',
'track_activity_query_size': '16384',
'idle_in_transaction_session_timeout': '7200000',
},
}),
});
globaldbM.rdsCluster.connections.allowDefaultPortFrom(ec2.Peer.ipv4(`${process.env.MYIP}/32`))
const stackS = new Stack(mockApp, 'testing-stackS',{env: envSingapro});
const vpcPublic2 = new ec2.Vpc(stackS,'defaultVpc2',{
natGateways: 0,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 26,
name: 'secondVPC2',
subnetType: ec2.SubnetType.PUBLIC,
}],
});
const globaldbS = new GlobalAuroraRDSSlaveInfra(stackS, 'slaveregion',{
vpc: vpcPublic2,subnetType:ec2.SubnetType.PUBLIC,
});
stackM.addDependency(stackS)
new CfnOutput(stackM, 'password', { value: globaldbM.rdsPassword });
// add second region cluster
globaldbM.addRegionalCluster(stackM,'addregionalrds',{
region: 'ap-southeast-1',
dbSubnetGroupName: globaldbS.dbSubnetGroup.dbSubnetGroupName,
});
To deploy
cdk deploy
To destroy
cdk destroy
:clap: Supporters
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cdk_aurora_globaldatabase-2.3.658.tar.gz
.
File metadata
- Download URL: cdk_aurora_globaldatabase-2.3.658.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd676ec7ae107d97dc2f5a171d9f04b42e6ddb24f613d3137634891ff057e84d |
|
MD5 | b9f1254213ceefeb9df8ea6b82233574 |
|
BLAKE2b-256 | ebe77cae8c3b9ff6fd70d250b676d587cb56eedf63f87f1b738b28b3b702cfa4 |
File details
Details for the file cdk_aurora_globaldatabase-2.3.658-py3-none-any.whl
.
File metadata
- Download URL: cdk_aurora_globaldatabase-2.3.658-py3-none-any.whl
- Upload date:
- Size: 75.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b62c87ed2307a5f06de8589f8a3849b36e4030fb40ae5201208489a3a19bcfdb |
|
MD5 | 0886909c3badb154a5601431dab596df |
|
BLAKE2b-256 | 410a438a53f35d556d19d6cdbcd3ee1c28fdb662f6b9d5a88a8cfbe83b514ee8 |