Amazon web services 防止AWS CloudFormation使用IAM删除DynamoDB
我正在尝试创建一个AWS角色,该角色可以防止删除表。例如,我创建的表如下所示:Amazon web services 防止AWS CloudFormation使用IAM删除DynamoDB,amazon-web-services,amazon-cloudformation,amazon-iam,Amazon Web Services,Amazon Cloudformation,Amazon Iam,我正在尝试创建一个AWS角色,该角色可以防止删除表。例如,我创建的表如下所示: UsersDynamoDBTable: Type: AWS::DynamoDB::Table Description: Users DynamoDB Table Properties: AttributeDefinitions: - AttributeName: hashKey AttributeType: S - Attribu
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}', '*']]
我是否缺少一些角色配置
谢谢。当从模板中删除堆栈或表格时,可以使用RETAIN的DeletionPolicy防止删除表格。此外,新的UpdateReplacement策略将防止CloudFormation在由于主键更改而需要删除表时删除该表。考虑到角色已正确附加到调用用户/主体,该联接的策略Arn是否可能与表Arn不匹配 <>也考虑保留资源而不是拒绝操作:
您是如何使用此角色的?创建堆栈时是否传入了它?是的。我在创建表的同一模板上传递了它。创建堆栈时,可以指定角色arn,以便cloudformation在创建/更新/删除资源时使用。当然,该角色不能由堆栈创建。