Skip to main content

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

aws-cdk.aws-rds-0.30.0.tar.gz (115.9 kB view hashes)

Uploaded Source

Built Distribution

aws_cdk.aws_rds-0.30.0-py3-none-any.whl (114.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page