本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
範例 4:使用 CloudFormation 標記串流
您可以直接在 CloudFormation 範本中指定 DynamoDB Streams 上的標籤。串流標籤是在標準資料表的 StreamSpecification 屬性內定義,而在全域資料表的 ReplicaStreamSpecification 屬性內定義。
AWS::DynamoDB::Table
Resources: MyTable: Type: AWS::DynamoDB::Table Properties: TableName: MyTable AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - AttributeName: id KeyType: HASH BillingMode: PAY_PER_REQUEST Tags: - Key: TableEnv Value: Production StreamSpecification: StreamViewType: NEW_AND_OLD_IMAGES Tags: - Key: StreamEnv Value: Production - Key: StreamTeam Value: Payments
AWS::DynamoDB::GlobalTable
Resources: MyGlobalTable: Type: AWS::DynamoDB::GlobalTable Properties: TableName: MyGlobalTable AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - AttributeName: id KeyType: HASH BillingMode: PAY_PER_REQUEST StreamSpecification: StreamViewType: NEW_AND_OLD_IMAGES Replicas: - Region: us-east-1 Tags: - Key: TableEnv Value: Production ReplicaStreamSpecification: Tags: - Key: StreamEnv Value: Production - Key: StreamTeam Value: Payments - Region: eu-west-1 Tags: - Key: TableEnv Value: Production ReplicaStreamSpecification: Tags: - Key: StreamEnv Value: Production - Key: StreamTeam Value: Payments
除了明確的串流標籤之外,CloudFormation 也會將堆疊層級標籤傳播至串流。如果您的堆疊已設定標籤,這些標籤會自動套用至堆疊中的所有資源,包括串流。
重要
用於 CloudFormation 部署的 IAM 角色必須具有串流資源 (arn:aws:dynamodb:*:*:table/*/stream/*) 的 dynamodb:TagResource和 dynamodb:UntagResource許可,才能將標籤套用至串流。如果缺少這些許可,請參閱 標記串流時 CloudFormation 部署失敗 以取得詳細資訊。