我在嘗試使用此代碼認購在iOS終端的SNS話題:AWS無法訂閱SNS主題:CognitoIdentityCredentials無權執行:SNS:訂閱
let sns = AWSSNS.defaultSNS()
let request = AWSSNSCreatePlatformEndpointInput()
request.token = deviceTokenString
request.platformApplicationArn = SNSPlatformApplicationArn
sns.createPlatformEndpoint(request).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task: AWSTask!) -> AnyObject! in
if task.error != nil {
print(task.error)
} else {
let createEndpointResponse = task.result as! AWSSNSCreateEndpointResponse
// Subscribe to the topic
let subscribeTopicInput = AWSSNSSubscribeInput()
subscribeTopicInput.endpoint = createEndpointResponse.endpointArn
subscribeTopicInput.protocols = "application"
subscribeTopicInput.topicArn = MyTopicARN
sns.subscribe(subscribeTopicInput).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (topicTask: AWSTask!) -> AnyObject! in
if topicTask.error != nil {
// Authorization error prints here
print(topicTask.error)
}
return nil
})
}
return nil
})
嘗試當我收到錯誤訂閱主題:
UserInfo={Type=Sender, Message=User: arn:aws:its::000000000000:assumed-role/appname_unauth_MOBILEHUB_000000000/CognitoIdentityCredentials is not authorized to perform: SNS:Subscribe on resource:...
的this answer筆者解釋說,您必須授予在Cognito角色訪問sns:Subscribe
,讓您的應用程序,使這個電話。我的Cognito用戶已被授予AmazonSNSFullAccess
,允許訪問所有sns操作(例如sns:*
)。爲什麼我的Cognito用戶被拒絕訪問?我的主題策略已設置爲只有主題所有者才能訂閱...但主題所有者似乎與我的Cognito用戶相同。
很高興聽到你的工作。一如果你有任何問題,隨時張貼在這裏或在我們的論壇。 –
另一個注意事項:你不能只複製/粘貼上面,它將無法驗證。不應該給予完全訪問權限。最簡單的方法是使用策略生成器並選擇SNS和訂閱。超級簡單。 – user3344977