class ServerlessCluster (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.RDS.ServerlessCluster |
Java | software.amazon.awscdk.services.rds.ServerlessCluster |
Python | aws_cdk.aws_rds.ServerlessCluster |
TypeScript (source) | @aws-cdk/aws-rds » ServerlessCluster |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IServerless
, IConnectable
, ISecret
Create an Aurora Serverless Cluster.
Example
declare const vpc: ec2.Vpc;
const cluster = new rds.ServerlessCluster(this, 'AnotherCluster', {
engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
vpc, // this parameter is optional for serverless Clusters
enableDataApi: true, // Optional - will be automatically set if you call grantDataApiAccess()
});
declare const code: lambda.Code;
const fn = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code,
environment: {
CLUSTER_ARN: cluster.clusterArn,
SECRET_ARN: cluster.secret!.secretArn,
},
});
cluster.grantDataApiAccess(fn);
Initializer
new ServerlessCluster(scope: Construct, id: string, props: ServerlessClusterProps)
Parameters
- scope
Construct
- id
string
- props
Serverless
Cluster Props
Construct Props
Name | Type | Description |
---|---|---|
engine | ICluster | What kind of database to start. |
backup | Duration | The number of days during which automatic DB snapshots are retained. |
cluster | string | An optional identifier for the cluster. |
credentials? | Credentials | Credentials for the administrative user. |
default | string | Name of a database which is automatically created inside the cluster. |
deletion | boolean | Indicates whether the DB cluster should have deletion protection enabled. |
enable | boolean | Whether to enable the Data API. |
parameter | IParameter | Additional parameters to pass to the database engine. |
removal | Removal | The removal policy to apply when the cluster and its instances are removed from the stack or replaced during an update. |
scaling? | Serverless | Scaling configuration of an Aurora Serverless database cluster. |
security | ISecurity [] | Security group. |
storage | IKey | The KMS key for storage encryption. |
subnet | ISubnet | Existing subnet group for the cluster. |
vpc? | IVpc | The VPC that this Aurora Serverless cluster has been created in. |
vpc | Subnet | Where to place the instances within the VPC. |
engine
Type:
ICluster
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.
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:
IParameter
(optional, default: no parameter group.)
Additional parameters to pass to the database engine.
removalPolicy?
Type:
Removal
(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:
Serverless
(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:
ISecurity
[]
(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:
ISubnet
(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:
Subnet
(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
Name | Type | Description |
---|---|---|
cluster | string | The ARN of the cluster. |
cluster | Endpoint | The endpoint to use for read/write operations. |
cluster | string | Identifier of the cluster. |
cluster | Endpoint | The endpoint to use for read/write operations. |
connections | Connections | Access to the network connections. |
env | Resource | The environment this resource belongs to. |
new | Cfn | |
node | Construct | The construct tree node associated with this construct. |
security | ISecurity [] | |
stack | Stack | The stack in which this resource is defined. |
enable | boolean | |
secret? | ISecret | The 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:
Resource
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:
Cfn
node
Type:
Construct
The construct tree node associated with this construct.
securityGroups
Type:
ISecurity
[]
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
Name | Description |
---|---|
add | Adds the multi user rotation to this cluster. |
add | Adds the single user rotation of the master password to this cluster. |
apply | Apply the given removal policy to this resource. |
as | Renders the secret attachment target specifications. |
grant | Grant the given identity to access to the Data API, including read access to the secret attached to the cluster if present. |
to | Returns a string representation of this construct. |
static from | Import an existing DatabaseCluster from properties. |
RotationMultiUser(id, options)
addpublic addRotationMultiUser(id: string, options: RotationMultiUserOptions): SecretRotation
Parameters
- id
string
- options
Rotation
Multi User Options
Returns
Adds the multi user rotation to this cluster.
RotationSingleUser(options?)
addpublic addRotationSingleUser(options?: RotationSingleUserOptions): SecretRotation
Parameters
- options
Rotation
Single User Options
Returns
Adds the single user rotation of the master password to this cluster.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
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
).
SecretAttachmentTarget()
aspublic asSecretAttachmentTarget(): SecretAttachmentTargetProps
Returns
Renders the secret attachment target specifications.
DataApiAccess(grantee)
grantpublic grantDataApiAccess(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— The principal to grant access to.
Returns
Grant the given identity to access to the Data API, including read access to the secret attached to the cluster if present.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
ServerlessClusterAttributes(scope, id, attrs)
static frompublic static fromServerlessClusterAttributes(scope: Construct, id: string, attrs: ServerlessClusterAttributes): IServerlessCluster
Parameters
- scope
Construct
- id
string
- attrs
Serverless
Cluster Attributes
Returns
Import an existing DatabaseCluster from properties.