DynamoDB
CloudFormation
Encryption at Rest
AWS Security
Cloud Infrastructure

How do I enable Encryption at Rest on DynamoDB with CloudFormation

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Enabling Encryption at Rest on DynamoDB with CloudFormation

Amazon DynamoDB is a fully managed NoSQL database service designed for fast and predictable performance with seamless scalability. As organizations manage sensitive data, it’s crucial to protect this data from unauthorized access or mismanagement. One key feature offered by DynamoDB for data protection is Encryption at Rest. This feature can be effortlessly managed through AWS CloudFormation. This article will guide you through the process of enabling Encryption at Rest using CloudFormation, along with key considerations and technical details.

What is Encryption at Rest?

Encryption at Rest in DynamoDB ensures that all your data is securely stored on disk by automatically encrypting it. Encryption is performed using AWS Key Management Service (KMS) customer master keys (CMKs). DynamoDB's encryption is seamless and non-disruptive, helping meet compliance requirements without affecting application performance.

CloudFormation Overview

AWS CloudFormation is a service that enables developers and system administrators to create, manage, and provision a collection of related AWS resources in an orderly and predictable fashion. By defining resources in CloudFormation templates, you can version control and consistently roll out infrastructure configurations.

Steps to Enable Encryption at Rest

To enable Encryption at Rest in DynamoDB using CloudFormation, follow these steps:

1. Define a CloudFormation Template

Below is a simplified CloudFormation template that illustrates how to enable Encryption at Rest for a DynamoDB table:

yaml
1AWSTemplateFormatVersion: "2010-09-09"
2Resources:
3  MyDynamoDBTable:
4    Type: AWS::DynamoDB::Table
5    Properties:
6      TableName: SampleTable
7      AttributeDefinitions:
8        - AttributeName: Id
9          AttributeType: S
10      KeySchema:
11        - AttributeName: Id
12          KeyType: HASH
13      BillingMode: PAY_PER_REQUEST
14      SSESpecification:
15        SSEEnabled: true
16        KMSMasterKeyId: <KMSKeyId>

2. Key Components Explained

  • AWS::DynamoDB::Table: This is the AWS CloudFormation resource type for a DynamoDB Table.
  • SSESpecification: This section specifies information enabling server-side encryption.
    • SSEEnabled: Set to true to enable encryption.
    • KMSMasterKeyId: (Optional) Specify the key from AWS KMS. If not specified, AWS will use the default CMK.

Handling Default vs. Custom CMKs

  • Default AWS-Managed CMK: The default option that provides ease of use.
  • Customer-Managed CMK: Provides control over key rotation and management. Ensure the CMK has the necessary permissions through IAM policies.

AWS KMS Permissions

When you use a Customer-Managed CMK, your principals such as application roles or users interacting with DynamoDB tables need specific permissions to use the KMS key:

json
1{
2  "Version": "2012-10-17",
3  "Statement": [
4    {
5      "Effect": "Allow",
6      "Principal": {
7        "Service": "dynamodb.amazonaws.com"
8      },
9      "Action": [
10        "kms:GenerateDataKey",
11        "kms:Decrypt"
12      ],
13      "Resource": "arn:aws:kms:<Region>:<AccountId>:key/<KeyId>"
14    }
15  ]
16}

Creating and Deploying the CloudFormation Template

  1. Write the YAML Template: As described above.
  2. Validate the Template: Use AWS CloudFormation Linter or JSON/YAML validators to ensure syntactical correctness.
  3. Deploy the Template: Use AWS Management Console, AWS CLI, or AWS SDKs. Deploy using commands like:
bash
    aws cloudformation create-stack --stack-name MyDynamoDBStack --template-body file://path/to/template.yaml
  1. Monitor the Deployment: Check stack events in the AWS Management Console or using aws cloudformation describe-stack-events.

Considerations when Using Encryption at Rest

  • Compliance: Ensure that the keys and encryption satisfy your regulatory compliance needs.
  • Performance: Generally, encryption introduces negligible latency; however, plan accordingly for critical workloads.
  • Costs: Consider KMS related costs as they may apply based on key usage and requests.

Conclusion

Enabling Encryption at Rest for Amazon DynamoDB using CloudFormation provides an automated, scalable, and compliant method to enhance the security of your data. By using AWS KMS, you have further flexibility in managing encryption keys, thus fulfilling various security and compliance requirements.

Summary Table

AspectDescription
Encryption TypeAt Rest
AWS ServiceAmazon DynamoDB
Management ToolAWS CloudFormation
SSE SpecificationSSEEnabled: true to enable encryption. Optionally specify KMSMasterKeyId for customer-managed keys.
KMS Key OptionsDefault AWS-managed CMK or Customer-managed CMK. Default is simpler; Customer-managed offers more control.
PermissionsRequires IAM policies granting kms:GenerateDataKey and kms:Decrypt actions for access with customer-managed keys.
Deployment ToolsAWS Management Console, AWS CLI, AWS SDKs
Cost ConsiderationsAdditional KMS usage-related costs might apply depending on key operations.

By carefully planning and executing your CloudFormation templates, you ensure that your DynamoDB data remains secure, compliant, and accessible with minimal disruption to your application workflows.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.