如何将dynamodb恢复到初始状态?

时间:2018-01-17 15:26:04

标签: amazon-web-services amazon-dynamodb backup amazon-cloudformation restore

我是AWS的新手,我目前正在使用cloudformation,lambdas,dynamodb等。

我需要恢复我成功完成的发电机表,但根据AWS文档,应手动设置以下内容:

  • 自动缩放政策
  • IAM政策
  • Cloudwatch指标和警报
  • 标签
  • 流设置
  • 生存时间(TTL)设置

我找不到任何关于如何实现这一目标的文档,所以我正在尝试自己的想法,即将需要手动设置的资源放在单独的堆栈或嵌套堆栈中,然后删除嵌套堆栈资源并再次部署模板。

我能够进行自动扩展,因为它是一个完全不同的资源,可以在一个单独的堆栈中完成。

我的问题是:是否可以在单独的模板中拆分资源? 例如主云计算堆栈中的主要dynamodb表定义,其他定义如嵌套堆栈中的标记和流?

cloudformation-template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: this is a test app

Parameters:
  EnvironmentName:
    Type: String
    Default: test
Resources:
  # dynamodb table
  UserTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: User
      AttributeDefinitions:
        - AttributeName: id
          AttributeType: S
      KeySchema:
        - AttributeName: id
          KeyType: HASH
      ProvisionedThroughput:
        ReadCapacityUnits: 1
        WriteCapacityUnits: 1
      Tags:
        - Key: Environment
          Value: !Sub ${EnvironmentName}
        - Key: table
          Value: user
  AutoscalingStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      Parameters:
        EnvironmentName: !Ref EnvironmentName
        UserTable: !Ref UserTable
      TemplateURL: autoscaling-template.yaml
      TimeoutInMinutes: 5

自动缩放-template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Description: test autoscaling

Parameters:
  EnvironmentName:
    Type: String
    Default: playground
  UserTable:
    Type: String
Resources:
  UpdateUserTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Ref UserTable
      Tags:
        - Key: Environment
          Value: !Sub ${EnvironmentName}
        - Key: table
          Value: user
  UserTableWriteCapacityScalable:
    Type: "AWS::ApplicationAutoScaling::ScalableTarget"
    Properties:
      MaxCapacity: 1000
      MinCapacity: 5
      ResourceId: !Join
        - /
        - - table
          - !Ref UserTable
      RoleARN: !ImportValue "autoscaling--ScalingRole"
      ScalableDimension: dynamodb:table:WriteCapacityUnits
      ServiceNamespace: dynamodb
  UserTableReadCapacityScalable:
    Type: "AWS::ApplicationAutoScaling::ScalableTarget"
    Properties:
      MaxCapacity: 1000
      MinCapacity: 5
      ResourceId: !Join
        - /
        - - table
          - !Ref UserTable
      RoleARN: !ImportValue "autoscaling--ScalingRole"
      ScalableDimension: dynamodb:table:ReadCapacityUnits
      ServiceNamespace: dynamodb
  UserTableWriteScalingPolicy:
    Type: "AWS::ApplicationAutoScaling::ScalingPolicy"
    Properties:
      PolicyName: WriteAutoScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref UserTableWriteCapacityScalable
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 50.0
        ScaleInCooldown: 30
        ScaleOutCooldown: 30
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBWriteCapacityUtilization
  UserTableReadScalingPolicy:
    Type: "AWS::ApplicationAutoScaling::ScalingPolicy"
    Properties:
      PolicyName: ReadAutoScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref UserTableReadCapacityScalable
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 50.0
        ScaleInCooldown: 20
        ScaleOutCooldown: 20
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBReadCapacityUtilization

UpdateUserTable无效,因为它无效。但是当我在恢复后删除并添加嵌套堆栈时,其余的工作正常。

0 个答案:

没有答案