AWS Cognito IAM:InvalidSmsRoleTrustRelationshipException:角色没有允许 Cognito 承担该角色的信任关系

Dat*_*ray 3 amazon-web-services amazon-iam amazon-cognito aws-lambda

我正在尝试使用 Go lang 通过 lambda 函数创建 Cognito 用户池。

已成功创建 IAM 角色、IAM 策略和信任关系策略。

但是当我尝试创建 Cognito 池时,出现错误,

InvalidSmsRoleTrustRelationshipException: Role does not have a trust relationship allowing Cognito to assume the role.

信任关系政策是

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "cognito-idp.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

创建用户池 API 调用如下 -

newUserPoolData := &cognitoidentityprovider.CreateUserPoolInput{
        PoolName:               aws.String(poolName),
        Policies:               &userPoolPolicyType,
        AutoVerifiedAttributes: autoVerifiedAttributes,
        UsernameAttributes:     userNameAttributes,
        SmsConfiguration:       &smsConfingType,
    }
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?

Aks*_*hah 5

服务角色策略应该有路径service-role。例如 arn 的格式应为arn:aws:iam::{ACCOUNT_ID}:role/service-role/{role_name}

信任关系应该是:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "cognito-idp.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "sts:ExternalId": "{External ID}"
        }
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

并且角色的内联策略应该是

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sns:publish"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)