title: Can not create bucket in AWS S3
body: <p>I am trying to create a bucket in amazon S3 service. but the following exception arise:</p>
  
  <pre><code>11-27 05:32:53.868: E/AndroidRuntime(1628): FATAL EXCEPTION: AsyncTask #1
  11-27 05:32:53.868: E/AndroidRuntime(1628): java.lang.RuntimeException: An error occured while executing doInBackground()
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.lang.Thread.run(Thread.java:856)
  11-27 05:32:53.868: E/AndroidRuntime(1628): Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 404, AWS Service: Amazon S3, AWS Request ID: A8BC718C70431BC1, AWS Error Code: NoSuchBucket, AWS Error Message: The specified bucket does not exist, S3 Extended Request ID: /LB0Sfqrke3aDRbuZ51iXbgdESeQFVVijrK8X8Csp2zDzppRQ9G/WOgy0fA71ltI
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:666)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:330)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:182)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3105)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1234)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.demo.amazons3cloudservice.MainActivity.create(MainActivity.java:104)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.demo.amazons3cloudservice.MainActivity$CreateBucket.doInBackground(MainActivity.java:71)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at com.demo.amazons3cloudservice.MainActivity$CreateBucket.doInBackground(MainActivity.java:1)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
  11-27 05:32:53.868: E/AndroidRuntime(1628):     ... 4 more
  </code></pre>
  
  <p>I have learnt from the exception that the application is not sign in at the aws s3 but could not find out the way, here is my code, please give me any suggestion.</p>
  
  <pre><code>    import java.io.ByteArrayInputStream;
  import java.io.InputStream;
  
  import android.app.Activity;
  import android.content.Context;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.Toast;
  
  import com.amazon.identity.auth.device.endpoint.RequestUrlBuilder;
  import com.amazonaws.AmazonWebServiceRequest;
  import com.amazonaws.auth.BasicAWSCredentials;
  import com.amazonaws.http.AmazonHttpClient;
  import com.amazonaws.http.HttpRequest;
  import com.amazonaws.javax.xml.stream.xerces.impl.io.UTF8Reader;
  import com.amazonaws.services.s3.AmazonS3Client;
  import com.amazonaws.services.s3.model.ObjectMetadata;
  import com.amazonaws.services.s3.model.PutObjectRequest;
  
  public class MainActivity extends Activity {
  
      Button s3Connect;
      private AmazonS3Client client;
      String folderName = "new Folder";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          client = new AmazonS3Client(new BasicAWSCredentials(
                  Constants.ACCESS_KEY, Constants.ACCESS_SECRET));
  
          s3Connect =(Button)findViewById(R.id.s3Connect);
  
          s3Connect.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View arg0) {
                  CreateBucket bucket = new CreateBucket(getApplicationContext(),
                          client, folderName);
                  bucket.execute();
  
              }
          });
      }
  
      private class CreateBucket extends AsyncTask&lt;Boolean, Void, Boolean&gt; {
  
          private Context mContext;
          private AmazonS3Client mClient;
          private String folderName;
  
          public CreateBucket(Context mContext, AmazonS3Client mClient,
                  String folderName) {
              // TODO Auto-generated constructor stub
              this.mContext = mContext;
              this.mClient = mClient;
              this.folderName = "new";
          }
  
          @Override
          protected Boolean doInBackground(Boolean... arg0) {
              // TODO Auto-generated method stub
              create(folderName);
              return true;
          }
  
          @Override
          protected void onPostExecute(Boolean result) {
              // TODO Auto-generated method stub
              super.onPostExecute(result);
              if (result == true)
                  Toast.makeText(getApplicationContext(),
                          "The folder is created", Toast.LENGTH_SHORT).show();
              else
                  Toast.makeText(getApplicationContext(),
                          "The folder is not created", Toast.LENGTH_SHORT).show();
          }
  
      }
  
      public void create(String foldername) {
          // TODO validate foldername
  
          // Create metadata for your folder &amp; set content-length to 0
          ObjectMetadata metadata = new ObjectMetadata();
          metadata.setContentLength(0);
  
          // Create empty content
          InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
  
          // Create a PutObjectRequest passing the foldername suffixed by /
          PutObjectRequest putObjectRequest = new PutObjectRequest(
                  Constants.BUCKET, foldername + "/", emptyContent, metadata);
  
          // Send request to S3 to create folder
          client.putObject(putObjectRequest);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>