Skip to content

當使用 API Gateway 的跨帳戶 IAM 驗證調用 API 時,如何解決「HTTP 403 Forbidden」錯誤?

1 分的閱讀內容
0

我使用跨帳戶 AWS Identity and Access Management (IAM) 實體 (使用者或角色) 呼叫我的 Amazon API Gateway API。我收到「HTTP 403 Forbidden」錯誤。

解決方法

REST API

若要存取 API Gateway REST API,請在 API Gateway 主控台中開啟 API 方法的 IAM 驗證。然後,使用 IAM 政策和資源政策為 API 使用者指定許可。

確定跨帳戶 IAM 實體具有調用 API 的許可,並且允許在資源政策中存取。

在此範例中,帳戶 A 111111111 的 REST API 已啟用 IAM 驗證。User1 嘗試從帳戶 B 999999999 中調用。帳戶 B 中的 User1 附有以下 IAM 政策:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "execute-api:Invoke",
        "execute-api:ManageConnections"
      ],
      "Resource": "arn:aws:execute-api:us-east-1:111111111:AB12CDEF34/*/*/*"
    }
  ]
}

若要允許在帳戶 A 中帳戶 B 的 IAM 使用者調用跨帳戶存取,請使用類似下列的資源政策:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::999999999:user/User1"
      },
      "Action": "execute-api:Invoke",
      "Resource": "arn:aws:execute-api:us-east-1:111111111:AB12CDEF34/stage/*/*"
    }
  ]
}

如需詳細資訊,請參閱如何啟用 API Gateway REST APIs 的 IAM 驗證?

HTTP APIs

若要存取 API Gateway HTTP API,您可以使用 sts:AssumeRole API 動作來擔任 HTTP API 帳戶的角色。擔任的角色提供臨時安全性憑證,可用於在另一個帳戶中調用 HTTP API。

請確定用於調用 HTTP API 的臨時安全性憑證正確且未過期。

如需詳細資訊,請參閱如何為 API Gateway HTTP API 提供跨帳戶 IAM 授權?

相關資訊

API Gateway 資源政策範例