

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon EventBridge 中事件匯流排的許可
<a name="eb-event-bus-perms"></a>

您 AWS 帳戶中的預設[事件匯流排](eb-event-bus.md)僅允許來自一個帳戶[的事件](eb-events.md)。您可以將[以資源為基礎的政策](eb-use-resource-based.md)附加至事件匯流排，將其他權限授與事件匯流排。使用以資源為基礎的策略，您可以允許來自另一個帳戶的 `PutEvents`、`PutRule`、和 `PutTargets` API 呼叫。您也可以在政策中使用 [IAM 條件](eb-use-conditions.md)，將許可授予組織、套用[標籤](eb-tagging.md)或僅篩選特定規則或帳戶中的事件。您可以在建立事件匯流排時或之後為事件匯流排設定以資源為基礎的政策。

接受事件匯流排 `Name` 參數 (例如 `PutRule`、`PutTargets`、`DeleteRule`、`RemoveTargets`、`DisableRule` 和 `EnableRule`) 的 EventBridge 各種 API，也可以接受事件匯流排 ARN。使用這些參數可透過 API 參考跨帳戶或跨區域事件匯流排。例如，您可以呼叫 `PutRule` 在不同帳戶中的事件匯流排上建立[規則](eb-rules.md)，而不需要擔任角色。

您可以將本主題中的範例政策附加到 IAM 角色，以授予將事件傳送至其他帳戶或區域的權限。使用 IAM 角色設定組織控制政策和界限，瞭解誰可以將事件從您的帳戶傳送到其他帳戶。當規則的目標是事件匯流排時，建議一律使用 IAM 角色。您可以使用 `PutTarget` 呼叫附加 IAM 角色。如需關於建立規則以將事件傳送至其他帳戶或區域的相關資訊，請參閱 [在 Amazon EventBridge 中的 AWS 帳戶之間傳送和接收事件](eb-cross-account.md)。

# 在 Amazon EventBridge 中管理事件匯流排許可
<a name="eb-event-bus-permissions-manage"></a>

使用下列程序修改現有事件匯流排的許可。如需如何使用 CloudFormation 建立事件匯流排政策的資訊，請參閱 [AWS::Events::EventBusPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-eventbuspolicy.html)。

**管理現有事件匯流排的權限**

1. 訪問 [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/) 開啟 Amazon EventBridge 主控台。

1. 在導覽窗格中，選擇**事件匯流排**。

1. 在**名稱**中，選擇要管理其許可的事件匯流排名稱。

   如果資源策略已附加至事件匯流排，則會顯示策略。

1. 選擇**管理許可**，然後進行下列其中一個動作：
   + 輸入包含要授與事件匯流排之權限的政策。您可以貼上來自其他來源的政策，或輸入該政策的 JSON。
   + 若要使用政策的範例，請選擇**載入範例**。根據您的環境適當修改政策，包括新增您授權政策中主體使用的其他動作。

1. 選擇**更新**。

範本提供範例政策陳述式，您可以針對您的帳戶和環境自訂這些陳述式。範本不是有效的政策。您可以修改使用案例的範本，也可以複製其中一個範例政策並加以自訂。

範本會載入政策，其中包括如何授與帳戶以使用 `PutEvents` 動作的權限、如何授與權限給組織，以及如何授與帳戶管理帳戶規則的權限範例。您可以自訂特定帳戶的範本，然後從範本中刪除其他區段。本節稍後將包含更多範例政策。

如果您嘗試更新匯流排的權限，但政策包含錯誤，錯誤訊息會指出政策中的特定問題。

```
  ### Choose which sections to include in the policy to match your use case. ###
  ### Be sure to remove all lines that start with ###, including the ### at the end of the line. ###

  ### The policy must include the following: ###

  {
    "Version": "2012-10-17",		 	 	 
    "Statement": [

      ### To grant permissions for an account to use the PutEvents action, include the following, otherwise delete this section: ###

      {

        "Sid": "AllowAccountToPutEvents",
        "Effect": "Allow",
        "Principal": {
          "AWS": "<ACCOUNT_ID>"
        },
        "Action": "events:PutEvents",
        "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/default"
      },

      ### Include the following section to grant permissions to all members of your AWS Organizations to use the PutEvents action ###

      {
        "Sid": "AllowAllAccountsFromOrganizationToPutEvents",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "events:PutEvents",
        "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/default",
        "Condition": {
          "StringEquals": {
            "aws:PrincipalOrgID": "o-yourOrgID"
          }
        }
      },

      ### Include the following section to grant permissions to the account to manage the rules created in the account ###

      {
        "Sid": "AllowAccountToManageRulesTheyCreated",
        "Effect": "Allow",
        "Principal": {
          "AWS": "<ACCOUNT_ID>"
        },
        "Action": [
          "events:PutRule",
          "events:PutTargets",
          "events:DeleteRule",
          "events:RemoveTargets",
          "events:DisableRule",
          "events:EnableRule",
          "events:TagResource",
          "events:UntagResource",
          "events:DescribeRule",
          "events:ListTargetsByRule",
          "events:ListTagsForResource"],
        "Resource": "arn:aws:events:us-east-1:123456789012:rule/default",
        "Condition": {
          "StringEqualsIfExists": {
            "events:creatorAccount": "<ACCOUNT_ID>"
          }
        }
    }]
  }
```

# 範例政策：將事件傳送至 Amazon EventBridge 中不同帳戶中的預設匯流排
<a name="eb-event-bus-example-policy-cross-account"></a>

下列範例政策會授與帳戶 111122223333 的權限，以便將事件發佈至帳戶 123456789012 中的預設事件匯流排。

------
#### [ JSON ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
       {
        "Sid": "sid1",
        "Effect": "Allow",
        "Principal": {"AWS":"arn:aws:iam::111112222333:root"},
        "Action": "events:PutEvents",
        "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/default"
        }
    ]
  }
```

------

# 範例政策：將事件傳送至 Amazon EventBridge 中不同帳戶中的自訂匯流排
<a name="eb-event-bus-example-policy-cross-account-custom-bus-source"></a>

下列範例政策授與帳戶 111122223333 權限，可將事件發佈至帳戶 123456789012，但僅適用於來源值 `central-event-bus` 設定為 `com.exampleCorp.webStore` 和來源值 `detail-type` 設定為 `newOrderCreated` 的事件。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "WebStoreCrossAccountPublish",
      "Effect": "Allow",
      "Action": [
        "events:PutEvents"
      ],
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:root"
      },
      "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/central-event-bus",
      "Condition": {
        "ForAllValues:StringEquals": {
          "events:source": "com.exampleCorp.webStore",
          "events:detail-type": "newOrderCreated"
        }
      }
    }
  ]
}
```

------

# 範例政策：將事件傳送至 Amazon EventBridge 中相同帳戶中的事件匯流排
<a name="eb-event-bus-example-policy-same-account"></a>

下列附加至事件匯流排的範例政策 `CustomBus1` 可讓事件匯流排接收來自相同帳戶和區域的事件。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "events:PutEvents"
            ],
            "Resource": [
                "arn:aws:events:us-east-1:111122223333:event-bus/CustomBus1"
            ]
        }
    ]
}
```

------

# 範例政策：將事件從特定規則傳送至不同區域中的 Amazon EventBridge 匯流排
<a name="eb-event-bus-example-policy-restrict-rule"></a>

下列範例政策授與帳戶 111122223333 權限，令其可將符合中東 (巴林) 和美國西部 (奧勒岡) 區域中以 `SendToUSE1AnotherAccount` 命名之規則的事件傳送至美國東部 (維吉尼亞北部) 帳戶 123456789012 中以 `CrossRegionBus` 命名的事件匯流排。範例政策會新增至帳戶 123456789012 `CrossRegionBus` 中指定的事件匯流排。只有當事件符合帳戶 111122223333 中為事件匯流排指定的規則時，此政策才允許事件。陳述式 `Condition` 會將事件限制為僅符合規則與指定規則 ARN 的事件。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowSpecificRulesAsCrossRegionSource",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111112222333:root"
      },
      "Action": "events:PutEvents",
      "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": [
            "arn:aws:events:us-west-2:111112222333:rule/CrossRegionBus/SendToUSE1AnotherAccount",
            "arn:aws:events:me-south-1:111112222333:rule/CrossRegionBus/SendToUSE1AnotherAccount"
          ]
        }
      }
    }
  ]
}
```

------

# 範例政策：僅將事件從特定區域傳送至 Amazon EventBridge 中的不同區域
<a name="eb-event-bus-example-policy-specific-region"></a>

下列範例政策授與帳戶 111122223333 權限，令其可將在中東 (巴林) 和美國西部 (奧勒岡) 區域中發生的事件傳送至美國東部 (維吉尼亞北部) 帳戶 123456789012 中以 `CrossRegionBus` 命名的事件匯流排。帳戶 111122223333 沒有傳送任何其他區域產生之事件的權限。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowCrossRegionEventsFromUSWest2AndMESouth1",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111112222333:root"
      },
      "Action": "events:PutEvents",
      "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": [
            "arn:aws:events:us-west-2:*:*",
            "arn:aws:events:me-south-1:*:*"
          ]
        }
      }
    }
  ]
}
```

------

# 範例政策：拒絕從 Amazon EventBridge 中的特定區域傳送事件
<a name="eb-event-bus-example-policy-deny-regions"></a>

下列附加至帳戶 123456789012 中以 `CrossRegionBus` 命名的事件匯流排的範例政策會授與事件匯流排接收來自帳戶 111122223333 的事件的權限，但不授與在美國西部 (奧勒岡) 區域產生的事件。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "1AllowAnyEventsFromAccount111112222333",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111112222333:root"
      },
      "Action": "events:PutEvents",
      "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus"
    },
    {
      "Sid": "2DenyAllCrossRegionUSWest2Events",
      "Effect": "Deny",
      "Principal": {
        "AWS": "*"
      },
      "Action": "events:PutEvents",
      "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/CrossRegionBus",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": [
            "arn:aws:events:us-west-2:*:*"
          ]
        }
      }
    }
  ]
}
```

------