View a markdown version of this page

Cross-account 内存访问 - Amazon Bedrock AgentCore

Cross-account 内存访问

Amazon Bedrock AgentCore Memory 支持跨账户访问,使您能够构建多账户架构,让内存资源和消耗代理跨越多个账户。 AWS Cross-account 访问涵盖两种情况:

  • 来自其他账户的数据平面操作 — 账户 B 中的委托人可以针对账户 A 中的内存资源调用内存数据平面 API(创建事件、写入记录、检索记录)。这是通过将基于资源的策略附加到内存资源来配置的。

    High-level 步骤:

    1. 通过附加基于资源的策略,将您的内存资源配置为允许跨账户访问。

    2. 在来自账户 B 的数据平面 API 调用中引用内存 ARN

  • 另一个账户中的传送目标 — 账户 A 中的内存资源可以将负载和流式传输事件传送到账户 B 中的 Amazon S3 存储桶、Amazon SNS 主题和 Amazon Kinesis Data Streams。这是在创建内存时通过目标资源的内存执行角色和资源策略进行配置的。

    High-level 步骤:

    1. 在账户 A 中创建具有目标资源访问权限的内存执行角色。

    2. 向账户 B 中的目标资源添加基于资源的策略以允许执行角色。

    3. 在账户 A 中创建内存,引用执行角色和跨账户资源 ARN。

先决条件

在配置跨账户内存访问权限之前,请确认您已经:

  • 在资源所有者账户(账户 A)中创建的内存资源

  • 内存资源的完整 ARN(例如)arn:aws:bedrock-agentcore:us-east-1:<account-id>:memory/<memory-id>

  • 对于数据平面访问:账户 B 中具有基于身份的权限的 IAM 角色或用户,允许执行所需操作 bedrock-agentcore

  • 对于传送目的地:在账户 B 中创建的目标 S3 存储桶、SNS 主题或 Kinesis 数据流

Cross-account 数据平面访问

您可以允许其他账户中的委托人直接针对您的内存资源调用内存数据平面 API。这是通过使用 API 将基于资源的策略附加到内存来配置的。PutResourcePolicy有关基于资源的政策的更多信息,请参阅 Amazon Bedro AgentCore ck Resource-based 政策

工作原理

  1. 账户 A 创建内存资源。

  2. 账户 A 使用 PutResourcePolicy API 将基于资源的策略附加到内存资源,向账户 B 中的委托人授予特定操作。

  3. 账户 B 中的委托人调用内存数据平面 API,将账户 A 中内存资源的完整 ARN 指定为。memory-id

  4. AWS 评估基于资源的内存策略和账户 B 委托人附加的基于身份的策略。如果两者都允许该操作(且没有任何策略明确拒绝该操作),则请求成功。

支持的操作

您可以为任何内存数据平面操作授予跨账户访问权限。下表列出了可用的操作:

处理建议 说明

bedrock-agentcore:CreateEvent

创建短期记忆事件

bedrock-agentcore:GetEvent

检索特定事件

bedrock-agentcore:DeleteEvent

删除特定事件

bedrock-agentcore:ListEvents

列出会话中的事件

bedrock-agentcore:ListActors

列出记忆中的演员

bedrock-agentcore:ListSessions

列出演员的会话

bedrock-agentcore:GetMemoryRecord

检索特定的记忆记录

bedrock-agentcore:ListMemoryRecords

列出命名空间中的内存记录

bedrock-agentcore:RetrieveMemoryRecords

语义搜索记忆记录

bedrock-agentcore:DeleteMemoryRecord

删除特定的记忆记录

bedrock-agentcore:BatchCreateMemoryRecords

创建多条记忆记录

bedrock-agentcore:BatchUpdateMemoryRecords

更新多条记忆记录

bedrock-agentcore:BatchDeleteMemoryRecords

删除多条记忆记录

bedrock-agentcore:ListMemoryExtractionJobs

列出内存的提取任务

bedrock-agentcore:StartMemoryExtractionJobs

重启失败的提取作业

将基于资源的策略附加到内存

向其他账号授予单一操作

以下示例授予账户 B (<account-B-id>) 调BatchCreateMemoryRecords用账户 A (<account-A-id>) 中内存资源的权限:

aws bedrock-agentcore-control put-resource-policy \ --region us-east-1 \ --resource-arn "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" \ --policy '{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCrossAccountBatchCreate", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-B-id>:root" }, "Action": "bedrock-agentcore:BatchCreateMemoryRecords", "Resource": "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" } ] }'

向另一个账号授予多项操作

以下示例授予账户 B 对内存记录和事件的完全读写权限:

aws bedrock-agentcore-control put-resource-policy \ --region us-east-1 \ --resource-arn "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" \ --policy '{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCrossAccountMemoryReadWrite", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-B-id>:root" }, "Action": [ "bedrock-agentcore:CreateEvent", "bedrock-agentcore:GetEvent", "bedrock-agentcore:ListEvents", "bedrock-agentcore:ListActors", "bedrock-agentcore:ListSessions", "bedrock-agentcore:BatchCreateMemoryRecords", "bedrock-agentcore:BatchUpdateMemoryRecords", "bedrock-agentcore:BatchDeleteMemoryRecords", "bedrock-agentcore:ListMemoryRecords", "bedrock-agentcore:RetrieveMemoryRecords", "bedrock-agentcore:GetMemoryRecord", "bedrock-agentcore:DeleteMemoryRecord" ], "Resource": "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" } ] }'

向特定 IAM 角色授予访问权限

要遵循最低权限原则,请向特定角色而不是整个账户授予访问权限:

aws bedrock-agentcore-control put-resource-policy \ --region us-east-1 \ --resource-arn "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" \ --policy '{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowSpecificRoleReadAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-B-id>:role/AgentMemoryReaderRole" }, "Action": [ "bedrock-agentcore:RetrieveMemoryRecords", "bedrock-agentcore:ListMemoryRecords", "bedrock-agentcore:GetMemoryRecord" ], "Resource": "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" } ] }'

移除基于资源的策略

要撤消跨账户数据平面访问权限,请删除基于资源的策略:

aws bedrock-agentcore-control delete-resource-policy \ --region us-east-1 \ --resource-arn "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>"

删除策略后,任何后续的跨账户请求都会返回。AccessDeniedException

从账户 B 调用数据平面 API

附加基于资源的策略后,账户 B 中的委托人可以通过将已满内存 ARN 指定为来调用数据平面 API。memory-id

从账户 B 创建内存记录:

aws bedrock-agentcore batch-create-memory-records \ --region us-east-1 \ --memory-id "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" \ --records '[ { "requestIdentifier": "rec-001", "content": {"text": "User prefers morning meeting times before 10 AM"}, "namespaces": ["preferences/user-123"], "timestamp": "1729525989" } ]'

从账户 B 中检索内存记录:

aws bedrock-agentcore retrieve-memory-records \ --region us-east-1 \ --memory-id "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" \ --namespace "preferences/user-123" \ --search-criteria '{"searchQuery": "meeting preferences"}' \ --max-results 10

从账户 B 创建活动:

aws bedrock-agentcore create-event \ --region us-east-1 \ --memory-id "arn:aws:bedrock-agentcore:us-east-1:<account-A-id>:memory/<memory-id>" \ --actor-id "agent-in-account-b" \ --session-id "cross-account-session-1" \ --event-timestamp "$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")" \ --payload '[ { "conversational": { "content": {"text": "Schedule my standup for 9 AM tomorrow"}, "role": "USER" } } ]'

Cross-account 送货目的地

当您使用自定义(自我管理)策略或直播传输配置创建内存时,Amazon Bedrock 会 AgentCore 使用内存执行角色将负载传送到您的目标资源。当这些资源位于不同的账户中时,您必须配置双方:账户 A 中的执行角色需要访问资源的权限,而账户 B 中的资源需要允许从账户 A 进行访问的策略。

工作原理

  1. 您可以使用基于资源的策略在账户 B 中创建目标资源(S3 存储桶、SNS 主题或 Kinesis 数据流),这些策略允许在账户 A 中使用内存执行角色。

  2. 您可以使用针对 Amazon Bedrock 的信任策略 AgentCore 和授予访问账户 B 中跨账户资源的权限策略在账户 A 中创建内存执行角色

  3. 您可以在账户 A 中创建内存,引用执行角色和跨账户资源 ARN。

  4. Amazon Bedrock AgentCore 担任执行角色,并使用它向账户 B 中的资源传送有效负载或流式传输事件。

设置内存执行角色

在账户 A 中创建内存执行角色。该角色需要一个允许 Amazon Bedrock AgentCore 担任该角色的信任策略,以及一个允许访问账户 B 中目标资源的权限策略。

信任策略:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "bedrock-agentcore.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "ArnLike": { "aws:SourceArn": "arn:aws:bedrock-agentcore:<region>:<account-A-id>:memory/*" } } } ] }

权限策略(仅包括与您正在使用的资源相关的声明):

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowS3Access", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject" ], "Resource": "arn:aws:s3:::<bucket-name-in-account-B>/*" }, { "Sid": "AllowSNSPublish", "Effect": "Allow", "Action": "sns:Publish", "Resource": "arn:aws:sns:<region>:<account-B-id>:<topic-name>" }, { "Sid": "AllowKinesisAccess", "Effect": "Allow", "Action": [ "kinesis:PutRecords", "kinesis:DescribeStream" ], "Resource": "arn:aws:kinesis:<region>:<account-B-id>:stream/<stream-name>" } ] }

在账户 B 中配置 S3 存储桶策略

将以下基于资源的策略添加到账户 B 中的 S3 存储桶,以允许账户 A 中的内存执行角色交付负载:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowMemoryExecutionRoleAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-A-id>:role/<memory-execution-role-name>" }, "Action": [ "s3:PutObject", "s3:GetObject" ], "Resource": "arn:aws:s3:::<bucket-name>/*" } ] }

在账户 B 中配置 SNS 主题策略

将以下基于资源的策略添加到账户 B 的 SNS 主题中,以允许账户 A 中的内存执行角色发布通知:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowMemoryExecutionRolePublish", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-A-id>:role/<memory-execution-role-name>" }, "Action": "sns:Publish", "Resource": "arn:aws:sns:<region>:<account-B-id>:<topic-name>" } ] }

在账户 B 中配置 Kinesis 数据流策略

将以下基于资源的策略添加到账户 B 中的 Kinesis 数据流,以允许账户 A 中的内存执行角色流式传输事件:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowMemoryExecutionRolePutRecords", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-A-id>:role/<memory-execution-role-name>" }, "Action": [ "kinesis:PutRecords", "kinesis:DescribeStream" ], "Resource": "arn:aws:kinesis:<region>:<account-B-id>:stream/<stream-name>" } ] }

使用跨账户 S3 和 SNS 创建内存

配置执行角色和资源策略后,在账户 A 中创建一个引用账户 B 中的跨账户资源的内存:

aws bedrock-agentcore-control create-memory \ --region us-east-1 \ --name "cross-account-memory" \ --description "Memory with cross-account S3 and SNS delivery" \ --event-expiry-duration 30 \ --memory-execution-role-arn "arn:aws:iam::<account-A-id>:role/MemoryCrossAccountRole" \ --memory-strategies '[ { "customMemoryStrategy": { "name": "cross_account_strategy", "configuration": { "selfManagedConfiguration": { "triggerConditions": [ {"messageBasedTrigger": {"messageCount": 5}} ], "invocationConfiguration": { "topicArn": "arn:aws:sns:us-east-1:<account-B-id>:memory-notifications", "payloadDeliveryBucketName": "<bucket-name>" }, "historicalContextWindowSize": 10 } } } } ]'

使用跨账户 Kinesis 直播创建内存

aws bedrock-agentcore-control create-memory \ --region us-east-1 \ --name "cross-account-streaming-memory" \ --description "Memory with cross-account Kinesis streaming" \ --event-expiry-duration 30 \ --memory-execution-role-arn "arn:aws:iam::<account-A-id>:role/MemoryCrossAccountRole" \ --stream-delivery-resources '{ "resources": [ { "kinesis": { "dataStreamArn": "arn:aws:kinesis:us-east-1:<account-B-id>:stream/memory-record-stream", "contentConfigurations": [ { "type": "MEMORY_RECORDS", "level": "FULL_CONTENT" } ] } } ] }'

最佳实践

  • 授予最低权限-仅授予跨账户委托人所需的特定操作。

  • 使用特定的委托人 — 授予对特定 IAM 角色而不是整个账户根目录的访问权限以限制爆炸半径。

  • 审计跨账户访问权限-用于监控 AWS CloudTrail 对内存资源的跨账户 API 调用。

  • 单独的读取和写入权限-为只读使用者和读写创建者创建单独的策略声明。

  • 在移除策略之前进行验证 — 在删除基于资源的策略之前,请确认其他账户中没有活动工作负载依赖于访问权限。