Skip to content

Resource: awsLightsailDatabase

Provides a Lightsail Database. Amazon Lightsail is a service to provide easy virtual private servers with custom software already setup. See What is Amazon Lightsail? for more information.

\~> Note: Lightsail is currently only supported in a limited number of AWS Regions, please see "Regions and Availability Zones" for more details

Example Usage

Basic mysql blueprint

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailDatabase.LightsailDatabase(this, "test", {
  availabilityZone: "us-east-1a",
  blueprintId: "mysql_8_0",
  bundleId: "micro_1_0",
  masterDatabaseName: "testdatabasename",
  masterPassword: "testdatabasepassword",
  masterUsername: "test",
  name: "test",
});

Basic postrgres blueprint

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailDatabase.LightsailDatabase(this, "test", {
  availabilityZone: "us-east-1a",
  blueprintId: "postgres_12",
  bundleId: "micro_1_0",
  masterDatabaseName: "testdatabasename",
  masterPassword: "testdatabasepassword",
  masterUsername: "test",
  name: "test",
});

Custom backup and maintenance windows

Below is an example that sets a custom backup and maintenance window. Times are specified in UTC. This example will allow daily backups to take place between 16:00 and 16:30 each day. This example also requires any maintiance tasks (anything that would cause an outage, including changing some attributes) to take place on Tuesdays between 17:00 and 17:30. An action taken against this database that would cause an outage will wait until this time window to make the requested changes.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailDatabase.LightsailDatabase(this, "test", {
  availabilityZone: "us-east-1a",
  blueprintId: "postgres_12",
  bundleId: "micro_1_0",
  masterDatabaseName: "testdatabasename",
  masterPassword: "testdatabasepassword",
  masterUsername: "test",
  name: "test",
  preferredBackupWindow: "16:00-16:30",
  preferredMaintenanceWindow: "Tue:17:00-Tue:17:30",
});

Final Snapshots

To enable creating a final snapshot of your database on deletion, use the finalSnapshotName argument to provide a name to be used for the snapshot.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailDatabase.LightsailDatabase(this, "test", {
  availabilityZone: "us-east-1a",
  blueprintId: "postgres_12",
  bundleId: "micro_1_0",
  finalSnapshotName: "MyFinalSnapshot",
  masterDatabaseName: "testdatabasename",
  masterPassword: "testdatabasepassword",
  masterUsername: "test",
  name: "test",
  preferredBackupWindow: "16:00-16:30",
  preferredMaintenanceWindow: "Tue:17:00-Tue:17:30",
});

Apply Immediately

To enable applying changes immediately instead of waiting for a maintiance window, use the applyImmediately argument.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailDatabase.LightsailDatabase(this, "test", {
  applyImmediately: true,
  availabilityZone: "us-east-1a",
  blueprintId: "postgres_12",
  bundleId: "micro_1_0",
  masterDatabaseName: "testdatabasename",
  masterPassword: "testdatabasepassword",
  masterUsername: "test",
  name: "test",
});

Argument Reference

The following arguments are supported:

  • name - (Required) The name to use for your new Lightsail database resource. Names be unique within each AWS Region in your Lightsail account.
  • availabilityZone - The Availability Zone in which to create your new database. Use the us-east-2a case-sensitive format.
  • masterDatabaseName - (Required) The name of the master database created when the Lightsail database resource is created.
  • masterPassword - (Sensitive) The password for the master user of your new database. The password can include any printable ASCII character except "/", """, or "@".
  • masterUsername - The master user name for your new database.
  • blueprintId - (Required) The blueprint ID for your new database. A blueprint describes the major engine version of a database. You can get a list of database blueprints IDs by using the AWS CLI command: awsLightsailGetRelationalDatabaseBlueprints
  • bundleId - (Required) The bundle ID for your new database. A bundle describes the performance specifications for your database (see list below). You can get a list of database bundle IDs by using the AWS CLI command: awsLightsailGetRelationalDatabaseBundles.
  • preferredBackupWindow - The daily time range during which automated backups are created for your new database if automated backups are enabled. Must be in the hh24:mi-hh24:mi format. Example: 16:0016:30. Specified in Coordinated Universal Time (UTC).
  • preferredMaintenanceWindow - The weekly time range during which system maintenance can occur on your new database. Must be in the ddd:hh24:mi-ddd:hh24:mi format. Specified in Coordinated Universal Time (UTC). Example: tue:17:00Tue:17:30
  • publiclyAccessible - Specifies the accessibility options for your new database. A value of true specifies a database that is available to resources outside of your Lightsail account. A value of false specifies a database that is available only to your Lightsail resources in the same region as your database.
  • applyImmediately - When true , applies changes immediately. When false , applies changes during the preferred maintenance window. Some changes may cause an outage.
  • backupRetentionEnabled - When true, enables automated backup retention for your database. When false, disables automated backup retention for your database. Disabling backup retention deletes all automated database backups. Before disabling this, you may want to create a snapshot of your database.
  • skipFinalSnapshot - Determines whether a final database snapshot is created before your database is deleted. If true is specified, no database snapshot is created. If false is specified, a database snapshot is created before your database is deleted. You must specify the final relational database snapshot name parameter if the skip final snapshot parameter is false.
  • finalSnapshotName - (Required unless skipFinalSnapshot =True) The name of the database snapshot created if skip final snapshot is false, which is the default value for that parameter.
  • tags - (Optional) A map of tags to assign to the resource. To create a key-only tag, use an empty string as the value.

Blueprint Ids

A list of all available Lightsail Blueprints for Relational Databases the aws lightsail get-relational-database-blueprints aws cli command.

Examples

  • mysql80
  • postgres12

Prefix

A Blueprint ID starts with a prefix of the engine type.

Suffix

A Blueprint ID has a sufix of the engine version.

Bundles

A list of all available Lightsail Bundles for Relational Databases the aws lightsail get-relational-database-bundles aws cli command.

Examples

  • small10
  • smallHa10
  • large10
  • largeHa10

Prefix

A Bundle ID starts with one of the below size prefixes:

  • micro
  • small
  • medium
  • large

Infixes (Optional for HA Database)

A Bundle Id can have the following infix added in order to use the HA option of the selected bundle.

  • ha

Suffix

A Bundle ID ends with one of the following suffix: 1_0

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - The ARN of the Lightsail instance (matches arn).
  • arn - The ARN of the Lightsail instance (matches id).
  • caCertificateIdentifier - The certificate associated with the database.
  • createdAt - The timestamp when the instance was created.
  • engine - The database software (for example, MySQL).
  • engineVersion - The database engine version (for example, 5.7.23).
  • cpuCount - The number of vCPUs for the database.
  • ramSize - The amount of RAM in GB for the database.
  • diskSize - The size of the disk for the database.
  • masterEndpointPort - The master endpoint network port for the database.
  • masterEndpointAddress - The master endpoint fqdn for the database.
  • secondaryAvailabilityZone - Describes the secondary Availability Zone of a high availability database. The secondary database is used for failover support of a high availability database.
  • supportCode - The support code for the database. Include this code in your email to support when you have questions about a database in Lightsail. This code enables our support team to look up your Lightsail information more easily.
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

Lightsail Databases can be imported using their name, e.g.

$ terraform import aws_lightsail_database.foo 'bar'