创建前先将AWS Cloud形成删除资源

时间:2019-10-04 10:48:23

标签: amazon-web-services amazon-cloudformation

我试图编写用于创建dynamodb的云形成脚本。当我执行脚本时,它的获取错误已经存在于堆栈中

这是我的模板。

AWSTemplateFormatVersion: "2010-09-09"
Resources: 
  terminationLettersDynamodb:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Delete
      Properties:
        AttributeDefinitions:
          - AttributeName: schemeId
            AttributeType: S

        KeySchema:
          - AttributeName: schemeId
            KeyType: HASH

        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: "terminationLetters"

在创建之前是否可以删除资源?

1 个答案:

答案 0 :(得分:1)

您应避免使用硬编码表名。如果指定名称,则无法执行需要替换此资源的更新。

在忽略TableName时,您可以使用Ref内在函数在堆栈中的其他位置引用动态创建的表名,例如:Ref“ terminationLettersDynamodb”