createBucket method

Future<CreateBucketResult> createBucket({
  1. required String bucketName,
  2. required String bundleId,
  3. bool? enableObjectVersioning,
  4. List<Tag>? tags,
})

Creates an Amazon Lightsail bucket.

A bucket is a cloud storage resource available in the Lightsail object storage service. Use buckets to store objects such as data and its descriptive metadata. For more information about buckets, see Buckets in Amazon Lightsail in the Amazon Lightsail Developer Guide.

May throw AccessDeniedException. May throw InvalidInputException. May throw RegionSetupInProgressException. May throw ServiceException. May throw UnauthenticatedException.

Parameter bucketName : The name for the bucket.

For more information about bucket names, see Bucket naming rules in Amazon Lightsail in the Amazon Lightsail Developer Guide.

Parameter bundleId : The ID of the bundle to use for the bucket.

A bucket bundle specifies the monthly cost, storage space, and data transfer quota for a bucket.

Use the GetBucketBundles action to get a list of bundle IDs that you can specify.

Use the UpdateBucketBundle action to change the bundle after the bucket is created.

Parameter enableObjectVersioning : A Boolean value that indicates whether to enable versioning of objects in the bucket.

For more information about versioning, see Enabling and suspending object versioning in a bucket in Amazon Lightsail in the Amazon Lightsail Developer Guide.

Parameter tags : The tag keys and optional values to add to the bucket during creation.

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

Implementation

Future<CreateBucketResult> createBucket({
  required String bucketName,
  required String bundleId,
  bool? enableObjectVersioning,
  List<Tag>? tags,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.CreateBucket'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'bucketName': bucketName,
      'bundleId': bundleId,
      if (enableObjectVersioning != null)
        'enableObjectVersioning': enableObjectVersioning,
      if (tags != null) 'tags': tags,
    },
  );

  return CreateBucketResult.fromJson(jsonResponse.body);
}