create-bucket-get-location-example
Examples of Creating a Bucket
Topics
- Using the Amazon S3 Console
- Using the AWS SDK for Java
- Using the AWS SDK for .NET
- Using the AWS SDK for Ruby Version 3
- Using Other AWS SDKs
The following code examples create a bucket programmatically using the AWS SDKs for Java, .NET, and Ruby. The code examples perform the following tasks:
Create a bucket, if the bucket doesn't already exist—The examples create a bucket by performing the following tasks:
Create a client by explicitly specifying an AWS Region (the example uses the
s3.eu-west-1
Region). Accordingly, the client communicates with Amazon S3 using thes3.eu-west-1.amazonaws.com
endpoint. You can specify any other AWS Region. For a list of AWS Regions, see Regions and Endpoints in the AWS General Reference.Send a create bucket request by specifying only a bucket name. The create bucket request doesn't specify another AWS Region. The client sends a request to Amazon S3 to create the bucket in the Region you specified when creating the client. Once you have created a bucket, you can't change its Region. Note
If you explicitly specify an AWS Region in your create bucket request that is different from the Region you specified when you created the client, you might get an error. For more information, see Creating a Bucket.The SDK libraries send the PUT bucket request to Amazon S3 to create the bucket\. For more information, see [PUT Bucket](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html)\.
Retrieve information about the location of the bucket—Amazon S3 stores bucket location information in the location subresource that is associated with the bucket. The SDK libraries send the GET Bucket location request (see GET Bucket location) to retrieve this information.
Using the Amazon S3 Console
To create a bucket using the Amazon S3 console, see How Do I Create an S3 Bucket? in the Amazon Simple Storage Service Console User Guide.
Using the AWS SDK for Java
Example
This example shows how to create an Amazon S3 bucket using the AWS SDK for Java. For instructions on creating and testing a working sample, see Testing the Amazon S3 Java Code Examples.
Using the AWS SDK for .NET
For information about how to create and test a working sample, see Running the Amazon S3 .NET Code Examples.
Example
Using the AWS SDK for Ruby Version 3
For information about how to create and test a working sample, see Using the AWS SDK for Ruby - Version 3.
Example
Using Other AWS SDKs
For information about using other AWS SDKs, see Sample Code and Libraries.