AWS Cognito IAM: InvalidSmsRoleTrustRelationshipException:角色没有信任关系允许Cognito扮演该角色

3

我正在尝试使用Go语言通过Lambda函数创建Cognito用户池。

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

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

InvalidSmsRoleTrustRelationshipException: 角色没有信任关系允许Cognito扮演该角色。

信任关系策略如下:

{
  "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,
    }

这里我有所疏漏吗?
1个回答

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}"
        }
      }
    }
  ]
}

角色的内联策略应该是什么?
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sns:publish"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

我在插入了上述代码后仍然遇到相同的错误。 - msbomrel
1
@akshay-shah 非常感谢你。你的回答帮助我解决了我的问题。 - Ishan
{External ID}是什么?在哪里创建或查找它? - lazzy_ms
你可以删除整个条件部分,它只是添加条件的示例。 - gtopcu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接