我正在尝试在 Objective C 中使用 AWSCognito
对 Amazon SimpleDB 数据库进行身份验证。
我使用我的 Amazon 账户中提供的身份池 ID 初始化了一个 AWSCognitoCredentialsProvider
。问题是,当我尝试从 AWSCognitoCredentialsProvider
对象获取访问 key 和 secret key 时,它们为零。
我像这样初始化凭证提供程序:
AWSCognitoCredentialsProvider *credentialsProvider = [AWSCognitoCredentialsProvider credentialsWithRegionType:AWSRegionUSEast1 accountId:ACCOUNT_ID identityPoolId:IDENTITY_POOL_ID unauthRoleArn:UNAUTH_ROLE authRoleArn:AUTH_ROLE];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
之后,我尝试像这样初始化一个 SimpleDB 客户端:
sdbClient = [[AmazonSimpleDBClient alloc] initWithAccessKey:[credentialsProvider accessKey] withSecretKey:[credentialsProvider secretKey]];
我做错了什么吗?
最佳答案
您是否混合使用适用于 iOS 的 AWS 移动开发工具包版本 1 和版本 2?它们不是为一起使用而设计的,您应该考虑完全迁移到版本 2。
v2 SDK 在适当的时候自动调用凭据提供程序的 -refresh
。因为您没有使用 AWSSimpleDB
,所以从未调用过 -refresh
,这就是 accessKey
和 secretKey
返回的原因无
。
AWSCognitoCredentialsProvider
生成由 accessKey
、secretKey
和 sessionKey
组成的 AWS 临时凭证。 - initWithAccessKey:withSecretKey:
不获取临时凭证,即使您在凭证提供程序上手动调用 - refresh
,AmazonSimpleDBClient
也不起作用。
我建议使用 AWSSimpleDB
而不是 AmazonSimpleDBClient
重写应用程序,以便使用 Amazon Cognito Identity。
关于ios - AWS Cognito Credentials Provider for IOS - 访问 key 和 secret key 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29010644/