我是AWS iOS SDK的新手。我正在尝试使用iPhone应用中的“assumeRole” api生成临时安全凭证。我在项目中添加了AWSSecurityTokenService,AWSRuntime框架。下面是代码。
#import <AWSSecurityTokenService/AWSSecurityTokenService.h>
#import <AWSSecurityTokenService/SecurityTokenServiceAssumeRoleRequest.h>
#import <AWSSecurityTokenService/SecurityTokenServiceAssumeRoleResponse.h>
#import <AWSSecurityTokenService/AmazonSecurityTokenServiceClient.h>
- (void)viewDidLoad
{
[super viewDidLoad];
TSC = [[AmazonSecurityTokenServiceClient alloc]init];
request = [[SecurityTokenServiceAssumeRoleRequest alloc]init];
request.roleArn = @"arn:aws:iam::xxxxxxxxxx:role/test";
request.roleSessionName = @"Bob";
request.policy = @"None";
request.durationSeconds=[NSNumber numberWithInt:3600];
request.externalId=@"abc";
//[self assumeRole:request];
@try {
response = [TSC assumeRole:request];
NSLog(@"%@ is response",response);
}
@catch (AmazonClientException *exception) {
NSLog(@" \n\n\nexception %@ \n\n\n", exception);
}
@finally {
NSLog(@"Done");
}
}
我收到以下错误消息和异常。任何帮助,将不胜感激。
objc [1938]:类AXEmojiUtilities在/Applications/Xcode5-DP.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/中实现。 PrivateFrameworks / AccessibilityUtilities.framework / AccessibilityUtilities和/Applications/Xcode5-DP.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libAXSpeechManager.dylib。将使用两者之一。哪一个未定义。
2013-01-17 17:16:51.807 AssumeRoleTest [1938:3207] NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9807)
2013-01-17 17:16:51.810 AssumeRoleTest [1938:c07]
exception AmazonServiceException {RequestId:(null),ErrorCode:(null),Message:Error Domain = NSURLErrorDomain Code = -1202“此服务器的证书无效。您可能正在连接到假装为”sts.amazonaws的服务器.com“这可能会使您的机密信息面临风险。” UserInfo = 0xa381cb0 {NSErrorFailingURLStringKey = https://sts.amazonaws.com/,NSLocalizedRecoverySuggestion =您是否还要连接到服务器?,NSErrorFailingURLKey = https://sts.amazonaws.com/,NSLocalizedDescription =此服务器的证书无效。您可能连接到假装为“sts.amazonaws.com”的服务器,这可能会使您的机密信息面临风险。,NSUnderlyingError = 0x8a64a70“此服务器的证书无效。您可能正在连接到服务器假装是“sts.amazonaws.com”,可能会使您的机密信息面临风险。“,NSURLErrorFailingURLPeerTrustErrorKey =}}
还有一个问题。如何在请求中提供政策详情?我的意思是直接可以粘贴json格式吗?
{ “声明”:[ { “效果”:“允许”, “行动”:[ “S3:将*”, “S3:获取*” ] “资源”:[ “*” ] } ] }
答案 0 :(得分:1)
我是AWS SDK for iOS的维护者之一。我会尝试一次解决您的问题。
AssumeRoleRequest
是已签名的请求,并且要求您使用凭据初始化AmazonSecurityTokenServiceClient
。您可能需要考虑使用AssumeRoleWithWebIdentityRequest
。我们有a sample,其中显示了如何使用Web联合身份验证。最后,您的代码中只需要以下导入行:
#import <AWSRuntime/AWSRuntime.h>
#import <AWSSecurityTokenService/AWSSecurityTokenService.h>