ServerlessCluster

class aws_cdk.aws_rds.ServerlessCluster(scope, id, *, engine, backup_retention=None, cluster_identifier=None, copy_tags_to_snapshot=None, credentials=None, default_database_name=None, deletion_protection=None, enable_data_api=None, parameter_group=None, removal_policy=None, scaling=None, security_groups=None, storage_encryption_key=None, subnet_group=None, vpc=None, vpc_subnets=None)

Bases: Resource

Create an Aurora Serverless Cluster.

Resource:

AWS::RDS::DBCluster

ExampleMetadata:

infused

Example:

# Build a data source for AppSync to access the database.
# api: appsync.GraphqlApi
# Create username and password secret for DB Cluster
secret = rds.DatabaseSecret(self, "AuroraSecret",
    username="clusteradmin"
)

# The VPC to place the cluster in
vpc = ec2.Vpc(self, "AuroraVpc")

# Create the serverless cluster, provide all values needed to customise the database.
cluster = rds.ServerlessCluster(self, "AuroraCluster",
    engine=rds.DatabaseClusterEngine.AURORA_MYSQL,
    vpc=vpc,
    credentials={"username": "clusteradmin"},
    cluster_identifier="db-endpoint-test",
    default_database_name="demos"
)
rds_dS = api.add_rds_data_source("rds", cluster, secret, "demos")

# Set up a resolver for an RDS query.
rds_dS.create_resolver("QueryGetDemosRdsResolver",
    type_name="Query",
    field_name="getDemosRds",
    request_mapping_template=appsync.MappingTemplate.from_string("""
          {
            "version": "2018-05-29",
            "statements": [
              "SELECT * FROM demos"
            ]
          }
          """),
    response_mapping_template=appsync.MappingTemplate.from_string("""
            $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
          """)
)

# Set up a resolver for an RDS mutation.
rds_dS.create_resolver("MutationAddDemoRdsResolver",
    type_name="Mutation",
    field_name="addDemoRds",
    request_mapping_template=appsync.MappingTemplate.from_string("""
          {
            "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)
            }
          }
          """),
    response_mapping_template=appsync.MappingTemplate.from_string("""
            $utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
          """)
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • engine (IClusterEngine) – What kind of database to start.

  • backup_retention (Optional[Duration]) – 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. Default: Duration.days(1)

  • cluster_identifier (Optional[str]) – An optional identifier for the cluster. Default: - A name is automatically generated.

  • copy_tags_to_snapshot (Optional[bool]) – Whether to copy tags to the snapshot when a snapshot is created. Default: - true

  • credentials (Optional[Credentials]) – Credentials for the administrative user. Default: - A username of ‘admin’ and SecretsManager-generated password

  • default_database_name (Optional[str]) – Name of a database which is automatically created inside the cluster. Default: - Database is not created in cluster.

  • deletion_protection (Optional[bool]) – Indicates whether the DB cluster should have deletion protection enabled. Default: - true if removalPolicy is RETAIN, false otherwise

  • enable_data_api (Optional[bool]) – Whether to enable the Data API. Default: false

  • parameter_group (Optional[IParameterGroup]) – Additional parameters to pass to the database engine. Default: - no parameter group.

  • removal_policy (Optional[RemovalPolicy]) – The removal policy to apply when the cluster and its instances are removed from the stack or replaced during an update. Default: - RemovalPolicy.SNAPSHOT (remove the cluster and instances, but retain a snapshot of the data)

  • scaling (Union[ServerlessScalingOptions, Dict[str, Any], None]) – Scaling configuration of an Aurora Serverless database cluster. Default: - Serverless cluster is automatically paused after 5 minutes of being idle. minimum capacity: 2 ACU maximum capacity: 16 ACU

  • security_groups (Optional[Sequence[ISecurityGroup]]) – Security group. 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.

  • storage_encryption_key (Optional[IKey]) – The KMS key for storage encryption. Default: - the default master key will be used for storage encryption

  • subnet_group (Optional[ISubnetGroup]) – Existing subnet group for the cluster. 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

  • vpc (Optional[IVpc]) – The VPC that this Aurora Serverless cluster has been created in. Default: - the default VPC in the account and region will be used

  • vpc_subnets (Union[SubnetSelection, Dict[str, Any], None]) – Where to place the instances within the VPC. If provided, the vpc property must also be specified. Default: - the VPC default strategy if not specified.

Methods

add_rotation_multi_user(id, *, secret, automatically_after=None, endpoint=None, exclude_characters=None, rotate_immediately_on_update=None, security_group=None, vpc_subnets=None)

Adds the multi user rotation to this cluster.

Parameters:
  • id (str) –

  • secret (ISecret) – The secret to rotate. It 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>, “masterarn”: <required: the arn of the master secret which will be used to create users/change passwords> }

  • automatically_after (Optional[Duration]) – Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation. Default: - 30 days

  • endpoint (Optional[IInterfaceVpcEndpoint]) – The VPC interface endpoint to use for the Secrets Manager API. If you enable private DNS hostnames for your VPC private endpoint (the default), you don’t need to specify an endpoint. The standard Secrets Manager DNS hostname the Secrets Manager CLI and SDKs use by default (https://secretsmanager..amazonaws.com) automatically resolves to your VPC endpoint. Default: https://secretsmanager..amazonaws.com

  • exclude_characters (Optional[str]) – Specifies characters to not include in generated passwords. Default: “ %+~`#$&*()|[]{}:;<>?!’/@”"

  • rotate_immediately_on_update (Optional[bool]) – Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. Default: true

  • security_group (Optional[ISecurityGroup]) – The security group for the Lambda rotation function. Default: - a new security group is created

  • vpc_subnets (Union[SubnetSelection, Dict[str, Any], None]) – Where to place the rotation Lambda function. Default: - same placement as instance or cluster

Return type:

SecretRotation

add_rotation_single_user(*, automatically_after=None, endpoint=None, exclude_characters=None, rotate_immediately_on_update=None, security_group=None, vpc_subnets=None)

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

Parameters:
  • automatically_after (Optional[Duration]) – Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation. Default: - 30 days

  • endpoint (Optional[IInterfaceVpcEndpoint]) – The VPC interface endpoint to use for the Secrets Manager API. If you enable private DNS hostnames for your VPC private endpoint (the default), you don’t need to specify an endpoint. The standard Secrets Manager DNS hostname the Secrets Manager CLI and SDKs use by default (https://secretsmanager..amazonaws.com) automatically resolves to your VPC endpoint. Default: https://secretsmanager..amazonaws.com

  • exclude_characters (Optional[str]) – Specifies characters to not include in generated passwords. Default: “ %+~`#$&*()|[]{}:;<>?!’/@”"

  • rotate_immediately_on_update (Optional[bool]) – Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. Default: true

  • security_group (Optional[ISecurityGroup]) – The security group for the Lambda rotation function. Default: - a new security group is created

  • vpc_subnets (Union[SubnetSelection, Dict[str, Any], None]) – Where to place the rotation Lambda function. Default: - same placement as instance or cluster

Return type:

SecretRotation

apply_removal_policy(policy)

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).

Parameters:

policy (RemovalPolicy) –

Return type:

None

as_secret_attachment_target()

Renders the secret attachment target specifications.

Return type:

SecretAttachmentTargetProps

grant_data_api_access(grantee)

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

Parameters:

grantee (IGrantable) – The principal to grant access to.

Return type:

Grant

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

cluster_arn

The ARN of the cluster.

cluster_endpoint

The endpoint to use for read/write operations.

cluster_identifier

Identifier of the cluster.

cluster_read_endpoint

The endpoint to use for read/write operations.

connections

Access to the network connections.

env

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.

node

The tree node.

secret

The secret attached to this cluster.

stack

The stack in which this resource is defined.

Static Methods

classmethod from_serverless_cluster_attributes(scope, id, *, cluster_identifier, cluster_endpoint_address=None, port=None, reader_endpoint_address=None, secret=None, security_groups=None)

Import an existing DatabaseCluster from properties.

Parameters:
  • scope (Construct) –

  • id (str) –

  • cluster_identifier (str) – Identifier for the cluster.

  • cluster_endpoint_address (Optional[str]) – Cluster endpoint address. Default: - no endpoint address

  • port (Union[int, float, None]) – The database port. Default: - none

  • reader_endpoint_address (Optional[str]) – Reader endpoint address. Default: - no reader address

  • secret (Optional[ISecret]) – The secret attached to the database cluster. Default: - no secret

  • security_groups (Optional[Sequence[ISecurityGroup]]) – The security groups of the database cluster. Default: - no security groups

Return type:

IServerlessCluster

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool