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 Simple Storage Service Developer 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 do not support

  • ACLs. Instead, configure access point policies to manage access to buckets.
  • Public access.
  • Object Lock
  • Bucket Location constraint
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 {
  ArgumentError.checkNotNull(bucket, 'bucket');
  _s.validateStringLength(
    'bucket',
    bucket,
    3,
    255,
    isRequired: true,
  );
  _s.validateStringLength(
    'outpostId',
    outpostId,
    1,
    64,
  );
  final headers = <String, String>{
    if (acl != null) 'x-amz-acl': acl.toValue(),
    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'),
  );
}