createBucket method
- required String bucket,
- BucketCannedACL? acl,
- BucketNamespace? bucketNamespace,
- CreateBucketConfiguration? createBucketConfiguration,
- String? grantFullControl,
- String? grantRead,
- String? grantReadACP,
- String? grantWrite,
- String? grantWriteACP,
- bool? objectLockEnabledForBucket,
- ObjectOwnership? objectOwnership,
There are two types of buckets: general purpose buckets and directory buckets. For more information about these bucket types, see Creating, configuring, and working with Amazon S3 buckets in the Amazon S3 User Guide.
General purpose buckets exist in a global namespace, which means that each
bucket name must be unique across all Amazon Web Services accounts in all
the Amazon Web Services Regions within a partition. A partition is a
grouping of Regions. Amazon Web Services currently has four partitions:
aws (Standard Regions), aws-cn (China Regions),
aws-us-gov (Amazon Web Services GovCloud (US)), and
aws-eusc (European Sovereign Cloud). When you create a
general purpose bucket, you can choose to create a bucket in the shared
global namespace or you can choose to create a bucket in your account
regional namespace. Your account regional namespace is a subdivision of
the global namespace that only your account can create buckets in. For
more information on account regional namespaces, see Namespaces
for general purpose buckets.
-
General purpose buckets - If you send your
CreateBucketrequest to thes3.amazonaws.comglobal endpoint, the request goes to theus-east-1Region. So the signature calculations in Signature Version 4 must useus-east-1as the Region, even if the location constraint in the request specifies another Region where the bucket is to be created. If you create a bucket in a Region other than US East (N. Virginia), your application must be able to handle 307 redirect. For more information, see Virtual hosting of buckets in the Amazon S3 User Guide. -
Directory buckets - For directory buckets, you must make requests
for this API operation to the Regional endpoint. These endpoints support
path-style requests in the format
https://s3express-control.region-code.amazonaws.com/bucket-name. Virtual-hosted-style requests aren't supported. For more information about endpoints in Availability Zones, see Regional and Zonal endpoints for directory buckets in Availability Zones in the Amazon S3 User Guide. For more information about endpoints in Local Zones, see Concepts for directory buckets in Local Zones in the Amazon S3 User Guide.
- Permissions
-
-
General purpose bucket permissions - In addition to the
s3:CreateBucketpermission, the following permissions are required in a policy when yourCreateBucketrequest includes specific headers:-
Access control lists (ACLs) - In your
CreateBucketrequest, if you specify an access control list (ACL) and set it topublic-read,public-read-write,authenticated-read, or if you explicitly specify any other custom ACLs, boths3:CreateBucketands3:PutBucketAclpermissions are required. In yourCreateBucketrequest, if you set the ACL toprivate, or if you don't specify any ACLs, only thes3:CreateBucketpermission is required. -
Object Lock - In your
CreateBucketrequest, if you setx-amz-bucket-object-lock-enabledto true, thes3:PutBucketObjectLockConfigurationands3:PutBucketVersioningpermissions are required. -
S3 Object Ownership - If your
CreateBucketrequest includes thex-amz-object-ownershipheader, then thes3:PutBucketOwnershipControlspermission is required. -
S3 Block Public Access - If your specific use case requires
granting public access to your S3 resources, you can disable Block Public
Access. Specifically, you can create a new bucket with Block Public Access
enabled, then separately call the
DeletePublicAccessBlockAPI. To use this operation, you must have thes3:PutBucketPublicAccessBlockpermission. For more information about S3 Block Public Access, see Blocking public access to your Amazon S3 storage in the Amazon S3 User Guide.
-
Access control lists (ACLs) - In your
-
Directory bucket permissions - You must have the
s3express:CreateBucketpermission in an IAM identity-based policy instead of a bucket policy. Cross-account access to this API operation isn't supported. This operation can only be performed by the Amazon Web Services account that owns the resource. For more information about directory bucket policies and permissions, see Amazon Web Services Identity and Access Management (IAM) for S3 Express One Zone in the Amazon S3 User Guide.
-
General purpose bucket permissions - In addition to the
- HTTP Host header syntax
-
Directory buckets - The HTTP Host header syntax is
s3express-control.region-code.amazonaws.com.
CreateBucket:
May throw BucketAlreadyExists.
May throw BucketAlreadyOwnedByYou.
Parameter bucket :
The name of the bucket to create.
General purpose buckets - For information about bucket naming restrictions, see Bucket naming rules in the Amazon S3 User Guide.
Directory buckets - When you use this operation with a directory
bucket, you must use path-style requests in the format
https://s3express-control.region-code.amazonaws.com/bucket-name
. Virtual-hosted-style requests aren't supported. Directory bucket
names must be unique in the chosen Zone (Availability Zone or Local Zone).
Bucket names must also follow the format
bucket-base-name--zone-id--x-s3 (for example,
DOC-EXAMPLE-BUCKET--usw2-az1--x-s3). For information
about bucket naming restrictions, see Directory
bucket naming rules in the Amazon S3 User Guide
Parameter acl :
The canned ACL to apply to the bucket.
Parameter bucketNamespace :
Specifies the namespace where you want to create your general purpose
bucket. When you create a general purpose bucket, you can choose to create
a bucket in the shared global namespace or you can choose to create a
bucket in your account regional namespace. Your account regional namespace
is a subdivision of the global namespace that only your account can create
buckets in. For more information on bucket namespaces, see Namespaces
for general purpose buckets.
General purpose buckets in your account regional namespace must follow a
specific naming convention. These buckets consist of a bucket name prefix
that you create, and a suffix that contains your 12-digit Amazon Web
Services Account ID, the Amazon Web Services Region code, and ends with
-an. Bucket names must follow the format
bucket-name-prefix-accountId-region-an (for example,
amzn-s3-demo-bucket-111122223333-us-west-2-an). For
information about bucket naming restrictions, see Account
regional namespace naming rules in the Amazon S3 User Guide.
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 new objects in the bucket.
For the bucket and object owners of existing objects, also allows deletions and overwrites of those objects.
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.
Implementation
Future<CreateBucketOutput> createBucket({
required String bucket,
BucketCannedACL? acl,
BucketNamespace? bucketNamespace,
CreateBucketConfiguration? createBucketConfiguration,
String? grantFullControl,
String? grantRead,
String? grantReadACP,
String? grantWrite,
String? grantWriteACP,
bool? objectLockEnabledForBucket,
ObjectOwnership? objectOwnership,
}) async {
final headers = <String, String>{
if (acl != null) 'x-amz-acl': acl.value,
if (bucketNamespace != null)
'x-amz-bucket-namespace': bucketNamespace.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 (objectOwnership != null)
'x-amz-object-ownership': objectOwnership.value,
};
final $result = await _protocol.sendRaw(
method: 'PUT',
requestUri: '/${Uri.encodeComponent(bucket)}',
headers: headers,
payload: createBucketConfiguration?.toXml('CreateBucketConfiguration'),
exceptionFnMap: _exceptionFns,
);
final $elem = await _s.xmlFromResponse($result);
return CreateBucketOutput(
bucketArn:
_s.extractHeaderStringValue($result.headers, 'x-amz-bucket-arn'),
location: _s.extractHeaderStringValue($result.headers, 'Location'),
);
}