0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

クロスアカウントのカスタムイベントバスを作ってみる。

Posted at

はじめに

今回はイベントバスのアクセス許可周りを見てみます。

イベント送信できるのは同一アカウントのみ。

初期状態では、イベント送信できるのは同一アカウントのみとのことなので、動作確認してみます。

適当なカスタムイベントバスCross-Account-BusをアカウントAに作ってみます。

スクリーンショット 2025-02-18 4.13.04.png

アカウントBでCLIを利用し、アカウントAのカスタムイベントバスにイベント送信(put-events)してみます!

aws events put-events \
  --entries '[{
    "Source": "custom.application",
    "DetailType": "paid",
    "Detail": "{\"payment_number\": \"00001\"}",
    "EventBusName": "arn:aws:events:ap-northeast-1:AAAAAAAAAAAA:event-bus/Cross-Account-Bus"
  }]' \
  --region ap-northeast-1

確かに以下のようなエラーが出ました。

An error occurred (AccessDeniedException) when calling the PutEvents operation: User: arn:aws:sts::BBBBBBBBBBBB:assumed-role/AWSReservedSSO_AdministratorAccess_27a704c6bb0e0488/chelky is not authorized to perform: events:PutEvents on resource: arn:aws:events:ap-northeast-1:AAAAAAAAAAAA:event-bus/Cross-Account-Bus because no resource-based policy allows the events:PutEvents action

no resource-based policy allows the events:PutEvents actionとあり、リソースベースのポリシーで許可されていないよ。って感じです。

リソースベースのポリシーを設定してみる。

エラーの通り、リソースベースのポリシーを設定してみます。

テンプレートをロード機能があるので、作成は簡単です。

スクリーンショット 2025-02-18 4.27.27.png

こんな感じで設定してみました。

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "AllowAccountToPutEvents",
    "Effect": "Allow",
    "Principal": {
      "AWS": "arn:aws:iam::BBBBBBBBBBBB:root"
    },
    "Action": "events:PutEvents",
    "Resource": "arn:aws:events:ap-northeast-1:853835738220:event-bus/Cross-Account-Bus"
  }]
}

動作確認

リソースベースのポリシーを設定後、再度アカウントBからイベントを送信すると、無事イベント送信できました!

スクリーンショット 2025-02-18 4.33.12.png

最後に

簡単な記事でしたが、カスタムイベントバスとリソースベースのポリシーを触ることができました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?