僕が作ったサービス

clanworkz

2016年2月17日水曜日

CognitoIdentityCredentials is not authorized to perform: SNS:CreatePlatformEndpoint on resource

Error Domain=com.amazonaws.AWSSNSErrorDomain Code=4 "(null)" UserInfo={Type=Sender, Message=User: arn:aws:sts::760948203691:assumed-role/Cognito_TokyoCasinoUnauth_Role/CognitoIdentityCredentials is not authorized to perform: SNS:CreatePlatformEndpoint on resource: arn:aws:sns:ap-northeast-1:760948203691:app/APNS_SANDBOX/tokyo-casino, Code=AuthorizationError, __text=(    "\n    ",    "\n    ",    "\n    ",    "\n  ")}


  1. CognitoとSNSは同一のregionを指定。異なるregion(例:CognitoはUS、SNSはTokyo)だとエラーになり、エンドポイントは登録されない
  2. Cognitoの「Edit identity pool」から「Unauthenticated role」と「Authenticated role」にセットされてるロールをチェック
  3. IAMのロールから上記で確認したロールを編集する
  4. 編集内容は「インラインポリシー」でポリシーの編集から「sns:CreatePlatformEndpoint」とSNSにあったARNsを設定

こんな感じで
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "mobileanalytics:PutEvents",
                "cognito-sync:*",
                "sns:CreatePlatformEndpoint",
                "sns:SetEndpointAttributes",
                "sns:Subscribe",
                "sns:Unsubscribe"
            ],
            "Resource": [
                "arn:*****************",
                "arn:*****************"
            ]
        }
    ]
}

参考サイト↓