CDK Constructs for AWS RDS
Project description
AWS RDS Construct Library
The aws-cdk-rds
package contains Constructs for setting up RDS instances.
Note: the functionality this package is currently limited, as the CDK team is focusing on other use cases first. If your use case is not listed below, you will have to use achieve it using CloudFormation resources.
If you would like to help improve the state of this library, Pull Requests are welcome.
Supported:
- Clustered databases
Not supported:
- Instance databases
- Setting up from a snapshot
Starting a Clustered Database
To set up a clustered database (like Aurora), create an instance of DatabaseCluster
. You must
always launch a database in a VPC. Use the vpcSubnets
attribute to control whether
your instances will be launched privately or publicly:
const cluster = new DatabaseCluster(this, 'Database', {
engine: DatabaseClusterEngine.Aurora,
masterUser: {
username: 'admin'
},
instanceProps: {
instanceType: new InstanceTypePair(InstanceClass.Burstable2, InstanceSize.Small),
vpcSubnets: {
subnetType: ec2.SubnetType.Public,
},
vpc
}
});
By default, the master password will be generated and stored in AWS Secrets Manager.
Your cluster will be empty by default. To add a default database upon construction, specify the
defaultDatabaseName
attribute.
Connecting
To control who can access the cluster, use the .connections
attribute. RDS database have
a default port, so you don't need to specify the port:
cluster.connections.allowFromAnyIpv4('Open to the world');
The endpoints to access your database will be available as the .clusterEndpoint
and .readerEndpoint
attributes:
const writeAddress = cluster.clusterEndpoint.socketAddress; // "HOSTNAME:PORT"
Rotating master password
When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:
const cluster = new rds.DatabaseCluster(stack, 'Database', {
engine: rds.DatabaseClusterEngine.Aurora,
masterUser: {
username: 'admin'
},
instanceProps: {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small),
vpc
}
});
cluster.addRotationSingleUser('Rotation');
Rotation of the master password is also supported for an existing cluster:
new RotationSingleUser(stack, 'Rotation', {
secret: importedSecret,
engine: DatabaseEngine.Oracle,
target: importedCluster,
vpc: importedVpc,
})
The importedSecret
must be a JSON string with the following format:
{
"engine": "<required: database engine>",
"host": "<required: instance host name>",
"username": "<required: username>",
"password": "<required: password>",
"dbname": "<optional: database name>",
"port": "<optional: if not specified, default port will be used>"
}
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
Hashes for aws_cdk.aws_rds-0.33.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 461c854f2b54ee3b69843a2c47806b4fe7b039af2d72d86f6ab46a7ae14e1916 |
|
MD5 | 0ad59c336e0aa3747202540d99ef8596 |
|
BLAKE2b-256 | 98719e518a5da255278554323b47da35c8e890b60b8dbaf4fd0257bbabaf89a1 |