diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index b55f913e278db15a9d7e038074f8ed98cd51c270..2a79ecf9a3a992d39e8fe5c4373e763972df6d82 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -36,6 +36,8 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 	private $connection;
 	private $bucket;
 	private static $tmpFiles = array();
+	private $test = false;
+	private $timeout = 15;
 
 	private function normalizePath($path) {
 		$path = trim($path, '/');
@@ -47,44 +49,54 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 		return $path;
 	}
 
+	private function testTimeout() {
+		if ($this->test) {
+			sleep($this->timeout);
+		}
+	}
+
 	public function __construct($params) {
 		if ( ! isset($params['key']) || ! isset($params['secret']) || ! isset($params['bucket'])) {
 			throw new \Exception("Access Key, Secret and Bucket have to be configured.");
 		}
 
 		$this->id = 'amazon::' . $params['key'] . md5($params['secret']);
+
 		$this->bucket = $params['bucket'];
 		$scheme = ($params['use_ssl'] === 'false') ? 'http' : 'https';
-
-		if (isset($params['hostname']) && isset($params['port'])) {
-			$base_url = $scheme.'://'.$params['hostname'].':'.$params['port'].'/';
-			$this->connection = S3Client::factory(array(
-				'key' => $params['key'],
-				'secret' => $params['secret'],
-				'base_url' => $base_url
-			));
-		} else {
-			if ( ! isset($params['region'])) {
-				$params['region'] = 'us-west-1';
-			}
-			$this->connection = S3Client::factory(array(
-				'key' => $params['key'],
-				'secret' => $params['secret'],
-				'scheme' => $scheme,
-				'region' => $params['region']
-			));
+		$this->test = ( isset($params['test'])) ? true : false;
+		$this->timeout = ( ! isset($params['timeout'])) ? 15 : $params['timeout'];
+		$params['region'] = ( ! isset($params['region'])) ? 'eu-west-1' : $params['region'];
+		$params['hostname'] = ( !isset($params['hostname'])) ? 's3.amazonaws.com' : $params['hostname'];
+		if ( ! isset($params['port'])) {
+			$params['port'] = ($params['use_ssl'] === 'false') ? 80 : 443;
 		}
+		$base_url = $scheme.'://'.$params['hostname'].':'.$params['port'].'/';
+
+		$this->connection = S3Client::factory(array(
+			'key' => $params['key'],
+			'secret' => $params['secret'],
+			'base_url' => $base_url,
+			'region' => $params['region']
+		));
 
 		if (! $this->connection->isValidBucketName($this->bucket)) {
 			throw new \Exception("The configured bucket name is invalid.");
 		}
 
 		if ( ! $this->connection->doesBucketExist($this->bucket)) {
-			$result = $this->connection->createBucket(array(
-				'Bucket' => $this->bucket
-			));
-			while ( ! $this->connection->doesBucketExist($this->bucket)) {
-				sleep(1);
+			try {
+				$result = $this->connection->createBucket(array(
+					'Bucket' => $this->bucket
+				));
+				$this->connection->waitUntilBucketExists(array(
+					'Bucket' => $this->bucket,
+					'waiter.interval' => 1,
+					'waiter.max_attempts' => 15
+				));
+			$this->testTimeout();
+			} catch (S3Exception $e) {
+				throw new \Exception("Creation of bucket failed.");
 			}
 		}
 
@@ -96,6 +108,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 				'ContentType' => 'httpd/unix-directory',
 				'ContentLength' => 0
 			));
+			$this->testTimeout();
 		}
 	}
 
@@ -114,6 +127,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 				'ContentType' => 'httpd/unix-directory',
 				'ContentLength' => 0
 			));
+			$this->testTimeout();
 		} catch (S3Exception $e) {
 			return false;
 		}
@@ -168,6 +182,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 				'Bucket' => $this->bucket,
 				'Key' => $path . '/'
 			));
+			$this->testTimeout();
 		} catch (S3Exception $e) {
 			return false;
 		}
@@ -276,6 +291,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 				'Bucket' => $this->bucket,
 				'Key' => $path
 			));
+			$this->testTimeout();
 		} catch (S3Exception $e) {
 			return false;
 		}
@@ -373,12 +389,14 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 					'Metadata' => $metadata,
 					'CopySource' => $this->bucket . '/' . $path
 				));
+				$this->testTimeout();
 			} else {
 				$result = $this->connection->putObject(array(
 					'Bucket' => $this->bucket,
 					'Key' => $path,
 					'Metadata' => $metadata
 				));
+				$this->testTimeout();
 			}
 		} catch (S3Exception $e) {
 			return false;
@@ -398,6 +416,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 					'Key' => $path2,
 					'CopySource' => $this->bucket . '/' . $path1
 				));
+				$this->testTimeout();
 			} catch (S3Exception $e) {
 				return false;
 			}
@@ -412,6 +431,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 					'Key' => $path2 . '/',
 					'CopySource' => $this->bucket . '/' . $path1 . '/'
 				));
+				$this->testTimeout();
 			} catch (S3Exception $e) {
 				return false;
 			}
@@ -491,6 +511,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
 				'ContentType' => \OC_Helper::getMimeType($tmpFile),
 				'ContentLength' => filesize($tmpFile)
 			));
+			$this->testTimeout();
 
 			unlink($tmpFile);
 			$this->touch(dirname(self::$tmpFiles[$tmpFile]));
diff --git a/apps/files_external/tests/amazons3.php b/apps/files_external/tests/amazons3.php
index bd9348bf818412d66993160b37c9abda5b9f7f2a..a73b6307b0147d0e632014415862abf1b627f3cc 100644
--- a/apps/files_external/tests/amazons3.php
+++ b/apps/files_external/tests/amazons3.php
@@ -59,9 +59,8 @@ class AmazonS3 extends Storage {
 				'Bucket' => $this->config['amazons3']['bucket']
 			));
 
-			while($connection->doesBucketExist($this->config['amazons3']['bucket'])) {
-				sleep(1);
-			}
+			//wait some seconds for completing the replication
+			sleep(30);
 		}
 	}
 }
diff --git a/apps/files_external/tests/config.php b/apps/files_external/tests/config.php
index 90ca21b43da3e30934fd94ae600119ae57fe48cc..ca7bf50038f9a11f4697e0fe50736f4f0aac2025 100644
--- a/apps/files_external/tests/config.php
+++ b/apps/files_external/tests/config.php
@@ -54,8 +54,9 @@ return array(
 		//'hostname' => 'your.host.name',
 		//'port' => '443',
 		//'use_ssl' => 'true',
-		//'use_path_style' => 'false',
-		//'region' => 'us-west-1'
+		//'region' => 'eu-west-1',
+		//'test'=>'true',
+		//'timeout'=>20
 	),
 	'dropbox' => array (
 		'run'=>false,