Skip to content

S3 Service Unavailable While Updating putObjectAcl

0

Hello, I have a php script that needs to update the acl on over 900 objects. I started running into Service Unavailable. The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. From my understanding I am going over rate limits so it is causing this error. I have searched for a method to throttle this, but cannot find one. Is there a way to make this work or suggest better design pattern I can use? Below is my process and code. I have tried adding sleep() to pause the script, but this had no effect.

PHP: 74 aws-sdk-php: ^3.209

  1. Loop thru groups and get keys according to dates (This works as expected)
  2. Loop thru group objects and check if object has correct ACL using promise, wait and getObjectAclAsync, a group can have object count of 400.
  3. Update object using promise, wait and putObjectAclAsync
private function isACLRead($key) {
	$blnPublicRead = false;
	$promise = $this->s3Client->getObjectAclAsync([
		'Bucket' => $this->AWSBUCKET,
		'Key' => $key
	]);
	try {
		$result = $promise->wait();
		foreach($result["Grants"] as $grant=>$v) {
			if ($v['Permission'] == 'READ') :
				$blnPublicRead = true;
				break;
			endif;
		}
		return $blnPublicRead;
	} catch (AwsException $e) {
		$this->notifyMSG .= 'Error: '.$key;
		return false;
	}
}

private function updateACL($key) {
	$promise = $this->s3Client->putObjectAclAsync([
		'Bucket' => $this->AWSBUCKET, 
		'Key' => $key, 
		'ACL' => 'public-read'
	]);
	try{
		$result = $promise->wait();
		$this->keys[] = $key; //Key List
		return true;
	} catch (AwsException $e) {
		$this->notifyMSG .= 'Error: '.$key;
		return false;
	}
}
asked 4 years ago468 views
1 Answer
0

A simple delay (such as sleep) won't necessarily introduce enough delay until your next API call so that you are not throttled. Instead, you should look at exponential backoff and retries. The AWS API documentation has an example of how to do this.

AWS
EXPERT
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.