Data Security and Governance · Topic 5 of 7

Data Masking and Anonymization

Protect sensitive fields with masking, hashing, tokenization and anonymization using Redshift masking, Glue and DataBrew PII tools and Lake Formation.

  • 5 min
In a nutshell
  • Masking hides values. Hashing is one way. Encryption is reversible with a key. Tokenization uses a vault.
  • Redshift dynamic data masking changes query results per user or role without changing stored data.
  • Lake Formation data filters remove columns and rows for chosen principals.

What it is

Encryption protects data from people who should not see it at all. Masking and anonymization protect fields that some people may use but should not read in full, such as a card number or a national ID.

The goal is to let analysts, developers and partners work with useful data while the sensitive values stay hidden or unlinkable to a person.

Raw datanames, IDs, cardsdetectClassifierMacie or Glue PIIprotectMask or hashpolicy or jobdeliverAnalystssafe view

How it works

Core terms

TechniqueWhat it doesReversible?
MaskingHides part or all of a value, for example XXXX-1234Not from the masked output
HashingOne way function turns a value into a fixed digestNo, but equal inputs give equal hashes
EncryptionReversible with a keyYes, with the key
TokenizationReplaces a value with a random token and keeps the mapping in a secure vaultYes, through the vault
PseudonymizationReplaces identifiers with a stand in that can be linked back with extra informationYes, with extra data
AnonymizationRemoves or transforms data so a person cannot be identifiedNot intended to be

Hashing without a salt can be attacked by guessing common values, such as email addresses. A salt is extra data added before hashing so lookup tables of known hashes do not work.

Static and dynamic masking

Static masking changes the stored data, for instance when you create a masked copy for a test environment. Dynamic masking leaves the stored data intact and changes what a query returns depending on who asks.

Amazon Redshift dynamic data masking

Redshift dynamic data masking lets you define a masking policy in SQL and attach it to a column for a user or role. Users and roles that the policy is attached to see the masked value, and a priority setting decides which policy wins when several apply.

CREATE MASKING POLICY mask_card
WITH (card_number VARCHAR(19))
USING ('XXXX-XXXX-XXXX-0000'::VARCHAR(19));

ATTACH MASKING POLICY mask_card
ON payments(card_number)
TO ROLE analyst;

The policy uses SQL expressions, so it can show the last four characters instead of a constant. Redshift also has row level security for hiding entire rows.

Lake Formation filters and views

Lake Formation data filters exclude sensitive columns or rows for a principal, as the earlier page explains. This is the right tool for a data lake. A SQL view that omits or transforms columns offers a simple alternative in Athena, but remember that users need access to the view, not the base table, for the protection to work.

SELECT customer_id,
       to_hex(sha256(to_utf8(email))) AS email_hash,
       substr(postcode, 1, 3) AS postcode_area
FROM customers;

This Athena query hashes the email and generalizes the postcode. Hashing keeps the field usable for joins and counting distinct people, since the same email always gives the same hash.

Detecting sensitive data

You cannot protect what you cannot find. Amazon Macie scans S3 buckets for sensitive data such as names, financial details and credentials.

AWS Glue has a sensitive data detection transform that finds and can mask or hash personal data inside an ETL job. Glue DataBrew offers PII transformations that substitute, hash, shuffle, encrypt or null out values.

Anonymization methods

MethodExample
RemovalDrop the name and address columns
GeneralizationReplace an exact age with an age band, or a full postcode with a region
AggregationReport counts and averages, not individual rows
ShufflingReorder values within a column so rows no longer match people
NoiseAdd small random changes to numbers

Combining several quasi identifiers, such as birth date, postcode and gender, can still identify a person, so generalize them together. Test the result for re identification risk before sharing.

Where to apply protection

Apply masking at the layer closest to the consumer. Keep the raw zone encrypted and restricted, create masked or hashed copies in the curated zone for broad use, and use dynamic policies where one table serves users with different rights.

Combining controls

Masking does not replace encryption or access control. Use all three: encrypt data at rest and in transit, restrict who can reach raw data, and mask what each audience sees.

What to remember for the exam

  • Masking hides values. Hashing is one way. Encryption is reversible with a key. Tokenization uses a vault.
  • Redshift dynamic data masking changes query results per user or role without changing stored data.
  • Lake Formation data filters remove columns and rows for chosen principals.
  • Macie finds sensitive data in S3. Glue and DataBrew can detect and transform PII.
  • Hashing keeps joins possible. Salting protects against lookups of known values.
  • Anonymization uses removal, generalization, aggregation, shuffling and noise.
  • Combine quasi identifiers carefully, since they can reveal identity together.
  • Apply masking close to the consumer and keep raw data tightly controlled.
Exam tip

When one table must show full values to the privacy team and masked values to analysts, think Redshift dynamic data masking or Lake Formation filters, not copies of the table.

Common mistakes

Treating hashing as encryption. A hash cannot be reversed, so it fits joins and matching but not recovering the original value.

Hashing without a salt. Common values can be guessed by hashing a list of candidates.

Masking in the app only. If users can query the table directly, the data is still exposed.

Removing only direct identifiers. Remaining fields may still point to a person.

Watch out

A view only protects data if users have access to the view and not the underlying table, so check both permissions.

Check yourself

  • Which Redshift feature changes query results by role without altering stored data?

    Dynamic data masking policies.

  • Why salt a hash?

    It stops attackers from matching hashes against precomputed lists of common values.

  • Which service finds sensitive data in S3?

    Amazon Macie.

Topic 5 of 7 in Data Security and Governance

Test yourself on Data Security and Governance

The full AWS DEA-C01 question bank has 845 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.