我正在使用包括 dynamodb 和 s3 在内的服务和 ios 用于自定义登录用户池,该用户池由联合身份使用,为经过身份验证和未经身份验证的用户提供角色。这完美无缺。
然后,当我使用 AWS AppSync 时,我只是在执行一个 Mutation 并且我收到一条错误消息 Unable to take role arn:aws:iam::xxxxxxxxxx:role/xxxxxxxxx 。尝试由 AppSync 使用的这个 arn:aws:iam:xxx/xxx 角色不是我想要使用的角色,并且 iam 角色与 DynamoDb 和 s3 出于某种原因使用的角色不同,即使我是不改变代码中使用的任何 cognitoid。请参阅下面的一些示例代码。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// CognitoIdentityUserPoolId is the id of the federated identity from console. works fine with all services except for AppSync by wrong Iam role being chosen
let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: CognitoIdentityUserPoolAppClientId, clientSecret: CognitoIdentityUserPoolAppClientSecret, poolId: CognitoIdentityUserPoolId)
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: AWSCognitoUserPoolsSignInProviderKey)
pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolsSignInProviderKey)
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: CognitoIdentityUserPoolId, identityProviderManager:pool)
let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
pool?.delegate = self
return true
}
// In SampleViewController
// after user signs in
let appSyncConfig = try AWSAppSyncClientConfiguration(url: AppSyncEndpointURL, serviceRegion: CognitoIdentityUserPoolRegion, userPoolsAuthProvider: self)
// Initialize the AWS AppSync client
self.appSyncClient = try AWSAppSyncClient(appSyncConfig: appSyncConfig)
// Set id as the cache key for objects
self.appSyncClient?.apolloClient?.cacheKeyForObject = { $0["id"] }
// later on in the file....
extension SampleViewController: AWSCognitoUserPoolsAuthProvider{
func getLatestAuthToken() -> String {
return (myUserSess?.idToken?.tokenString)!
}
}
AWS AppSync 尝试使用错误的 Iam 名称的任何帮助/原因?