将基于身份的策略(IAM 策略)用于 Amazon EventBridge - 亚马逊 EventBridge
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

将基于身份的策略(IAM 策略)用于 Amazon EventBridge

基于身份的策略是附加到 IAM 身份的权限策略。

Amazon的托管策略 EventBridge

Amazon通过提供由创建和管理的独立 IAM policy来满足许多常用案例的要求。Amazon托管式策略或预定义策略可针对常用案例授予必要的权限,因此您无需调查所需权限的工作。有关更多信息,请参阅《IAM 用户指南》中的 Amazon 托管式策略

以下Amazon托管式策略(可附加到您账户中的用户)是特定于的 EventBridge:

  • AmazonEventBridgeFullAccess— 授予对 EventBridge 管道 EventBridge、 EventBridge 架构和 EventBridge 调度程序的完全访问权限。

  • AmazonEventBridgeReadOnlyAccess— 授予对 EventBridge 管道 EventBridge、 EventBridge 架构和 EventBridge 调度程序的只读访问权限。

AmazonEventBridgeFullAccess 策略

该 AmazonEventBridgeFullAccess 策略授予使用所有 EventBridge 操作的权限以及以下权限:

  • iam:CreateServiceLinkedRole— EventBridge 需要此权限才能在您的账户中为 API 目标创建服务角色。此权限仅授予在您的账户中专门为 API 目标创建角色的 IAM 服务权限。

  • iam:PassRole— EventBridge 需要此权限才能将调用角色传递给 EventBridge 才能调用规则的目标。

  • S@@ ecrets Manager 权限 — 当您通过连接资源提供证书以授权 API 目的地时, EventBridge需要这些权限才能管理账户中的密钥。

以下 JSON 显示了该 AmazonEventBridgeFullAccess 策略。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "EventBridgeActions", "Effect": "Allow", "Action": [ "events:*", "schemas:*", "scheduler:*", "pipes:*" ], "Resource": "*" }, { "Sid": "IAMCreateServiceLinkedRoleForApiDestinations", "Effect": "Allow", "Action": "iam:CreateServiceLinkedRole", "Resource": "arn:aws:iam::*:role/aws-service-role/AmazonEventBridgeApiDestinationsServiceRolePolicy", "Condition": { "StringEquals": { "iam:AWSServiceName": "apidestinations.events.amazonaws.com" } } }, { "Sid": "IAMCreateServiceLinkedRoleForAmazonEventBridgeSchemas", "Effect": "Allow", "Action": "iam:CreateServiceLinkedRole", "Resource": "arn:aws:iam::*:role/aws-service-role/schemas.amazonaws.com/AWSServiceRoleForSchemas", "Condition": { "StringEquals": { "iam:AWSServiceName": "schemas.amazonaws.com" } } }, { "Sid": "SecretsManagerAccessForApiDestinations", "Effect": "Allow", "Action": [ "secretsmanager:CreateSecret", "secretsmanager:UpdateSecret", "secretsmanager:DeleteSecret", "secretsmanager:GetSecretValue", "secretsmanager:PutSecretValue" ], "Resource": "arn:aws:secretsmanager:*:*:secret:events!*" }, { "Sid": "IAMPassRoleAccessForEventBridge", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::*:role/*", "Condition": { "StringLike": { "iam:PassedToService": "events.amazonaws.com" } } }, { "Sid": "IAMPassRoleAccessForScheduler", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::*:role/*", "Condition": { "StringLike": { "iam:PassedToService": "scheduler.amazonaws.com" } } }, { "Sid": "IAMPassRoleAccessForPipes", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::*:role/*", "Condition": { "StringLike": { "iam:PassedToService": "pipes.amazonaws.com" } } } ] }
注意

本节中的信息也适用于该CloudWatchEventsFullAccess政策。但是,强烈建议您使用亚马逊 EventBridge 而不是亚马逊 CloudWatch 活动。

AmazonEventBridgeReadOnlyAccess 策略

该 AmazonEventBridgeReadOnlyAccess 策略授予使用所有读取 EventBridge 操作的权限。

以下 JSON 显示了该 AmazonEventBridgeReadOnlyAccess 策略。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "events:DescribeRule", "events:DescribeEventBus", "events:DescribeEventSource", "events:ListEventBuses", "events:ListEventSources", "events:ListRuleNamesByTarget", "events:ListRules", "events:ListTargetsByRule", "events:TestEventPattern", "events:DescribeArchive", "events:ListArchives", "events:DescribeReplay", "events:ListReplays", "events:DescribeConnection", "events:ListConnections", "events:DescribeApiDestination", "events:ListApiDestinations", "events:DescribeEndpoint", "events:ListEndpoints", "schemas:DescribeCodeBinding", "schemas:DescribeDiscoverer", "schemas:DescribeRegistry", "schemas:DescribeSchema", "schemas:ExportSchema", "schemas:GetCodeBindingSource", "schemas:GetDiscoveredSchema", "schemas:GetResourcePolicy", "schemas:ListDiscoverers", "schemas:ListRegistries", "schemas:ListSchemas", "schemas:ListSchemaVersions", "schemas:ListTagsForResource", "schemas:SearchSchemas", "scheduler:GetSchedule", "scheduler:GetScheduleGroup", "scheduler:ListSchedules", "scheduler:ListScheduleGroups", "scheduler:ListTagsForResource", "pipes:DescribePipe", "pipes:ListPipes", "pipes:ListTagsForResource" ], "Resource": "*" } ] }
注意

本节中的信息也适用于该CloudWatchEventsReadOnlyAccess政策。但是,强烈建议您使用亚马逊 EventBridge 而不是亚马逊 CloudWatch 活动。

EventBridge 特定于的托管式策略

架构定义了发送到的事件的结构 EventBridge。 EventBridge 为Amazon服务生成的所有事件提供架构。以下特定于 EventBridge 架构的Amazon托管策略可用:

EventBridge 特定于的托管式策略

Amazon Schedul EventBridge er 是一款无服务器调度程序,允许您通过一项中央托管服务创建、运行和管理任务。有关特定于 EventBridge 调度程序的Amazon托Amazon管策略,请参阅《 EventBridge 调度程序用户指南》中的EventBridge 调度程序托管策略。

EventBridge 管道特定于的托管式策略

Amazon Pip EventBridge es 将事件源连接到目标。在开发事件驱动架构时,Pipes 减少了对专业知识和集成代码的需求。这有助于确保贵公司应用程序之间的一致性。以下Amazon专用于 EventBridge 管道的托管策略可用:

用于发送事件的 IAM 角色

要将事件中继到目标, EventBridge 需要一个 IAM 角色。

创建 IAM 角色以将事件发送到 EventBridge
  1. 通过以下网址打开 IAM 控制台:https://console.aws.amazon.com/iam/

  2. 要创建 IAM 角色,请执行 I A M 用户指南中创建角色以向Amazon服务委派权限中的步骤。执行这些步骤时,请执行以下操作:

    • 角色名称中,使用您账户内唯一的名称。

    • 选择角色类型中,选择Amazon服务角色,然后选择亚马逊 EventBridge。这会授予代入该角色的相关 EventBridge 权限。

    • 在 “附加策略” 中,选择AmazonEventBridgeFullAccess

此外,您还可以创建您自己的自定义 IAM 策略,以授予 EventBridge 操作和资源的相关权限。您可以将这些自定义策略附加到需要这些权限的 IAM 用户或组。有关 IAM 策略的更多信息,请参阅《IAM 用户指南》中的 IAM 策略概述。有关管理和创建自定义 IAM 策略的更多信息,请参阅《IAM 用户指南》中的管理 IAM 策略

使用 IAM 角色 EventBridge 访问目标所需的权限

EventBridge 目标通常需要授予调用目标权 EventBridge 限的 IAM 角色。以下是各种Amazon服务和目标的一些示例。对于其他人,使用 EventBridge 控制台创建规则并创建一个新角色,该角色将使用预先配置了范围合理的权限的策略来创建。

Amazon SQS、Amazon SNS、Lambda、L CloudWatch ogs 和 EventBridge 总线目标不使用角色, EventBridge 必须通过资源策略授予权限。API Gateway 目标可以使用资源策略或 IAM 角色。

如果目标是 API 目标,则您指定的角色必须包含以下策略。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "events:InvokeApiDestination" ], "Resource": [ "arn:aws:events:::api-destination/*" ] } ] }

如果目标是 Kinesis 流,则用于向该目标发送事件数据的角色必须包含以下策略。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "kinesis:PutRecord" ], "Resource": "*" } ] }

如果目标是 Systems Manager 运行命令,并且您为该命令指定了一个或多个InstanceIds值,则您指定的角色必须包含以下策略。

{ "Version": "2012-10-17", "Statement": [ { "Action": "ssm:SendCommand", "Effect": "Allow", "Resource": [ "arn:aws:ec2:region:accountId:instance/instanceIds", "arn:aws:ssm:region:*:document/documentName" ] } ] }

如果目标是 Systems Manager run 命令,并且您为该命令指定了一个或多个标签,则您指定的角色必须包含以下策略。

{ "Version": "2012-10-17", "Statement": [ { "Action": "ssm:SendCommand", "Effect": "Allow", "Resource": [ "arn:aws:ec2:region:accountId:instance/*" ], "Condition": { "StringEquals": { "ec2:ResourceTag/*": [ "[[tagValues]]" ] } } }, { "Action": "ssm:SendCommand", "Effect": "Allow", "Resource": [ "arn:aws:ssm:region:*:document/documentName" ] } ] }

如果目标是 Amazon Step Functions 状态机,则您指定的角色必须包含以下策略。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "states:StartExecution" ], "Resource": [ "arn:aws:states:*:*:stateMachine:*" ] } ] }

如果目标为 Amazon ECS 任务,则您指定的角色必须包含以下策略。

{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "ecs:RunTask" ], "Resource": [ "arn:aws:ecs:*:account-id:task-definition/task-definition-name" ], "Condition": { "ArnLike": { "ecs:cluster": "arn:aws:ecs:*:account-id:cluster/cluster-name" } } }, { "Effect": "Allow", "Action":"iam:PassRole", "Resource": [ "*" ], "Condition": { "StringLike": { "iam:PassedToService": "ecs-tasks.amazonaws.com" } } }] }

以下策略允许中的 EventBridge 内置目标代表您执行 Amazon EC2 操作。您需要使用Amazon Web Services Management Console来创建带有内置目标的规则。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "TargetInvocationAccess", "Effect": "Allow", "Action": [ "ec2:Describe*", "ec2:RebootInstances", "ec2:StopInstances", "ec2:TerminateInstances", "ec2:CreateSnapshot" ], "Resource": "*" } ] }

以下政策允许 EventBridge 将事件中继到您账户中的 Kinesis 直播。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "KinesisAccess", "Effect": "Allow", "Action": [ "kinesis:PutRecord" ], "Resource": "*" } ] }

客户管理的策略示例:使用标记控制规则的访问权限

以下示例显示了一个授予 EventBridge 操作权限的用户策略。当您使用 EventBridge API、Amazon SDK 或时,此政策有效Amazon CLI。

您可以授予用户访问特定 EventBridge 规则的权限,同时阻止他们访问其他规则。为此,您可以标记这两组规则,然后使用引用这些标记的 IAM 策略。有关标记 EventBridge 资源的更多信息,请参阅亚马逊 EventBridge 标签

您可以为用户授予 IAM 策略,以仅允许访问具有特定标记的规则。您可以通过使用该特定标签来选择授予访问权限的规则。例如,以下策略向用户授予对标签密钥值Prod为的规则的访问权限Stack

{ "Statement": [ { "Effect": "Allow", "Action": "events:*", "Resource": "*", "Condition": { "StringEquals": { "aws:ResourceTag/Stack": "Prod" } } } ] }

有关使用 IAM 策略语句的更多信息,请参阅 IAM 用户指南中的使用策略控制访问

亚马逊 EventBridge 更新Amazon了托管政策

查看有关此服务开始跟踪这些更改以 EventBridge 来的Amazon托管策略更新的详细信息。有关此页面更改的自动提示,请订阅 EventBridge 文档历史记录页面上的 RSS 源。

更改 说明 日期

AmazonEventBridgePipesFullAccess— 添加了新政策

EventBridge 为使用 Pipes 的完全权限添加了托 EventBridge 管策略。

2 月 1 月 1 月 1 月 1

AmazonEventBridgePipesReadOnlyAccess— 添加了新政策

EventBridge 为查看 Pip EventBridge es 信息资源的权限添加了托管策略。

2 月 1 月 1 月 1 月 1

AmazonEventBridgePipesOperatorAccess— 添加了新政策

EventBridge 为查看 EventBridge 管道信息以及启动和停止运行管道的权限添加了托管策略。

2 月 1 月 1 月 1 月 1

AmazonEventBridgeFullAccess – 对现有策略的更新

EventBridge 更新了策略,加入了使用 Pip EventBridge es 功能所需的权限。

2 月 1 月 1 月 1 月 1

AmazonEventBridgeReadOnlyAccess – 对现有策略的更新

EventBridge 添加了查看 Pip EventBridge es 信息资源所需的权限。

添加了以下操作:

  • pipes:DescribePipe

  • pipes:ListPipes

  • pipes:ListTagsForResource

2 月 1 月 1 月 1 月 1

CloudWatchEventsReadOnlyAccess – 对现有策略的更新

已更新为匹配 AmazonEventBridgeReadOnlyAccess。

2 月 1 月 1 月 1 月 1

CloudWatchEventsFullAccess – 对现有策略的更新

已更新为匹配 AmazonEventBridgeFullAccess。

2 月 1 月 1 月 1 月 1

AmazonEventBridgeFullAccess – 对现有策略的更新

EventBridge 更新了策略,加入了使用架构和调度程序功能所需的权限。

添加了以下权限:

  • EventBridge 架构注册表操作

  • EventBridge 计划程序操作

  • iam:CreateServiceLinkedRole EventBridge 架构注册表的权限

  • iam:PassRole EventBridge 调度程序的权限

2022 年 11 月 10 日

AmazonEventBridgeReadOnlyAccess – 对现有策略的更新

EventBridge 添加了查看架构和调度程序信息资源所需的权限。

添加了以下操作:

  • schemas:DescribeCodeBinding

  • schemas:DescribeDiscoverer

  • schemas:DescribeRegistry

  • schemas:DescribeSchema

  • schemas:ExportSchema

  • schemas:GetCodeBindingSource

  • schemas:GetDiscoveredSchema

  • schemas:GetResourcePolicy

  • schemas:ListDiscoverers

  • schemas:ListRegistries

  • schemas:ListSchemas

  • schemas:ListSchemaVersions

  • schemas:ListTagsForResource

  • schemas:SearchSchemas

  • scheduler:GetSchedule

  • scheduler:GetScheduleGroup

  • scheduler:ListSchedules

  • scheduler:ListScheduleGroups

  • scheduler:ListTagsForResource

2022 年 11 月 10 日

AmazonEventBridgeReadOnlyAccess – 对现有策略的更新

EventBridge 添加了查看端点信息所需的权限。

添加了以下操作:

  • events:ListEndpoints

  • events:DescribeEndpoint

2022 年 4 月 7 日

AmazonEventBridgeReadOnlyAccess – 对现有策略的更新

EventBridge 添加了查看连接和 API 目标信息所需的权限。

添加了以下操作:

  • events:DescribeConnection

  • events:ListConnections

  • events:DescribeApiDestination

  • events:ListApiDestinations

2021 年 3 月 4 日

AmazonEventBridgeFullAccess – 对现有策略的更新

EventBridge 更新了策略,使其包含iam:CreateServiceLinkedRole使用 API 目标所需的Amazon Secrets Manager权限。

添加了以下操作:

  • secretsmanager:CreateSecret

  • secretsmanager:UpdateSecret

  • secretsmanager:DeleteSecret

  • secretsmanager:GetSecretValue

  • secretsmanager:PutSecretValue

2021 年 3 月 4 日

EventBridge 已开启跟踪更改

EventBridge 已开启跟踪其Amazon托管策略的更改。

2021 年 3 月 4 日