2012-10-09 66 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();