我正在尝试使用以下代码将iOS终结点订阅到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:...
该答案的作者解释说,您必须以sns:Subscribe
Cognito角色授予对的访问权限,以允许您的应用程序进行此调用。我的Cognito用户已被授予AmazonSNSFullAccess
,它允许访问所有sns动作(例如sns:*
)。为什么我的Cognito用户被拒绝访问?设置我的主题政策,以便只有主题所有者可以订阅...,但是主题所有者似乎与我的Cognito用户相同。
我曾使用Amazon Mobile Hub为我配置推送通知。我没有意识到Mobile Hub在该过程中创建了三个角色:
iOS应用正在使用appname_unauth_MOBILEHUB_00000000
角色而不是我手动创建的用户进行连接。此角色不允许sns:Subscribe
。
要解决,请执行以下任一操作:
AmazonSNSFullAccess
适当的角色sns:Subscribe
所有资源使用(更好的IMO)例子:
{
"Effect": "Allow",
"Action": [
"sns:Subscribe"
],
"Resource": [
"*"
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句