createRelationalDatabaseFromSnapshot method

Future<CreateRelationalDatabaseFromSnapshotResult> createRelationalDatabaseFromSnapshot({
  1. required String relationalDatabaseName,
  2. String? availabilityZone,
  3. bool? publiclyAccessible,
  4. String? relationalDatabaseBundleId,
  5. String? relationalDatabaseSnapshotName,
  6. DateTime? restoreTime,
  7. String? sourceRelationalDatabaseName,
  8. List<Tag>? tags,
  9. bool? useLatestRestorableTime,
})

Creates a new database from an existing database snapshot in Amazon Lightsail.

You can create a new database from a snapshot in if something goes wrong with your original database, or to change it to a different plan, such as a high availability or standard plan.

The create relational database from snapshot operation supports tag-based access control via request tags and resource tags applied to the resource identified by relationalDatabaseSnapshotName. For more information, see the Lightsail Dev Guide.

May throw ServiceException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw AccessDeniedException. May throw AccountSetupInProgressException. May throw UnauthenticatedException.

Parameter relationalDatabaseName : The name to use for your new database.

Constraints:

  • Must contain from 2 to 255 alphanumeric characters, or hyphens.
  • The first and last character must be a letter or number.

Parameter availabilityZone : The Availability Zone in which to create your new database. Use the us-east-2a case-sensitive format.

You can get a list of Availability Zones by using the get regions operation. Be sure to add the include relational database Availability Zones parameter to your request.

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

Parameter relationalDatabaseBundleId : The bundle ID for your new database. A bundle describes the performance specifications for your database.

You can get a list of database bundle IDs by using the get relational database bundles operation.

When creating a new database from a snapshot, you cannot choose a bundle that is smaller than the bundle of the source database.

Parameter relationalDatabaseSnapshotName : The name of the database snapshot from which to create your new database.

Parameter restoreTime : The date and time to restore your database from.

Constraints:

  • Must be before the latest restorable time for the database.
  • Cannot be specified if the use latest restorable time parameter is true.
  • Specified in Coordinated Universal Time (UTC).
  • Specified in the Unix time format.

    For example, if you wish to use a restore time of October 1, 2018, at 8 PM UTC, then you input 1538424000 as the restore time.

Parameter sourceRelationalDatabaseName : The name of the source database.

Parameter tags : The tag keys and optional values to add to the resource during create.

Use the TagResource action to tag a resource after it's created.

Parameter useLatestRestorableTime : Specifies whether your database is restored from the latest backup time. A value of true restores from the latest backup time.

Default: false

Constraints: Cannot be specified if the restore time parameter is provided.

Implementation

Future<CreateRelationalDatabaseFromSnapshotResult>
    createRelationalDatabaseFromSnapshot({
  required String relationalDatabaseName,
  String? availabilityZone,
  bool? publiclyAccessible,
  String? relationalDatabaseBundleId,
  String? relationalDatabaseSnapshotName,
  DateTime? restoreTime,
  String? sourceRelationalDatabaseName,
  List<Tag>? tags,
  bool? useLatestRestorableTime,
}) async {
  ArgumentError.checkNotNull(
      relationalDatabaseName, 'relationalDatabaseName');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.CreateRelationalDatabaseFromSnapshot'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'relationalDatabaseName': relationalDatabaseName,
      if (availabilityZone != null) 'availabilityZone': availabilityZone,
      if (publiclyAccessible != null)
        'publiclyAccessible': publiclyAccessible,
      if (relationalDatabaseBundleId != null)
        'relationalDatabaseBundleId': relationalDatabaseBundleId,
      if (relationalDatabaseSnapshotName != null)
        'relationalDatabaseSnapshotName': relationalDatabaseSnapshotName,
      if (restoreTime != null)
        'restoreTime': unixTimestampToJson(restoreTime),
      if (sourceRelationalDatabaseName != null)
        'sourceRelationalDatabaseName': sourceRelationalDatabaseName,
      if (tags != null) 'tags': tags,
      if (useLatestRestorableTime != null)
        'useLatestRestorableTime': useLatestRestorableTime,
    },
  );

  return CreateRelationalDatabaseFromSnapshotResult.fromJson(
      jsonResponse.body);
}