Cognito授权器中API网关中的{“消息":“未经授权"}

问题描述:

当我将Cognito授权者添加到API网关中定义的API时,出现{"message":"Unauthorized"}错误.我做了以下事情:

I get {"message":"Unauthorized"} error when I add cognito authorizer to my API defined in API Gateway. I did the following:

  1. 配置了Cognito授权者
  2. 在API方法中添加了授权者
  3. 部署了API

当我点击API网址时.我收到{"message":"Unauthorized"}错误.我想念什么吗?

As i hit the API url. I get the {"message":"Unauthorized"} error. Am I missing anything?

对于Cognito IAM角色,必须缺少Execute-API权限.

Execute-API permission must be be missing for the Cognito IAM role.

IAM策略示例以分配权限:

IAM Policy example to assign the permissions:


{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "execute-api:Invoke"
            ],
            "Resource": [
                "arn:aws:execute-api:*:*:{{APIGateway_API_ID}}/*"
            ]
        }
    ]
}