Reputation: 423
I am using "AssumeRole" api in iOS AWS sdk to generate temporary security credentials. Can anybody tell the steps for this or give sample app for this?
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];
My doubt is to get temporary credentials, the above code will be enough or do i need call the NSURLConnection delegates explicitly to make the web service call? Thanks.
Upvotes: 1
Views: 585
Reputation: 9020
That code should be enough to get credentials. If the request is successful, the credentials will be available in the response object. (API reference).
You'll need to initialize a AmazonCredentials object to use the returned credentials:
AmazonCredentials *credentials =
[[AmazonCredentials alloc] initWithAccessKey:response.credentials.accessKeyId
withSecretKey:response.credentials.secretAccessKey
withSecurityToken:response.credentials.sessionToken];
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithCredentials:credentials];
Upvotes: 2