【发布时间】:2019-06-25 00:13:02
【问题描述】:
我正在尝试创建一个阻止 CloudFormation 删除表的 AWS 角色。例如,我按如下方式创建了我的表:
UsersDynamoDBTable:
Type: AWS::DynamoDB::Table
Description: Users DynamoDB Table
Properties:
AttributeDefinitions:
- AttributeName: hashKey
AttributeType: S
- AttributeName: rangeKey
AttributeType: S
KeySchema:
- AttributeName: hashKey
KeyType: HASH
- AttributeName: rangeKey
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
- IndexName: index-rangeKey
KeySchema:
- AttributeName: rangeKey
KeyType: HASH
- AttributeName: hashKey
KeyType: RANGE
Projection:
ProjectionType: ALL
现在假设一个开发者不小心删除了这一行并更新了堆栈。这样,将删除包含所有数据的表。所以我想创建一个防止 CloudFormation 删除 DynamoDB 表的角色。我的第一次尝试是在下面创建角色,但没有成功。
PreventCloudFormationDeleteTableIAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- cloudformation.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: PreventTableDeletePolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Deny
Action:
- dynamodb:DeleteTable
Resource:
- !Join
- '/'
- - !Join [':', ['arn:aws:dynamodb', !Sub '${AWS::Region}', '*', 'table']]
- !Join ['', [!Sub '${StackName}', '*']]
我是否缺少一些角色配置?
谢谢。
【问题讨论】:
-
你是如何使用这个角色的?你是在创建栈的时候传入的吗?
-
是的。我在创建表格的同一模板上传递了它
-
当您创建堆栈时,您可以为 cloudformation 在创建/更新/删除资源时指定一个角色 arn。该角色当然不能由堆栈创建。
标签: amazon-web-services amazon-cloudformation amazon-iam