createDisk method
Creates a block storage disk that can be attached to an Amazon Lightsail
instance in the same Availability Zone (e.g., us-east-2a
).
The create disk
operation supports tag-based access control
via request tags. 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 availabilityZone
:
The Availability Zone where you want to create the disk (e.g.,
us-east-2a
). Use the same Availability Zone as the Lightsail
instance to which you want to attach the disk.
Use the get regions
operation to list the Availability Zones
where Lightsail is currently available.
Parameter diskName
:
The unique Lightsail disk name (e.g., my-disk
).
Parameter sizeInGb
:
The size of the disk in GB (e.g., 32
).
Parameter addOns
:
An array of objects that represent the add-ons to enable for the new disk.
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.
Implementation
Future<CreateDiskResult> createDisk({
required String availabilityZone,
required String diskName,
required int sizeInGb,
List<AddOnRequest>? addOns,
List<Tag>? tags,
}) async {
ArgumentError.checkNotNull(availabilityZone, 'availabilityZone');
ArgumentError.checkNotNull(diskName, 'diskName');
ArgumentError.checkNotNull(sizeInGb, 'sizeInGb');
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'Lightsail_20161128.CreateDisk'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'availabilityZone': availabilityZone,
'diskName': diskName,
'sizeInGb': sizeInGb,
if (addOns != null) 'addOns': addOns,
if (tags != null) 'tags': tags,
},
);
return CreateDiskResult.fromJson(jsonResponse.body);
}