【问题标题】:AWS Cognito IAM : InvalidSmsRoleTrustRelationshipException: Role does not have a trust relationship allowing Cognito to assume the roleAWS Cognito IAM:InvalidSmsRoleTrustRelationshipException:角色没有允许 Cognito 代入该角色的信任关系
【发布时间】:2019-10-28 22:05:00
【问题描述】:

我正在尝试使用 Go 语言通过 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"
    }
  ]
}

创建用户池 API 调用如下 -

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

我错过了什么吗?

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cognito amazon-iam


    【解决方案1】:

    服务角色策略应具有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}"
            }
          }
        }
      ]
    }
    

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

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "sns:publish"
                ],
                "Resource": [
                    "*"
                ]
            }
        ]
    }
    

    【讨论】:

    • 插入上述代码后,我仍然遇到同样的错误。
    • @akshay-shah 非常感谢。您的回答帮助解决了我的问题。
    • {External ID} 是什么?在哪里创建或找到它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 2020-10-03
    • 2018-10-08
    • 2017-09-02
    • 2017-05-15
    • 2018-03-16
    • 2019-08-15
    相关资源
    最近更新 更多