restoreServer method

Future<void> restoreServer({
  1. required String backupId,
  2. required String serverName,
  3. String? instanceType,
  4. String? keyPair,
})

Restores a backup to a server that is in a CONNECTION_LOST, HEALTHY, RUNNING, UNHEALTHY, or TERMINATED state. When you run RestoreServer, the server's EC2 instance is deleted, and a new EC2 instance is configured. RestoreServer maintains the existing server endpoint, so configuration management of the server's client devices (nodes) should continue to work.

Restoring from a backup is performed by creating a new EC2 instance. If restoration is successful, and the server is in a HEALTHY state, AWS OpsWorks CM switches traffic over to the new instance. After restoration is finished, the old EC2 instance is maintained in a Running or Stopped state, but is eventually terminated.

This operation is asynchronous.

An InvalidStateException is thrown when the server is not in a valid state. A ResourceNotFoundException is thrown when the server does not exist. A ValidationException is raised when parameters of the request are not valid.

May throw InvalidStateException. May throw ResourceNotFoundException. May throw ValidationException.

Parameter backupId : The ID of the backup that you want to use to restore a server.

Parameter serverName : The name of the server that you want to restore.

Parameter instanceType : The type of instance to restore. Valid values must be specified in the following format: ^(34|t2).* For example, m5.large. Valid values are m5.large, r5.xlarge, and r5.2xlarge. If you do not specify this parameter, RestoreServer uses the instance type from the specified backup.

Parameter keyPair : The name of the key pair to set on the new EC2 instance. This can be helpful if the administrator no longer has the SSH key.

Implementation

Future<void> restoreServer({
  required String backupId,
  required String serverName,
  String? instanceType,
  String? keyPair,
}) async {
  ArgumentError.checkNotNull(backupId, 'backupId');
  _s.validateStringLength(
    'backupId',
    backupId,
    0,
    79,
    isRequired: true,
  );
  ArgumentError.checkNotNull(serverName, 'serverName');
  _s.validateStringLength(
    'serverName',
    serverName,
    1,
    40,
    isRequired: true,
  );
  _s.validateStringLength(
    'instanceType',
    instanceType,
    0,
    10000,
  );
  _s.validateStringLength(
    'keyPair',
    keyPair,
    0,
    10000,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'OpsWorksCM_V2016_11_01.RestoreServer'
  };
  await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'BackupId': backupId,
      'ServerName': serverName,
      if (instanceType != null) 'InstanceType': instanceType,
      if (keyPair != null) 'KeyPair': keyPair,
    },
  );
}