AWS Cognito 和 API 网关身份验证

joh*_*nny 1 amazon-web-services amazon-iam amazon-cognito aws-lambda aws-api-gateway

我在 API 网关(身份验证:AWS_IAM)下设置了一个 GET 方法,并且有一个带有开发人员身份的 Cognito 池。我在 get 方法后面有一个 lambda。

当我调用 Cognito 时,我会获得临时凭证并承担一个角色。我担任的角色具有在 API 网关上执行和访问所有内容的适当权限。

       ...
       {
            "Effect": "Allow",
            "Action": [
                "execute-api:Invoke"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "apigateway:GET"
            ],
            "Resource": [
                "*"
            ]
        }
        ...
Run Code Online (Sandbox Code Playgroud)

当我使用此设置调用 API 网关时,我收到 500,内部服务器错误。

如果我从策略中删除上述 API 网关权限,那么我会得到 403 error forbidden (User: arn:aws:sts::xxxxx:assumed-role/Cogn_Auth_Role/xxx is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:us-east-1:xxxx:xxx/xxx/GET/events

如果我去并将 附加AdminAccess到这个角色,那么一切正常。这里有什么交易?我错过了什么吗?

joh*_*nny 6

因此,在像这样修改 cognito 角色的策略后,它开始正常工作。

  {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "lambda:InvokeFunction"
                ],
                "Resource": [
                    "*"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "execute-api:Invoke"
                ],
                "Resource": [
                    "*"
                ]
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)

使其工作的重要部分:

  {
        "Effect": "Allow",
        "Action": [
            "lambda:InvokeFunction"
        ],
        "Resource": [
            "*"
        ]
    }
Run Code Online (Sandbox Code Playgroud)

仍然不确定为什么我应该为所有 lambda 调用权限。