S3: Create a Bucket in us-east-1
See more S3 - HTTP Examples
Uses Chilkat.Http with Amazon S3 general purpose buckets and Signature Version 4. These examples do not cover directory buckets/S3 Express, access-point ARNs, Outposts, or other specialized endpoints. They target the commercial AWS partition; other partitions need their documented endpoint suffix.
Load private qa_data/aws/s3.json containing nonempty string fields access_key and secret_key, plus session_token for temporary credentials. Prefer short-lived role credentials. These samples do not discover AWS profiles or refresh credentials. Set the bucket's actual region and replace sample bucket names and object keys. TLS certificate verification is explicitly enabled. Keep detailed HTTP diagnostics private because they can contain credentials or presigned URLs.
Creates a general purpose bucket in us-east-1 using the convenience method's empty request body. Choose an unused bucket name in the shared global namespace. Leave new-bucket defaults intact: Block Public Access enabled and Object Ownership set to Bucket owner enforced (ACLs disabled). Requires s3:CreateBucket.
Use regional bucket creation for another region. Do not blindly retry a create request: a timeout does not prove failure, and legacy us-east-1 behavior can reset ACLs when recreating a bucket already owned by the caller.
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
CkStringBuilder stringCompare = new CkStringBuilder();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Load private credentials; never put access keys or session tokens in source.
CkJsonObject credentials = new CkJsonObject();
credentials.put_Strict(true);
success = credentials.LoadFile("qa_data/aws/s3.json");
if (success != true) {
Log.i(TAG, "Could not load private S3 credentials.");
return;
}
stringCompare.SetString(credentials.stringOf("access_key"));
boolean stringMatch1 = stringCompare.ContentsEqual("",true);
if ((credentials.JsonTypeOf("access_key") != 1) or (stringMatch1 == true)) {
Log.i(TAG, "Missing or invalid access_key.");
return;
}
stringCompare.SetString(credentials.stringOf("secret_key"));
boolean stringMatch2 = stringCompare.ContentsEqual("",true);
if ((credentials.JsonTypeOf("secret_key") != 1) or (stringMatch2 == true)) {
Log.i(TAG, "Missing or invalid secret_key.");
return;
}
CkHttp http = new CkHttp();
http.put_AwsAccessKey(credentials.stringOf("access_key"));
http.put_AwsSecretKey(credentials.stringOf("secret_key"));
if (credentials.HasMember("session_token") == true) {
stringCompare.SetString(credentials.stringOf("session_token"));
boolean stringMatch3 = stringCompare.ContentsEqual("",true);
if ((credentials.JsonTypeOf("session_token") != 1) or (stringMatch3 == true)) {
Log.i(TAG, "session_token must be a nonempty string when supplied.");
return;
}
http.put_AwsSessionToken(credentials.stringOf("session_token"));
}
// Current Chilkat uses SigV4 by default. Do not select deprecated SigV2.
// Set the actual bucket region, not the caller's location.
String region = "us-east-1";
http.put_AwsRegion(region);
CkStringBuilder endpoint = new CkStringBuilder();
endpoint.Append("s3.");
endpoint.Append(region);
endpoint.Append(".amazonaws.com");
http.put_AwsEndpoint(endpoint.getAsString());
http.put_RequireSslCertVerify(true);
http.put_FollowRedirects(false);
// A region redirect is not success. Correct the endpoint and signing region.
// This helper sends an empty body: use it only for us-east-1.
String bucketName = "replace-with-your-unique-bucket-name";
success = http.S3_CreateBucket(bucketName);
if (success != true) {
Log.i(TAG, "Request failed (transport or S3 error). HTTP status: " + String.valueOf(http.get_LastStatus()));
// Inspect LastErrorText privately. Do not log credentials or signed URLs.
return;
}
if (http.get_LastStatus() != 200) {
Log.i(TAG, "Unexpected HTTP status: " + String.valueOf(http.get_LastStatus()));
return;
}
Log.i(TAG, "Bucket creation request succeeded.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}