({ bucketName })
| 15 | * @param {{ bucketName: string }} config |
| 16 | */ |
| 17 | export const main = async ({ bucketName }) => { |
| 18 | const client = new S3Client({}); |
| 19 | |
| 20 | try { |
| 21 | const { Location } = await client.send( |
| 22 | new CreateBucketCommand({ |
| 23 | // The name of the bucket. Bucket names are unique and have several other constraints. |
| 24 | // See https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html |
| 25 | Bucket: bucketName, |
| 26 | }), |
| 27 | ); |
| 28 | await waitUntilBucketExists({ client }, { Bucket: bucketName }); |
| 29 | console.log(`Bucket created with location ${Location}`); |
| 30 | } catch (caught) { |
| 31 | if (caught instanceof BucketAlreadyExists) { |
| 32 | console.error( |
| 33 | `The bucket "${bucketName}" already exists in another AWS account. Bucket names must be globally unique.`, |
| 34 | ); |
| 35 | } |
| 36 | // WARNING: If you try to create a bucket in the North Virginia region, |
| 37 | // and you already own a bucket in that region with the same name, this |
| 38 | // error will not be thrown. Instead, the call will return successfully |
| 39 | // and the ACL on that bucket will be reset. |
| 40 | else if (caught instanceof BucketAlreadyOwnedByYou) { |
| 41 | console.error( |
| 42 | `The bucket "${bucketName}" already exists in this AWS account.`, |
| 43 | ); |
| 44 | } else { |
| 45 | throw caught; |
| 46 | } |
| 47 | } |
| 48 | }; |
| 49 | // snippet-end:[s3.JavaScript.buckets.createBucketV3] |
| 50 | |
| 51 | // Call function if run directly |
no test coverage detected