CloudFormation模板为DynamoDB GlobalTable添加标签报错如何解决
DynamoDB GlobalTable CloudFormation标签配置解决方案
错误原因
你遇到的属性校验报错是因为AWS::DynamoDB::GlobalTable资源的顶层Properties配置中不支持直接定义Tags属性,标签必须配置在每个副本(Replicas)的属性项中。
修正后的单副本模板示例
AWSTemplateFormatVersion: 2010-09-09 Description: AWS CloudFormation Template to create global tables Resources: globalTableExample: Type: 'AWS::DynamoDB::GlobalTable' Properties: TableName: sample1 AttributeDefinitions: - AttributeName: PK AttributeType: S KeySchema: - AttributeName: PK KeyType: HASH BillingMode: PAY_PER_REQUEST StreamSpecification: StreamViewType: NEW_AND_OLD_IMAGES SSESpecification: SSEEnabled: true SSEType: "KMS" Replicas: - Region: us-east-1 # 标签配置移动到对应副本配置项下 Tags: - Key: Name Value: mytable - Key: Region Value: east
多副本公共标签复用方案
如果需要给所有副本配置相同的标签,避免重复编写代码,可以使用YAML锚点复用标签配置,示例如下:
AWSTemplateFormatVersion: 2010-09-09 Description: AWS CloudFormation Template to create global tables # 定义公共标签锚点,可全局复用 x-common-tags: &common-tags - Key: Name Value: mytable - Key: Project Value: business-demo Resources: globalTableExample: Type: 'AWS::DynamoDB::GlobalTable' Properties: TableName: sample1 AttributeDefinitions: - AttributeName: PK AttributeType: S KeySchema: - AttributeName: PK KeyType: HASH BillingMode: PAY_PER_REQUEST StreamSpecification: StreamViewType: NEW_AND_OLD_IMAGES SSESpecification: SSEEnabled: true SSEType: "KMS" Replicas: - Region: us-east-1 Tags: *common-tags - Region: us-west-2 Tags: *common-tags
内容的提问来源于stack exchange,提问作者Chintamani
相关产品推荐
相关产品推荐

