在 EventBridge 中连接私有 API - Amazon EventBridge
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

在 EventBridge 中连接私有 API

您可以创建与私有 HTTPS 端点的连接,以提供对 VPC 或本地资源的安全点对点网络访问,而无需经由公共互联网。例如,您可以创建一个连接,用于访问 Amazon Elastic Load Balancer 后端基于 HTTPS 的应用程序。

EventBridge 利用在 VPC Lattice 中创建的资源配置来创建与私有 HTTPS 端点的连接。资源配置是一个逻辑对象,用于标识资源,并指定可访问该资源的对象及访问方式。要在 EventBridge 中创建与私有 API 的连接,需要为该私有 API 指定资源配置。有关更多信息,请参阅《Amazon VPC Lattice 用户指南》中的 VPC Lattice 中的资源配置

然后,EventBridge 会创建一个资源关联,使 EventBridge 能够访问私有 API。有关更多信息,请参阅《Amazon VPC Lattice 用户指南》中的管理资源关联

虽然 EventBridge 负责管理资源关联,但该关联是使用您的凭证创建的,因此您仍能查看资源关联操作的相关信息。

EventBridge 和 Step Functions 使用连接作为 HTTPS 端点的授权配置。

您可以创建访问其他 Amazon 账户中私有 API 的连接。有关更多信息,请参阅 跨账户私有 API

连接私有 API 的权限

以下策略示例包括创建私有 API 连接所需的最低权限。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Action": [ "vpc-lattice:CreateServiceNetworkResourceAssociation", "vpc-lattice:GetResourceConfiguration", "vpc-lattice:AssociateViaAWSService-EventsAndStates", "events:CreateConnection" ], "Resource": [ "*" ], "Effect": "Allow" } ] }

以下策略示例包括更新私有 API 连接所需的最低权限。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Action": [ "vpc-lattice:CreateServiceNetworkResourceAssociation", "vpc-lattice:GetResourceConfiguration", "vpc-lattice:AssociateViaAWSService-EventsAndStates", "events:UpdateConnection" ], "Resource": [ "*" ], "Effect": "Allow" } ] }

监控私有 API 连接的创建

当您创建与私有 API 的连接时,会生成以下日志:

在创建连接的账户中,Amazon CloudTrail 会记录一个 CreateServiceNetworkResourceAssociation 事件。

在此日志中,sourceIPAddressuserAgentserviceNetworkIdentifier 设置为 EventBridge 服务主体 events.amazonaws.com

{ "eventTime": "2024-11-21T00:00:00Z", "eventSource": "vpc-lattice.amazonaws.com", "eventName": "CreateServiceNetworkResourceAssociation", "awsRegion": "region", "sourceIPAddress": "events.amazonaws.com", "userAgent": "events.amazonaws.com", "requestParameters": { "x-amzn-vpc-lattice-association-source-arn": "***", "x-amzn-vpc-lattice-service-network-identifier": "***", "clientToken": "token", "serviceNetworkIdentifier": "events.amazonaws.com", "resourceConfigurationIdentifier": "arn:partition:vpc-lattice:region:account-id:resourceconfiguration/resource-configuration-id", "tags": { "ManagedByServiceAWSEventBridge": "account-id:connection-name" } }

在包含私有 API 的账户中,Amazon CloudTrail 会记录一个 CreateServiceNetworkResourceAssociationBySharee 事件。

此日志包含:

  • callerAccountId:创建连接的 Amazon 账户。

  • accountId:包含私有 API 的 Amazon 账户。

  • resource-configuration-arn:私有 API 的 VPC Lattice 资源配置。

{ "eventTime": "2024-11-21T06:31:42Z", "eventSource": "vpc-lattice.amazonaws.com", "eventName": "CreateServiceNetworkResourceAssociationBySharee", "awsRegion": "region", "sourceIPAddress": "vpc-lattice.amazonaws.com", "userAgent": "user-agent", "additionalEventData": { "callerAccountId": "consumer-account-id" }, "resources": [ { "accountId": "provider-account-id", "type": "AWS::VpcLattice::ServiceNetworkResourceAssociation", "ARN": "resource-configuration-arn" } ] }

如果跨账户连接到私有 API,则包含该连接的账户将不会收到关于调用私有 API 的 Amazon CloudTrail 或 VPC Lattice 日志。

管理连接的服务网络资源关联

当您为要连接的私有 API 指定 VPC Lattice 资源配置时,EventBridge 会通过在 VPC Lattice 资源配置和 EventBridge 服务拥有的 VPC Lattice 服务网络之间创建资源关联来启用连接。虽然 EventBridge 负责管理资源关联,但该关联是使用您的凭证创建的,因此您仍能查看资源关联的相关信息。这意味着您可以列出和描述资源关联。

使用 describe-connection 返回连接描述,其中包括资源配置和资源关联的 Amazon 资源名称(ARN)。

您无法删除由 EventBridge 创建的资源关联。如果您删除连接,EventBridge 会删除所有相应的资源关联。

有关更多信息,请参阅《Amazon VPC Lattice 用户指南》中的管理资源关联

连接到本地私有 API

通过使用 Amazon PrivateLink 和 VPC Lattice 访问 VPC 资源,您可以连接到本地私有 API。为此,您必须在 VPC 和本地环境之间配置网络路由。例如,您可以使用 Amazon Direct ConnectAmazon Site-to-Site VPN 来建立此类路由。