AssumeRole - AWS iOS SDK示例

时间:2013-10-21 10:32:31

标签: ios amazon-web-services

我在iOS AWS sdk中使用“AssumeRole”api来生成临时安全凭证。任何人都可以告诉这个步骤或为此提供示例应用程序吗?

 TSC = [[AmazonSecurityTokenServiceClient alloc]initWithAccessKey:@"XXXXXXXXXXXXXXXX" withSecretKey:@"uuuuuuuuuuuyyyyyyyy" ]; 
 request = [[SecurityTokenServiceAssumeRoleRequest alloc]init ]; 
    request.roleArn = @"arn:aws:iam::0000000000:role/test";
    request.roleSessionName = @"test";
    request.policy =nil;
    request.durationSeconds=[NSNumber numberWithInt:3600];
    request.externalId=@"test123";
    response =  [TSC assumeRole:request];

我怀疑是获取临时凭证,上面的代码是否足够或者我是否需要明确调用NSURLConnection委托来进行Web服务调用?感谢。

1 个答案:

答案 0 :(得分:2)

该代码应足以获取凭据。如果请求成功,则凭据将在响应对象中可用。 (API reference)。

您需要初始化AmazonCredentials对象以使用返回的凭据:

AmazonCredentials *credentials = 
   [[AmazonCredentials alloc] initWithAccessKey:response.credentials.accessKeyId
                                  withSecretKey:response.credentials.secretAccessKey
                              withSecurityToken:response.credentials.sessionToken];

AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithCredentials:credentials];