View a markdown version of this page

示例 2:使用 aws:RequestTag 支持为流添加标签 - Amazon DynamoDB
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

示例 2:使用 aws:RequestTag 支持为流添加标签

使用 aws:RequestTag/tag-key 条件键,可以将在请求中传递的标签键值对与在 IAM 策略中指定的标签对进行比较。例如,仅当请求包含特定的标签时,您才可以为流添加标签。

使用 Amazon CLI

  1. 创建内联策略并将其添加到角色中,如以下示例所示。

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "dynamodb:TagResource" ], "Resource": "arn:aws:dynamodb:*:*:table/*/stream/*", "Condition": { "StringEquals": { "aws:RequestTag/CostCenter": "12345" } } } ] }
  2. 使用所需的标签键值对为流添加标签。

    aws dynamodb tag-resource \ --resource-arn arn:aws:dynamodb:us-east-1:123456789012:table/myMusicTable/stream/2024-01-01T00:00:00.000 \ --tags Key=CostCenter,Value=12345

带和不带 Streams ABAC 时的行为

不带 Streams ABAC

如果您未为您的 Amazon Web Services 账户启用 Streams ABAC,则内联策略和请求中的标签条件不匹配。TagResource 操作会返回 AccessDeniedException。

带 Streams ABAC

如果您为您的 Amazon Web Services 账户启用了 Streams ABAC,则标签请求将成功完成。由于 "CostCenter": "12345" 请求中存在 TagResource 的标签键值对,因此内联策略支持该操作。