2012-10-09 96 views
1

我正在嘗試使用aws sdk for php爲用戶創建臨時憑證。從我可以收集它應該只是將通過IAM的STS政策爲我的SDK用戶的情況:如何使用aws php sdk使用AmazonSTS?

{ 
    "Statement": [ 
    { 
     "Sid": "Stmt1349820612345", 
     "Action": "sts:*", 
     "Effect": "Allow", 
     "Resource": "*" 
    } 
    ] 
} 

,然後實例化STS類作爲示例所示:

// Instantiate the class 
    $token = new AmazonSTS(); 

// Generate a new IAM policy 
    $policy = new CFPolicy($token, array(
    'Statement' => array(
     array(
     'Sid' => 'SID' . time(), 
     'Action' => array(
      's3:ListBucket' 
     ), 
     'Effect' => 'Allow', 
     'Resource' => 'arn:aws:s3:::my-bucket' 
    ) 
    ) 
)); 

// Fetch the session credentials 
    $response = $token->get_federation_token('my-user', array(
    'Policy' => $policy->get_json(), 
    'DurationSeconds' => 3600 
)); 

    $credentials = $response->body->GetFederatedTokenResult->Credentials 
    ->to_array()->getArrayCopy(); 
    return $credentials; 

它當我使用常規的臨時憑證令牌正常工作:

$token = new AmazonSTS(); 
$response = $token->get_session_token(); 

$credentials = $response->body->GetSessionTokenResult->Credentials->to_array()->getArrayCopy(); 

有沒有人有這方面的一個工作示例或能看到我錯了?

回答

1

最後found this in the s3 docs的作品

$AccessKeyId = (string)$response-> 
    body->GetFederationTokenResult->Credentials->AccessKeyId; 
    $SecretAccessKey = (string)$response-> 
    body->GetFederationTokenResult->Credentials->SecretAccessKey; 
    $SessionToken = (string)$response-> 
    body->GetFederationTokenResult->Credentials->SessionToken; 

所以此工程

$credentials = $response->body->GetFederationTokenResult->Credentials->to_array()->getArrayCopy();