How to do it...

Follow these steps in order to create a DynamoDB table, and then observe the drift after you have used the console to make a manual configuration change to the table:

  1. Paste the following code into a file on your filesystem. Give it a .yaml extension:
AWSTemplateFormatVersion: "2010-09-09"
Resources:
SimpleDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: "Id"
AttributeType: "S"
KeySchema:
-
AttributeName: "Id"
KeyType: "HASH"
BillingMode: PAY_PER_REQUEST
Outputs:
TableName:
Description: Drift Detection Example Table
Value: !Ref SimpleDynamoDBTable
  1. Go to the CloudFormation console, and click Create stack.
  2. Select Upload a template to Amazon S3, and choose the file that you just created. Click Next, and give the stack a name. 
  3. Click Next, and then Next on the following screen.
  4. Click Create.
  5. Once the stack has completed, go to the Outputs tab, and note the name of the table.
  6. Go to the DynamoDb dashboard, and view the tables.
  7. Select the table that you just created:

A DynamoDB table
  1. Now, you are going to introduce drift to your stack, by making a change to the table configuration. Select the Indexes tab.
  2. Create a new index on an attribute called Name:

Create a DynamoDB index via the console
  1. Once the status on the new Global Secondary Index (GSI) is active, go back to the CloudFormation dashboard, and select the stack.
  2. Select Detect drift from the Actions drop-down menu:

Detect drift
  1. You should be able to refresh the page, and see that the stack's Drift status has changed to DRIFTED
  2. Select View drifts results from the Actions menu in order to see a report that describes the detected drift:

A drifted stack
  1. To demonstrate why the drift is a problem, try to change the billing mode, by updating the stack with the following code, which attempts to add the same index to the table:
AWSTemplateFormatVersion: "2010-09-09"
Resources:
SimpleDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: "Id"
AttributeType: "S"
- AttributeName: "Name"
AttributeType: "S"
KeySchema:
-
AttributeName: "Id"
KeyType: "HASH"
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
-
IndexName: "Name-index"
KeySchema:
-
AttributeName: "Name"
KeyType: "HASH"
Projection:
ProjectionType: "ALL"
Outputs:
TableName:
Description: Drift Detection Example Table
Value: !Ref SimpleDynamoDBTable
  1. Choose Actions Update Stack.
  2. Select Replace the current template, and upload the new file.
  3. Click Next until you reach the final confirmation screen, and then click Update Stack.
  4. After a few moments, the stack will fail:

A failed stack update
  1. Drift detection will not fix the problem for you. It only points out that there is a problem, and it's up to you to fix it.
  2. Go back to the DynamoDB console, and delete the index.
  1. Go back to the CloudFormation dashboard, and repeat steps 16-18.
  2. This time, the stack update will succeed, since the table properties match what CloudFormation expects, based on the prior version of the template.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset