首页 > 解决方案 > 如何配置 AWS API Gateway 以从另一个 AWS 账户访问它

问题描述

我想向其他账户的 IAM 用户授予访问权限,以便能够调用我的 API。

我的 API Gateway 资源方法中有这些配置:

Authorization type: AWS_IAM(我也尝试过使用 Auth 类型None..)

资源策略定义为:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<ACCOUNT_2>:user/ApiUser"
            },
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:us-west-2:<ACCOUNT_1>:<API_ID>/*/*/*"
        }
    ]
}

我还向另一个账户的 IAM 用户授予了调用权限:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "execute-api:Invoke"
            ],
            "Resource": "arn:aws:execute-api:us-west-2:<ACCOUNT_1>:<API_ID>:test/GET/*"
        }
    ]
}

我已将 API 部署到名为test.

尽管如此,当我使用来自其他帐户用户的凭据调用 API 时,仍会看到以下错误:

{
    "message": "User: arn:aws:iam::<ACCOUNT_2>:user/ApiUser is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:us-west-<ACCOUNT_1>:<API_ID>/test/GET/foo/bar"
}

我在这里想念什么?

我遵循了本指南: https ://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies-examples.html

标签: amazon-web-servicesaws-api-gatewayapi-gateway

解决方案


这曾经咬过我,也可能是你的问题。

保存资源策略后,还必须部署 API。

  • 在左侧菜单中,单击上一级
  • 然后在操作下,选择部署 API

推荐阅读