attachDisk method

Future<AttachDiskResult> attachDisk({
  1. required String diskName,
  2. required String diskPath,
  3. required String instanceName,
  4. bool? autoMounting,
})

Attaches a block storage disk to a running or stopped Lightsail instance and exposes it to the instance with the specified disk name.

The attach disk operation supports tag-based access control via resource tags applied to the resource identified by disk name. For more information, see the Amazon Lightsail Developer Guide.

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

Parameter diskName : The unique Lightsail disk name (my-disk).

Parameter diskPath : The disk path to expose to the instance (/dev/xvdf).

Parameter instanceName : The name of the Lightsail instance where you want to utilize the storage disk.

Parameter autoMounting : A Boolean value used to determine the automatic mounting of a storage volume to a virtual computer. The default value is False.

Implementation

Future<AttachDiskResult> attachDisk({
  required String diskName,
  required String diskPath,
  required String instanceName,
  bool? autoMounting,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.AttachDisk'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'diskName': diskName,
      'diskPath': diskPath,
      'instanceName': instanceName,
      if (autoMounting != null) 'autoMounting': autoMounting,
    },
  );

  return AttachDiskResult.fromJson(jsonResponse.body);
}