# Data Masking

Data masking conceals sensitive values by replacing, obscuring, or suppressing them while retaining useful information for an authorized task.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/data-masking

> Data masking reduces unnecessary exposure of confidential information in logs, messages, query results, and nonproduction datasets. It complements encryption and access control by limiting which sensitive values users and downstream systems can actually see.

Practice exams covering Data Masking: [DEA-C01 AWS Certified Data Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate), [DVA-C02 AWS Certified Developer - Associate](https://blowstack.com/practice-exams/aws-certified-developer-associate), [DOP-C02 AWS Certified DevOps Engineer - Professional](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional), [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [MLA-C02 (beta) AWS Certified Machine Learning Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate), [SCS-C03 AWS Certified Security - Specialty](https://blowstack.com/practice-exams/aws-certified-security-specialty), [SAP-C03 AWS Certified Solutions Architect - Professional](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional).

## 6 key aspects of Data Masking

Effective masking combines selective disclosure, tested detection, appropriate enforcement boundaries, and tightly controlled access to original values.

1. **Selective disclosure**: Hide sensitive values while preserving the context needed for a task. For example, retain an error code and request identifier while suppressing a customer's national identifier.
2. **Static and dynamic enforcement**: Static masking modifies a copy of data; dynamic masking changes the representation returned to a reader. Determine whether original values remain accessible before treating a masked result as safe to distribute.
3. **Sensitive-data identification**: Combine known field definitions with managed identifiers or custom matching rules. Test for missed matches and false positives, especially for application-specific secrets and identifiers.
4. **Trust-boundary placement**: Apply masking before sensitive content reaches a broader audience or downstream system. An outbound masking rule protects its covered deliveries, not every upstream or parallel copy.
5. **Controlled access to originals**: Where an implementation retains original values, restrict permissions that bypass masking or request unmasked output. Separate routine troubleshooting access from exceptional access to confidential content.
6. **Defense in depth**: Combine masking with data minimization, encryption, least privilege, and retention controls. Treat exposed credentials and cryptographic keys as compromised rather than relying on masking to repair the exposure.

## Cloud services for Data Masking

These services apply masking at different points in a data flow. Amazon SNS can de-identify sensitive message content at configured messaging boundaries, while CloudWatch Logs can mask sensitive values that nevertheless appear in operational logs. Amazon Redshift applies dynamic masking when users query analytical data. Configure each boundary independently rather than assuming one policy follows the data everywhere. Align detection rules and access permissions, test downstream outputs, and verify whether each mechanism preserves original values. Encryption and retention controls remain necessary for the underlying data.

- **[Amazon Redshift](https://blowstack.com/tools/cloud-services-hub/amazon-redshift)**: Dynamic data masking policies transform sensitive column values in query results according to policy assignments and priority. This enables analysts to work with useful results without granting routine visibility into the underlying sensitive values.

## Data Masking exam questions

Real practice exam questions on Data Masking, with the correct answer and its explanation.

### Question 1 (MLA-C02 (beta))

**Question:**

A company is building an ingestion API for English-language customer feedback used to train an ML model. Each request contains less than 5 KB of UTF-8 text. Before the API stores a message, it must identify personally identifiable information (PII), including names, email addresses, and bank account numbers, and replace every character in each detected PII span with an asterisk. The sanitized message must retain its original character count so that existing text annotations remain aligned. Unredacted messages must not be written to Amazon S3, and preprocessing must complete within the ingestion request.

Which solution best meets these requirements?

**Correct answer:** Call Amazon Comprehend DetectPiiEntities for each message. Use the returned beginning and ending character offsets to replace each detected PII span with the same number of asterisks before storing the message.

**Explanation:** DetectPiiEntities synchronously identifies supported PII types and returns their character offsets. Applying length-preserving masking to those spans produces sanitized text while maintaining annotation alignment, without staging unredacted messages in S3.

### Question 2 (SAP-C03)

**Question:**

A manufacturer uses Amazon Bedrock to draft public procurement announcements from internal purchasing notes. Security policy prohibits personal names, email addresses, and confidential bid references in model inputs and generated announcements. Bid references have the format BID- followed by exactly 10 digits and are not a built-in PII type.

If inspection detects prohibited information, the application must reject the entire input or response and return an approved notification. Processing must not continue with redacted content. Testing shows that personal-name detection varies with the surrounding text. An independent approval gate is required before publication because automated inspection alone cannot establish that all sensitive information has been removed.

Which design meets these requirements with the least custom detection code?

**Correct answer:** Configure built-in name and email sensitive information filters and a custom regular expression for bid references with the block action. Inspect inputs before inference and responses before delivery, configure the approved blocked-content messages, and retain context-diverse testing and independent publication approval.

**Explanation:** Built-in PII filters detect names and email addresses, and a custom regular expression detects the organization-specific bid-reference format. The block action rejects all inspected input or response content when sensitive information is detected and returns a configured message. Built-in PII detection is probabilistic and context-dependent, so a clean inspection does not guarantee that no sensitive information remains. Testing and independent publication approval address that coverage limitation.

### Question 3 (DEA-C01)

**Question:**

A company runs an AWS Glue Spark job that processes customer records in a restricted data lake. When validation fails, the job writes the rejected record and exception details to Amazon CloudWatch Logs. Operations engineers need the validation rule, processing stage, and error details for troubleshooting, but company policy prohibits storing customer account identifiers in the logging system. The original records must remain unchanged in the restricted data lake.

Which change meets these requirements?

**Correct answer:** Update the Glue job's logging and exception-handling paths to replace account identifiers with a fixed placeholder before emitting messages, while preserving validation rules, processing stages, and nonsensitive error details.

**Explanation:** Masking before log emission prevents account identifiers from entering the logging system. Applying the transformation to both explicit record logging and exception details closes both exposure paths, preserves useful diagnostics, and leaves the restricted source records unchanged.

### Question 4 (AIP-C01)

**Question:**

A healthcare company operates a generative AI assistant that uses a model hosted outside AWS. Generated responses occasionally contain patient reference numbers that follow a documented organization-specific pattern. These numbers are not needed by users or safety auditors.

A new governance policy requires the application to preserve useful response text while replacing patient reference numbers before responses reach users or any persistent response-log destination. If inspection fails, the application must withhold the response. Auditors need the sanitized response, request identifier, applied policy version, and number of detected references. The company wants to use a managed inspection capability without changing model providers.

Which implementation meets these requirements?

**Correct answer:** Buffer each generated response in memory and call Amazon Bedrock ApplyGuardrail with source OUTPUT, using an approved guardrail version whose sensitive information policy anonymizes matches for a custom regular expression. Deliver and persist only the returned sanitized text after successful inspection; otherwise withhold the response. Record the request identifier, guardrail version, and detection count without recording matched values or the original response.

**Explanation:** ApplyGuardrail can inspect text independently of the model provider. A sensitive information policy with a custom regular expression and the ANONYMIZE action replaces matching references while preserving other text. Applying it before delivery and logging, using the transformed output, and withholding responses when inspection fails satisfies the exposure boundary. Sanitized content and non-sensitive assessment metadata provide audit evidence.

### Question 5 (DVA-C02)

**Question:**

An application sends JSON logs to an Amazon CloudWatch Logs log group that uses the Standard log class. Some events contain customer email addresses needed for incident investigations. Before the next release, a developer must ensure that email addresses in newly ingested events are masked when support engineers query logs or receive logs through subscriptions. A restricted incident-response role must still be able to retrieve the original values. Historical events are outside the scope of this requirement. Which solution meets these requirements with the least application modification?

**Correct answer:** Configure a log group data protection policy with the managed email-address data identifier and a de-identification operation. Allow only the incident-response role to use logs:Unmask.

**Explanation:** CloudWatch Logs data protection policies can detect and mask email addresses in newly ingested events in Standard-class log groups. Masking applies at supported egress points, including queries and subscriptions. A role with logs:Unmask can request original values through supported interfaces, satisfying the investigation requirement without changing application logging.

### Question 6 (SCS-C03)

**Question:**

A company publishes support alerts to an Amazon SNS Standard topic that delivers messages to Amazon SQS queues. Each alert includes a customer email address in both the JSON message body and a message attribute named CustomerEmail. Subscribers use a separate Severity attribute for routing and do not need CustomerEmail.

The topic has an outbound message data protection policy that uses an AWS managed data identifier to mask email addresses for all subscribers. Testing shows that email addresses in message bodies are masked, but CustomerEmail attribute values remain readable.

The company must deliver every alert while preventing readable email addresses from reaching the queues. The company can change publisher serialization but wants to retain SNS-managed masking without adding processing infrastructure.

Which solution meets these requirements?

**Correct answer:** Stop including the CustomerEmail message attribute in published alerts. Continue including the email address in the message body and retain the existing outbound masking policy.

**Explanation:** SNS message data protection inspects message bodies, not message attributes. Removing the unnecessary sensitive attribute eliminates the unprotected copy, while the existing outbound policy masks the email address in the body. Alerts and the Severity routing attribute can continue to be delivered.

### Question 7 (DOP-C02)

**Question:**

A company runs a legacy authentication application on Amazon EC2 instances. The application sends structured JSON events over a local socket to a trusted log collector without writing the events to disk. Some error events contain a sessionSecret field. The collector currently writes each event to a disk-backed retry queue and then independently delivers copies to Amazon CloudWatch Logs and an Amazon S3 archive.

A new security requirement prohibits persisting sessionSecret values anywhere in the logging system, including local queues, failed-delivery records, CloudWatch Logs, and S3. Unmodified events may exist temporarily in the collector's memory. All other fields must remain available for troubleshooting, and delivery must remain resilient to temporary AWS service outages. The application cannot be modified.

Which change will meet the requirement for events generated after the change?

**Correct answer:** Add an in-memory sanitization stage before the collector's disk-backed queue. Replace sessionSecret values with a fixed placeholder, persist and deliver only sanitized events, and ensure parsing failures and collector diagnostics cannot persist the original payload.

**Explanation:** Sanitizing before the first persistent write prevents secrets from entering the retry queue and either destination. Applying the same protection to parsing failures and diagnostics closes alternative persistence paths. The disk-backed queue can still provide durable retries for sanitized events during service outages.

## Practice Data Masking in a full exam

Questions on Data Masking in each practice exam, with every answer option and an explanation for each:

- [SCS-C03](https://blowstack.com/practice-exams/aws-certified-security-specialty): 12 questions
- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 10 questions
- [MLA-C02 (beta)](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate): 9 questions
- [DVA-C02](https://blowstack.com/practice-exams/aws-certified-developer-associate): 5 questions
- [DEA-C01](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate): 4 questions
- [SAP-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional): 3 questions
- [DOP-C02](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional): 3 questions

## What is Data Masking

Data masking protects sensitive information by hiding selected values rather than making an entire dataset unavailable. A support engineer might see a payment card number as a sequence of asterisks followed by its last four digits, while still seeing the transaction timestamp and error code. The objective is to preserve enough context for troubleshooting, analysis, or testing without exposing information that the task does not require.

Start by identifying sensitive fields and the boundaries where they could escape. Examples include personal identifiers in application logs, credentials accidentally included in error messages, and customer details distributed through messaging systems. Prefer not to collect or emit sensitive values in the first place. When that is impractical, apply masking before data crosses a trust boundary, and check every path that can produce another copy, including exports, subscriptions, retries, and diagnostic output.

Static masking creates a modified copy of data, such as a sanitized dataset for development. Dynamic masking changes what a reader sees while retaining the original value in the underlying system. This distinction matters operationally: a masked display does not prove that the stored value has been removed. Administrators, privileged readers, alternative APIs, or downstream copies might still expose the original, depending on the implementation.

In Amazon CloudWatch Logs, data protection policies use managed or custom data identifiers to detect sensitive information and mask matching content at supported egress points. This capability is available for Standard-class log groups. Policies protect newly ingested events after configuration; they do not retroactively mask previously ingested events. A principal with the logs:Unmask permission can request access to original values through supported interfaces, so that permission should be narrowly controlled and its use monitored.

Amazon SNS message data protection applies policies to Standard topics to inspect message bodies. Policies can audit findings, deny messages containing specified sensitive information, or de-identify matching content through masking or redaction. Inbound policies evaluate messages entering the topic, while outbound policies evaluate messages before delivery to subscribers. Choose the direction and applicable principals deliberately: inspecting a message is not equivalent to preventing its delivery, and masking an outbound delivery does not sanitize every other copy of that message.

Detection requires testing. Pattern-based identifiers can miss unusual formats or incorrectly classify ordinary values, and encoded or encrypted payloads can defeat content inspection. Use representative synthetic examples, including negative cases, and monitor findings without reproducing the sensitive values in alerts. Do not assume that managed identifiers recognize every password, access token, private key, or proprietary identifier.

Masking is not encryption, and neither control replaces the other. Encryption protects data through cryptographic access restrictions, whereas masking limits disclosed content. Masking also does not automatically make data anonymous: remaining fields may permit re-identification. Partial masking improves usability but reveals more information, while aggressive replacement can impair debugging and analysis. If a credential or cryptographic key is exposed, masking subsequent output is insufficient; revoke or rotate the material and address retained copies.

## Learn Data Masking in lessons

10 short lessons on Data Masking in 6 certification courses.

- MLA-C02 (beta): Data Masking: sensitive fields in ML datasets (Premium), https://app.blowstack.com/lessons/data-masking-sensitive-fields-in-ml-datasets-mla-c02
- SAP-C03: Data Masking: sensitive information in generative AI (Premium), https://app.blowstack.com/lessons/data-masking-sensitive-information-in-generative-ai-sap-c03
- DEA-C01: Data Masking: choosing masking transformations (Premium), https://app.blowstack.com/lessons/data-masking-choosing-masking-transformations-dea-c01
- AIP-C01: Data Anonymization vs Data Masking (Premium), https://app.blowstack.com/lessons/data-anonymization-vs-data-masking-aip-c01
- SCS-C03: Data Masking: policy-based disclosure controls (Premium), https://app.blowstack.com/lessons/data-masking-policy-based-disclosure-controls-scs-c03
- DOP-C02: Data Masking: sensitive-value protection in logs (Premium), https://app.blowstack.com/lessons/data-masking-sensitive-value-protection-in-logs-dop-c02
