aws-cdk-lib.aws_rds.ServerlessCluster

class ServerlessCluster (construct)

LanguageType name
.NETAmazon.CDK.AWS.RDS.ServerlessCluster
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsrds#ServerlessCluster
Javasoftware.amazon.awscdk.services.rds.ServerlessCluster
Pythonaws_cdk.aws_rds.ServerlessCluster
TypeScript (source)aws-cdk-lib » aws_rds » ServerlessCluster

Implements IConstruct, IDependable, IResource, IServerlessCluster, IConnectable, ISecretAttachmentTarget

Create an Aurora Serverless Cluster.

Example

// Create username and password secret for DB Cluster
const secret = new rds.DatabaseSecret(this, 'AuroraSecret', {
  username: 'clusteradmin',
});

// The VPC to place the cluster in
const vpc = new ec2.Vpc(this, 'AuroraVpc');

// Create the serverless cluster, provide all values needed to customise the database.
const cluster = new rds.ServerlessCluster(this, 'AuroraCluster', {
  engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
  vpc,
  credentials: { username: 'clusteradmin' },
  clusterIdentifier: 'db-endpoint-test',
  defaultDatabaseName: 'demos',
});

// Build a data source for AppSync to access the database.
declare const api: appsync.GraphqlApi;
const rdsDS = api.addRdsDataSource('rds', cluster, secret, 'demos');

// Set up a resolver for an RDS query.
rdsDS.createResolver('QueryGetDemosRdsResolver', {
  typeName: 'Query',
  fieldName: 'getDemosRds',
  requestMappingTemplate: appsync.MappingTemplate.fromString(`
  {
    "version": "2018-05-29",
    "statements": [
      "SELECT * FROM demos"
    ]
  }
  `),
  responseMappingTemplate: appsync.MappingTemplate.fromString(`
    $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
  `),
});

// Set up a resolver for an RDS mutation.
rdsDS.createResolver('MutationAddDemoRdsResolver', {
  typeName: 'Mutation',
  fieldName: 'addDemoRds',
  requestMappingTemplate: appsync.MappingTemplate.fromString(`
  {
    "version": "2018-05-29",
    "statements": [
      "INSERT INTO demos VALUES (:id, :version)",
      "SELECT * WHERE id = :id"
    ],
    "variableMap": {
      ":id": $util.toJson($util.autoId()),
      ":version": $util.toJson($ctx.args.version)
    }
  }
  `),
  responseMappingTemplate: appsync.MappingTemplate.fromString(`
    $utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
  `),
});

Initializer

new ServerlessCluster(scope: Construct, id: string, props: ServerlessClusterProps)

Parameters

  • scope Construct
  • id string
  • props ServerlessClusterProps

Construct Props

NameTypeDescription
engineIClusterEngineWhat kind of database to start.
backupRetention?DurationThe number of days during which automatic DB snapshots are retained.
clusterIdentifier?stringAn optional identifier for the cluster.
copyTagsToSnapshot?booleanWhether to copy tags to the snapshot when a snapshot is created.
credentials?CredentialsCredentials for the administrative user.
defaultDatabaseName?stringName of a database which is automatically created inside the cluster.
deletionProtection?booleanIndicates whether the DB cluster should have deletion protection enabled.
enableDataApi?booleanWhether to enable the Data API.
parameterGroup?IParameterGroupAdditional parameters to pass to the database engine.
removalPolicy?RemovalPolicyThe removal policy to apply when the cluster and its instances are removed from the stack or replaced during an update.
scaling?ServerlessScalingOptionsScaling configuration of an Aurora Serverless database cluster.
securityGroups?ISecurityGroup[]Security group.
storageEncryptionKey?IKeyThe KMS key for storage encryption.
subnetGroup?ISubnetGroupExisting subnet group for the cluster.
vpc?IVpcThe VPC that this Aurora Serverless cluster has been created in.
vpcSubnets?SubnetSelectionWhere to place the instances within the VPC.

engine

Type: IClusterEngine

What kind of database to start.


backupRetention?

Type: Duration (optional, default: Duration.days(1))

The number of days during which automatic DB snapshots are retained.

Automatic backup retention cannot be disabled on serverless clusters. Must be a value from 1 day to 35 days.


clusterIdentifier?

Type: string (optional, default: A name is automatically generated.)

An optional identifier for the cluster.


copyTagsToSnapshot?

Type: boolean (optional, default: true)

Whether to copy tags to the snapshot when a snapshot is created.


credentials?

Type: Credentials (optional, default: A username of 'admin' and SecretsManager-generated password)

Credentials for the administrative user.


defaultDatabaseName?

Type: string (optional, default: Database is not created in cluster.)

Name of a database which is automatically created inside the cluster.


deletionProtection?

Type: boolean (optional, default: true if removalPolicy is RETAIN, false otherwise)

Indicates whether the DB cluster should have deletion protection enabled.


enableDataApi?

Type: boolean (optional, default: false)

Whether to enable the Data API.

See also: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html


parameterGroup?

Type: IParameterGroup (optional, default: no parameter group.)

Additional parameters to pass to the database engine.


removalPolicy?

Type: RemovalPolicy (optional, default: RemovalPolicy.SNAPSHOT (remove the cluster and instances, but retain a snapshot of the data))

The removal policy to apply when the cluster and its instances are removed from the stack or replaced during an update.


scaling?

Type: ServerlessScalingOptions (optional, default: Serverless cluster is automatically paused after 5 minutes of being idle. minimum capacity: 2 ACU maximum capacity: 16 ACU)

Scaling configuration of an Aurora Serverless database cluster.


securityGroups?

Type: ISecurityGroup[] (optional, default: a new security group is created if vpc was provided. If the vpc property was not provided, no VPC security groups will be associated with the DB cluster.)

Security group.


storageEncryptionKey?

Type: IKey (optional, default: the default master key will be used for storage encryption)

The KMS key for storage encryption.


subnetGroup?

Type: ISubnetGroup (optional, default: a new subnet group is created if vpc was provided. If the vpc property was not provided, no subnet group will be associated with the DB cluster)

Existing subnet group for the cluster.


vpc?

Type: IVpc (optional, default: the default VPC in the account and region will be used)

The VPC that this Aurora Serverless cluster has been created in.


vpcSubnets?

Type: SubnetSelection (optional, default: the VPC default strategy if not specified.)

Where to place the instances within the VPC.

If provided, the vpc property must also be specified.

Properties

NameTypeDescription
clusterArnstringThe ARN of the cluster.
clusterEndpointEndpointThe endpoint to use for read/write operations.
clusterIdentifierstringIdentifier of the cluster.
clusterReadEndpointEndpointThe endpoint to use for read/write operations.
connectionsConnectionsAccess to the network connections.
envResourceEnvironmentThe environment this resource belongs to.
newCfnPropsCfnDBClusterProps
nodeNodeThe tree node.
securityGroupsISecurityGroup[]
stackStackThe stack in which this resource is defined.
enableDataApi?boolean
secret?ISecretThe secret attached to this cluster.

clusterArn

Type: string

The ARN of the cluster.


clusterEndpoint

Type: Endpoint

The endpoint to use for read/write operations.


clusterIdentifier

Type: string

Identifier of the cluster.


clusterReadEndpoint

Type: Endpoint

The endpoint to use for read/write operations.


connections

Type: Connections

Access to the network connections.


env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


newCfnProps

Type: CfnDBClusterProps


node

Type: Node

The tree node.


securityGroups

Type: ISecurityGroup[]


stack

Type: Stack

The stack in which this resource is defined.


enableDataApi?

Type: boolean (optional)


secret?

Type: ISecret (optional)

The secret attached to this cluster.

Methods

NameDescription
addRotationMultiUser(id, options)Adds the multi user rotation to this cluster.
addRotationSingleUser(options?)Adds the single user rotation of the master password to this cluster.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
asSecretAttachmentTarget()Renders the secret attachment target specifications.
grantDataApiAccess(grantee)Grant the given identity to access to the Data API, including read access to the secret attached to the cluster if present.
toString()Returns a string representation of this construct.
static fromServerlessClusterAttributes(scope, id, attrs)Import an existing DatabaseCluster from properties.

addRotationMultiUser(id, options)

public addRotationMultiUser(id: string, options: RotationMultiUserOptions): SecretRotation

Parameters

  • id string
  • options RotationMultiUserOptions

Returns

  • SecretRotation

Adds the multi user rotation to this cluster.


addRotationSingleUser(options?)

public addRotationSingleUser(options?: RotationSingleUserOptions): SecretRotation

Parameters

  • options RotationSingleUserOptions

Returns

  • SecretRotation

Adds the single user rotation of the master password to this cluster.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


asSecretAttachmentTarget()

public asSecretAttachmentTarget(): SecretAttachmentTargetProps

Returns

  • SecretAttachmentTargetProps

Renders the secret attachment target specifications.


grantDataApiAccess(grantee)

public grantDataApiAccess(grantee: IGrantable): Grant

Parameters

  • grantee IGrantable — The principal to grant access to.

Returns

  • Grant

Grant the given identity to access to the Data API, including read access to the secret attached to the cluster if present.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromServerlessClusterAttributes(scope, id, attrs)

public static fromServerlessClusterAttributes(scope: Construct, id: string, attrs: ServerlessClusterAttributes): IServerlessCluster

Parameters

  • scope Construct
  • id string
  • attrs ServerlessClusterAttributes

Returns

  • IServerlessCluster

Import an existing DatabaseCluster from properties.