Amazon DynamoDB connections
DataMasque masks Amazon DynamoDB tables by exporting them to Amazon S3, masking the exported files, and importing the masked data into new tables.
- Masking process
- Required privileges
- Connection parameters
- Encrypted connections
- Limitations
- Supported data types
Masking process
Amazon DynamoDB databases are masked by exporting the table to an S3 bucket, splitting the exported files into batch files of manageable sizes, masking the data, and then importing into a new Amazon DynamoDB table with a new name. The existing table is retained. This method is used because table scans and bulk updates of Amazon DynamoDB are not performant.
The following diagram shows the high level data masking workflow for Amazon DynamoDB:

The data in the S3 bucket is removed at the end of a successful masking run.
Important! Since this staging bucket will have sensitive data stored in it temporarily, access to the bucket should be confined to trusted users/IAM roles only.
Due to the speed of Amazon DynamoDB Data Export and Amazon DynamoDB Data Import, masking in Amazon DynamoDB can take longer than standard SQL database masks. Most of this time is taken up by the Amazon DynamoDB import and export processes, which are internal to AWS and so DataMasque has no control over their performance. Masking a table with a single item can take up to ten minutes, while masking 1,000,000 items takes around 20 minutes, so the time does not scale linearly with the number of items.
Warning!: On failed or cancelled masking runs, the staging S3 bucket should be checked and left over export data may need to be manually cleaned up. This is because DataMasque might not be able to clean up exported data as it depends on when and how the masking run failed. For example, if an export is in process when a run is cancelled then AWS may continue to execute it and export data.
If a run fails during the import process, the target table may still have been created with no items. Check the AWS Management Console for Amazon DynamoDB and delete the table if it exists.
For more information please refer to the AWS Documentation for Amazon DynamoDB
Required privileges
Masking an Amazon DynamoDB table has five steps:
- The table to be masked is exported to an S3 bucket.
- DataMasque reads the exported data and masks it.
- The masked data is uploaded back to the same S3 bucket.
- An Amazon DynamoDB import is run to load the masked data into a new table.
- The masked and unmasked data is removed from the S3 bucket.
This process is much faster than masking data in place. Because of this approach, your DataMasque instance requires access to both the Amazon DynamoDB table being masked, and the staging S3 bucket to store the data in transit.
Access control
It is important to restrict access on the S3 bucket you configure to use on your Amazon DynamoDB connection.
- Block public access. Read the Blocking public access to your Amazon S3 storage guide for information on how to set up public blocks.
- Apply access control to your S3 bucket. The How can I secure the files in my Amazon S3 bucket? guide has information on steps to take to secure your S3 bucket.
Disable object lock
Object Lock must be disabled on your S3 bucket to allow DataMasque to clean up staging data when masking is completed. If Object Lock is not disabled, staging data will be left in your S3 bucket.
Optional configurations
The following configurations are not required, but recommended:
- Disable Bucket Versioning.
For AWS EC2 instances: Follow the steps below to configure the IAM Role which can be attached to the EC2 running DataMasque to allow for masking of Amazon DynamoDB database tables and accessing your S3 bucket:
To mask a DynamoDB table in a different AWS account from where DataMasque is, please refer to the Cross Account Functionality documentation.
- Open the Amazon IAM console, create an IAM policy. The following example IAM
policy grants the required privileges for Amazon DynamoDB and S3, where <bucket-name> and <table-name>
should be replaced with the S3 staging bucket and table being masked respectively.
Sidattributes have been added to explain the purpose of each statement. Further explanation of theResourceattributes are given after the example policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowEventLogging",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:CreateLogGroup",
"logs:PutLogEvents"
],
"Resource": "*"
},
{
"Sid": "ExportedDataAccess",
"Effect": "Allow",
"Action": [
"s3:GetBucketPublicAccessBlock",
"s3:GetBucketPolicyStatus",
"s3:GetBucketObjectLockConfiguration",
"s3:PutObject",
"s3:GetObject",
"s3:GetEncryptionConfiguration",
"s3:ListBucket",
"s3:GetBucketAcl",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::<bucket-name>",
"arn:aws:s3:::<bucket-name>/*"
]
},
{
"Sid": "SourceTableExport",
"Effect": "Allow",
"Action": [
"dynamodb:DescribeTable",
"dynamodb:DescribeContinuousBackups",
"dynamodb:ExportTableToPointInTime"
],
"Resource": [
"arn:aws:dynamodb:<region>:<account-id>:table/<table-name>"
]
},
{
"Sid": "ExportProcessStatus",
"Effect": "Allow",
"Action": [
"dynamodb:DescribeExport"
],
"Resource": [
"arn:aws:dynamodb:<region>:<account-id>:table/<table-name>/*"
]
},
{
"Sid": "TargetTableImportAndCleanup",
"Effect": "Allow",
"Action": [
"dynamodb:DeleteTable",
"dynamodb:DescribeTable",
"dynamodb:ImportTable",
"dynamodb:UpdateTable"
],
"Resource": [
"arn:aws:dynamodb:<region>:<account-id>:table/<table-name>*"
]
},
{
"Sid": "ImportProcessStatus",
"Effect": "Allow",
"Action": [
"dynamodb:DescribeImport"
],
"Resource": [
"arn:aws:dynamodb:<region>:<account-id>:table/<table-name>*/*"
]
}
]
}
Note: Since the policy above makes use of wildcards (
*) you may receive warnings when adding the policy through the AWS console. Since not all the wildcards can be removed (as explained below) these warning can be ignored.
Since the name of the S3 staging bucket is defined as part of the DataMasque connection, it is static, so it can be hard-coded as part of the policy. The Amazon DynamoDB table names are defined as part of ruleset, so more flexibility is needed when specifying the IAM policy.
The SourceTableExport statement controls access to the source table to get information about it. DataMasque requires
point-in-time-recovery (PITR)/continuous backups to be enabled for a table in order to be able to export it, therefore
it requires permission be able to check that the table has these enabled.
The Resource arguments for the SourceTableExport statement specify the source tables that DataMasque has access to.
Specific tables can be named, or * can be used to allow access to all tables in your account. Multiple Resource
entries can be added to grant access to multiple named tables. Here are some Resource examples:
"arn:aws:dynamodb:*:*:table/*": allow access to all tables in your account."arn:aws:dynamodb:*:*:table/users": allow access an exampleuserstable."arn:aws:dynamodb:us-east-1:123456789012:table/users": allow access an exampleuserstable, in theus-east-1region, for the account123456789012.
The ExportProcessStatus statement contains permissions to allow DataMasque to query the status of the source table's
export process. Under Resource, the source table name can be set, followed by /*. A trailing wildcard is required as
the ID of the export process is unknown until started. A * can be specified instead of a table name to allow access to
export statuses for all tables in your account. Multiple Resource entries can be added to grant access to multiple
named tables. Here are some Resource examples:
"arn:aws:dynamodb:*:*:table/*": allow access to all export processes in your account."arn:aws:dynamodb:*:*:table/users/*": allow access to export processes for just an exampleuserstable."arn:aws:dynamodb:us-east-1:123456789012:table/users/*": allow access to export processes for just an exampleuserstable, in a specific region and account.
The permissions under TargetTableImportAndCleanup allow importing masked data from S3 to the target table. The
Resource attributes make use of the wildcard as sometimes the name of the target table cannot be predicted. The name
of the target table is generated from the source table, with a suffix added. By default, the suffix is random, therefore
the example shows how to specify the source table name followed by a * (i.e. any suffix).
If specifying the suffix as part of the DataMasque connection settings (the Specify Suffix setting), then the suffix can be specified in the policy too.
Multiple Resource entries can be added to grant access to more named tables. Here are some Resource examples:
"arn:aws:dynamodb:*:*:table/*": allow access to import into any table."arn:aws:dynamodb:*:*:table/users*": allow access to import into an example tableuserswith any suffix."arn:aws:dynamodb:*:*:table/users-masked": allow access to import into an example tableusers-masked. Must be used in conjunction with the Specify Suffix setting. In this case, the suffix-maskedwas specified."arn:aws:dynamodb:us-east-1:123456789012:table/users-masked": allow access to import into an example tableusers-masked, in a specific region and account. Again, used with the Specify Suffix setting.
Note that the dynamodb:DeleteTable permission is only required if the Replace existing tables option is turned on
in the Amazon DynamoDB connection's Advanced Settings.
The ImportProcessStatus statement contains permissions to allow DataMasque to query the status of the target table's
import process. Under Resource, the source table name can be supplied, followed by a *, to allow any suffix. It is
then followed by /* to allow access to any import process status for that table. As with the export process, the
import process ID is not known until the process is started, so the use of wildcard is necessary.
As with the access to the table itself, if the suffix has been specified as part of the connection settings, it can be used in the policy.
Multiple Resource entries can be added to grant access to multiple named tables. Here are some Resource examples:
"arn:aws:dynamodb:*:*:table/*": allow access to all import processes in your account."arn:aws:dynamodb:*:*:table/users*/*": allow access to import processes for auserstable with any suffix."arn:aws:dynamodb:*:*:table/users-masked/*": allow access to import processes for an example tableusers-masked. Must be used in conjunction with the Specify Suffix setting. In this case, the suffix-maskedwas specified."arn:aws:dynamodb:us-east-1:123456789012:table/users-masked/*": allow access to import processes for an example tableusers-masked, in the specified region and account. Again, used with the Specify Suffix setting.
Create an IAM role:
- Select
AWS serviceas the trusted entity,EC2as the service. - Attach the policy created from the previous step to the role.
- Select
Open the Amazon EC2 and associate the IAM role to your EC2.
Important:* EC2 instance are unable to determine the AWS region in which they reside. The region is provided if setting up a
~/.aws/credentialsfile, but not in the case of attaching a policy. In this case, the Amazon DynamoDB table name in the YAML ruleset must be prefixed by the region and a forward slash. For example, the tableusersin regionus-east-1should be specified asus-east-1/users:
version: "1.0"
tasks:
- type: mask_table
table: '"us-east-1/users"'
Advanced SSE Key Permissions
All Amazon DynamoDB tables are server-side encrypted, however the way the encryption keys are managed is configurable. Please refer to Amazon DynamoDB Encryption key management for background on the types of key management available.
There are three scenarios when using DataMasque, where extra permissions are required on the IAM policy to access KMS keys:
- The option Stored in your account, and owned and managed by you is selected when configuring how the target Amazon DynamoDB table should be imported.
- The option Use configuration from the original table is selected when configuring how the target Amazon DynamoDB table should be imported, and the source table uses Stored in your account, and owned and managed by you for key management.
- The option Use configuration from the original table is selected when configuring how the target Amazon DynamoDB table should be imported, and the source table uses AWS managed key for key management.
In these cases, an extra IAM statement should be added to the policy to allow access to the particular keys(s) that the table(s) use:
{
"Sid": "KMSAccess",
"Effect": "Allow",
"Action": [
"kms:CreateGrant",
"kms:DescribeKey",
"kms:Decrypt"
],
"Resource": [
"<key-arn>"
]
}
Note: If directly choosing AWS managed key as the key management type for the new table, no extra permissions are required. The extra permissions are only needed if using the source table's configuration and the source table uses AWS managed key as DataMasque must perform extra checks to verify the actual key ARN of the source table.
<key-arn> should be replaced with the ARN of the key that is to be used. ARNs for keys can be found in the AWS KMS Console. ARNs for keys you have created are found by choosing Customer-managed keys from the sidebar, then clicking the alias or ID of the key you want to use. The ARN is displayed under General configuration. To find the AWS managed key for Amazon DynamoDB, choose AWS managed keys from the sidebar then click the aws/dynamodb alias. The ARN is displayed under General configuration.
Enabling Point-in-time Recovery Backup
Point-in-time Recovery Backup must be enabled in order for DataMasque to perform masking on Amazon DynamoDB. To enable this, follow the instructions in the official AWS Hands-on lab for Amazon DynamoDB.
Config carried over to masked tables
When masking an Amazon DynamoDB table, the new recreated table will have the following properties set to the exact values that the source table was configured with without reconstructing them.
KeySchemaAttributeDefinitions
The following properties will be set to mirror the source table.
BillingMode(Please check the notes below)ProvisionedThroughput(Please check the notes below)Global Secondary IndexesLocalSecondaryIndexes(Please check the notes below)SSESpecificationTableClass
The following properties WILL NOT be carried over from the source table.
- Any auto-scaling policies.
- IAM policies associated with the table.
- Amazon Cloudwatch metrics and alarms.
- Any tag associated with the table.
- Stream settings.
- Time to Live (TTL) settings.
- Point-In-Time-Recovery(PITR).
- Any properties associated with global tables such as Replication.
- Deletion Protection.
- Backups
Notes:
BillingModedefaults toPROVISIONEDfor masked tables asBillingModeis not returned when callingdescribe_tableonPROVISIONEDtables. WhenBillingModeis set toPAY_PER_REQUEST, this will be carried over to the masked table.ProvisionedThroughputwill be fixed for imported tables, auto-scaling will not be enabled.LocalSecondaryIndexeswill be carried over from the source table and recreated on the masked table asGlobalSecondaryIndexes. This is due the fact thatLocalSecondaryIndexescan only be added when creating the table and cannot be created when importing the table from S3. TheseGlobalSecondaryIndexeswill be created with the minimum read/write capacity (1/1) as this will affect the cost of Amazon DynamoDB.
Please refer to the AWS Documentation relating to read/write capacity.
Connection parameters
Amazon DynamoDB specific parameters
For Amazon DynamoDB databases, the following additional fields apply:
| S3 bucket name | Name of the S3 bucket to temporarily store Amazon DynamoDB exports and imports. |
| Encryption key management | The method of key management used for server-side encryption of the created masked table. |
| KMS key ID (optional) | The ID of the key to use for SSE, if using an account-managed key. |
If Cross account access is enabled the following parameter is also required:
| IAM Role ARN | The IAM Role ARN with access to the bucket. |
For more information please refer to the cross-account documentation.
Amazon DynamoDB data is exported into a directory called, AWSDynamoDB in the root of the S3 bucket specified. This directory
will be created as part of the export process.
For details on the Encryption key management and KMS key ID fields, see the section Amazon DynamoDB Encrypted Connections.
Specifying Amazon DynamoDB tables
The Amazon DynamoDB tables to mask are not specified as part of the connection settings, instead they are specified in the ruleset YAML. Refer to the table masks documentation for information on specifying table names.
Amazon DynamoDB Advanced Settings
Masking of Amazon DynamoDB creates a new table with a name based on the source table. The following fields control how the table is named, and removal of existing tables:
| Masked Table Name: Suffix | Masked tables are created as the source table with a random suffix. Enter a suffix to use instead of a random one. |
| Masked Table Name: Append datetime in ISO format | Append the date and time of the masking run to the new table name (as well as a suffix, if specified). |
| Replace existing tables | If checked, DataMasque will replace tables with the same name; otherwise, the masking run will fail if tables already exist with the generated name. |
Example Generated Table Names
In this example, masking will be applied to an Amazon DynamoDB table named users. This table shows example new table names
based on different combinations of the advanced settings.
| Suffix | Append datetime in ISO format | Result | New table name |
|---|---|---|---|
| unspecified | Not checked | Random suffix added | users-603d015a1 |
-masked |
Not checked | Specified suffix added | users-masked |
| unspecified | Checked | Datetime added | users-202303071922 |
-masked |
Checked | Suffix and datetime added | users-masked-202303071922 |
Note that the suffix is added verbatim: the leading dash is part of the suffix as a separator. This may be omitted if no separator is desired. A dash is always added before the ISO date.
Replace existing tables setting
Sometimes the name of the Amazon DynamoDB masked table may already exist. It is not very likely to happen when using a random suffix or appending the current date and time, but when specifying a suffix and masking a table more than once, the new table will already exist (unless it was removed between masking runs).
If Replace existing tables is Checked then an existing table with the same name will be deleted. A new table will be created with masked data.
If Replace existing tables is Not checked, and an existing table with the generated name already exists, then DataMasque will stop the masking run and log an error.
This table summarises the behaviour:
| Replace Existing Tables | Table With Generated Name Exists | Outcome |
|---|---|---|
| Not Checked | No | Table created |
| Not Checked | Yes | Masking run fails |
| Checked | No | Table created |
| Checked | Yes | Existing table deleted and new table created |
Note that since a suffix is always added during masking, the source table will never be deleted as the generated table name will always differ from the source table name.
Encrypted connections
All communication to Amazon DynamoDB is encrypted. Various options are available for server-side encryption (SSE) of data at rest.
Encryption settings can be specified at the connection level, which will apply to all tables when a ruleset is executed against that connection. However, the settings can be overridden on a per-table basis, with configuration specified in Run Options before starting a run. This will be looked at in more detail in the next section. First, we will explain what the options mean.
Encryption key management
Amazon DynamoDB has different options for how encryption keys are handled, and you can choose which you would like to use for SSE.
Owned by Amazon DynamoDB
- AWS owned key, specifically owned and managed by Amazon DynamoDB. You are not charged an additional fee for using this key. This is the default setting in the AWS console and for DataMasque.
AWS managed key
- The key is stored in your account and is managed by AWS Key Management Service (AWS KMS). AWS KMS charges apply.
Stored in your account, and owned and managed by you
- The key is stored in your AWS account and is managed by AWS Key Management Service (AWS KMS). AWS KMS charges apply. If choosing this option, a KMS key ID must be specified, and your IAM privileges must grant access to the specified key.
Use configuration from the original table
- Selecting this will use the same key as the source table. AWS do not recommend this. If the original table
specifies AWS managed key or Stored in your account, and owned and managed by you, then AWS KMS charges apply.
Additionally, your IAM profile must grant access to describe the
alias/aws/dynamodbKMS key alias (in order for DataMasque to check whether a given key is managed by AWS or your account). If the original table specifies Stored in your account, and owned and managed by you then your IAM profile must grant access to the KMS key of the original table.
- Selecting this will use the same key as the source table. AWS do not recommend this. If the original table
specifies AWS managed key or Stored in your account, and owned and managed by you, then AWS KMS charges apply.
Additionally, your IAM profile must grant access to describe the
Please also read the Amazon DynamoDB encryption at rest documentation for more explanation on key types in AWS/DynamoDB.
KMS key ID
When selecting the encryption key management option Stored in your account, and owned and managed by you, the ID of
the key must be specified. Typically, this is in an ARN format, for example
arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab.
Your IAM privileges must grant access to the key. See Advanced SSE Key Permissions for more information.
Specifying SSE Options
SSE options can be configured in the Connection form and these will act as the defaults for all tables in the connection. These settings can be overridden per table, for a run, by specifying per-table settings in the Run Options panel on the Database Masking Dashboard.
Refer to the run options documentation for more information on setting options for a specific masking run.
After selecting an Amazon DynamoDB connection in the Connections list, the Override connection's Server Side Encryption settings checkbox will be available to select. To configure the settings per table, click the gear icon next to this setting, which will show the Encryption key management form.

The Table name should match the table name as specified in your ruleset. If the table name in the ruleset includes an AWS region, then it should also be included here. The options for Encryption key management and KMS key ID match those in the two prior sections.
Limitations
When using Amazon DynamoDB, the Data Discovery and Schema Discovery features of DataMasque are unsupported.
Joining tables using join syntax is unsupported.
The following tasks are unavailable:
run_sqlmask_unique_keytruncate_tablebuild_temp_tablerun_data_discoveryrun_schema_discoveryparallel
The alternative methods below can be considered in absence of the unavailable features:
The from_unique mask should be used instead of
mask_unique_key.
The where option in mask_table in unsupported.
Conditional masking with if should be used instead.
Supported data types
The following Amazon DynamoDB data types are supported.
| Data type | Description |
|---|---|
| string | Unicode string with UTF-8 binary encoding. Can be a length of zero, or up to 400KB of data. |
| number | Numerical value with 38 digits of precision. |
| boolean | Can be true or false. |
| null | Represents an attribute with an unknown or undefined state. |
| list | Stores and ordered collection of values. Should be masked with a json mask. |
| map | Stores and unordered collection of name-value pairs. Should be masked with a json mask. |
| binary (partial support) | Store any binary data up to 400KB. While DataMasque does not have mask types for manipulating binary data, values from binary columns can be copied to other columns or replaced with non-binary values (e.g. null). |