createBucket method

Future<CreateBucketResult> createBucket({
  1. required String bucket,
  2. BucketCannedACL? acl,
  3. CreateBucketConfiguration? createBucketConfiguration,
  4. String? grantFullControl,
  5. String? grantRead,
  6. String? grantReadACP,
  7. String? grantWrite,
  8. String? grantWriteACP,
  9. bool? objectLockEnabledForBucket,
  10. String? outpostId,
})
Creates a new Outposts bucket. By creating the bucket, you become the bucket owner. To create an Outposts bucket, you must have S3 on Outposts. For more information, see Using Amazon S3 on Outposts in Amazon S3 User Guide.

Not every string is an acceptable bucket name. For information on bucket naming restrictions, see Working with Amazon S3 Buckets.

S3 on Outposts buckets support:

  • Tags
  • LifecycleConfigurations for deleting expired objects
For a complete list of restrictions and Amazon S3 feature limitations on S3 on Outposts, see Amazon S3 on Outposts Restrictions and Limitations.

For an example of the request syntax for Amazon S3 on Outposts that uses the S3 on Outposts endpoint hostname prefix and x-amz-outpost-id in your API request, see the Examples section.

The following actions are related to CreateBucket for Amazon S3 on Outposts:

May throw BucketAlreadyExists. May throw BucketAlreadyOwnedByYou.

Parameter bucket : The name of the bucket.

Parameter acl : The canned ACL to apply to the bucket.

Parameter createBucketConfiguration : The configuration information for the bucket.

Parameter grantFullControl : Allows grantee the read, write, read ACP, and write ACP permissions on the bucket.

Parameter grantRead : Allows grantee to list the objects in the bucket.

Parameter grantReadACP : Allows grantee to read the bucket ACL.

Parameter grantWrite : Allows grantee to create, overwrite, and delete any object in the bucket.

Parameter grantWriteACP : Allows grantee to write the ACL for the applicable bucket.

Parameter objectLockEnabledForBucket : Specifies whether you want S3 Object Lock to be enabled for the new bucket.

Parameter outpostId : The ID of the Outposts where the bucket is being created.

Implementation

Future<CreateBucketResult> createBucket({
  required String bucket,
  BucketCannedACL? acl,
  CreateBucketConfiguration? createBucketConfiguration,
  String? grantFullControl,
  String? grantRead,
  String? grantReadACP,
  String? grantWrite,
  String? grantWriteACP,
  bool? objectLockEnabledForBucket,
  String? outpostId,
}) async {
  final headers = <String, String>{
    if (acl != null) 'x-amz-acl': acl.value,
    if (grantFullControl != null)
      'x-amz-grant-full-control': grantFullControl.toString(),
    if (grantRead != null) 'x-amz-grant-read': grantRead.toString(),
    if (grantReadACP != null) 'x-amz-grant-read-acp': grantReadACP.toString(),
    if (grantWrite != null) 'x-amz-grant-write': grantWrite.toString(),
    if (grantWriteACP != null)
      'x-amz-grant-write-acp': grantWriteACP.toString(),
    if (objectLockEnabledForBucket != null)
      'x-amz-bucket-object-lock-enabled':
          objectLockEnabledForBucket.toString(),
    if (outpostId != null) 'x-amz-outpost-id': outpostId.toString(),
  };
  final $result = await _protocol.sendRaw(
    method: 'PUT',
    requestUri: '/v20180820/bucket/${Uri.encodeComponent(bucket)}',
    headers: headers,
    payload: createBucketConfiguration?.toXml('CreateBucketConfiguration'),
    exceptionFnMap: _exceptionFns,
  );
  final $elem = await _s.xmlFromResponse($result);
  return CreateBucketResult(
    bucketArn: _s.extractXmlStringValue($elem, 'BucketArn'),
    location: _s.extractHeaderStringValue($result.headers, 'Location'),
  );
}