A comprehensive pipeline using AWS Glue and PySpark to perform Data Loss Prevention (DLP) by identifying and redacting sensitive information within datasets.
This Blog Post is part of Building and Securing Data Pipelines: From Governance to Secure Implementation Series
A practical guide for engineers and managers to design secure, compliant data pipelines — from governance basics to production-grade implementation.
- Blog 1: Data Governance for Engineers: The 5 Pillars Every Secure Pipeline Needs
- Blog 2: Designing a Data Pipeline Architecture That Embeds Governance & Security
- Blog 3: Mapping Data Governance to AWS: Building a Secure DLP Pipeline
- Blog 4: Securing Data Pipelines: Privacy, Compliance, and Security-by-Design on AWS
The pipeline reads raw data from an S3 bucket, identifies common sensitive data patterns (email addresses, phone numbers, credit card numbers), redacts them using configurable replacement strings, and stores the sanitized data in a destination S3 bucket.
Raw Data (S3) → AWS Glue Data Catalog → AWS Glue ETL Job (PySpark) → Sanitized Data (S3)
- Source S3 Bucket: Stores raw, unsanitized data
- AWS Glue Data Catalog: Schema repository for data discovery
- AWS Glue ETL Job: PySpark-based data processing and redaction
- Destination S3 Bucket: Stores processed, redacted data
- IAM Role: Secure access controls for Glue job execution
- AWS Glue: ETL job creation, Data Catalog management, Glue resource configuration
- PySpark: DataFrame operations, regex pattern matching, distributed data processing
- AWS S3: Secure data storage, encryption, access controls
- AWS IAM: Least-privilege access, role-based security
- Data Loss Prevention (DLP): Sensitive data identification and masking
- Data Governance: Privacy protection and compliance mechanisms
| Pattern Type | Regex Pattern | Redaction String |
|---|---|---|
[\w\.-]+@[\w\.-]+ |
[EMAIL_REDACTED] |
|
| Phone Number | \d{3}[-.\s]?\d{3}[-.\s]?\d{4}|\(\d{3}\)[-.\s]?\d{3}[-.\s]?\d{4} |
[PHONE_REDACTED] |
| Credit Card | \b(?:\d[ -]*?){13,16}\b |
[CC_REDACTED] |
- AWS Account with appropriate permissions
- Basic understanding of AWS Glue, S3, and IAM
Create an IAM role (eg. GlueDLPJobRole) for AWS Glue with the following policies:
AWSGlueServiceRoleAmazonS3FullAccess(or custom policy for specific buckets)CloudWatchLogsFullAccess
- Source Bucket (e.g.
aws-glue-raw-data-bucket-here) - Destination Bucket (e.g.
aws-glue-sanitized-data-bucket) - Scripts Bucket (e.g.
aws-glue-scripts-bucket-pranav)
- Create a Glue Crawler to scan your source S3 bucket
- Configure the crawler to create a database and table definitions
- Run the crawler to populate the Data Catalog
- Navigate to AWS Glue Console → Jobs
- Create a new job with the following configuration:
- Type: Spark
- Glue Version: 3.0 or later
- Language: Python 3
- IAM Role: Your created Glue role
- Script: Upload the
DLP_Redaction_Job.pyfile
Set the following job parameters:
--SOURCE_DATABASE: Database name in Glue Data Catalog--SOURCE_TABLE: Table name in Glue Data Catalog--DESTINATION_PATH: S3 path for sanitized data output
-
Run the Glue ETL Job which runs the
DLP_Redaction_Job.pyfile from the scripts bucket
-
It will output a new file to destination bucket
Feel free to submit issues and enhancement requests. This project serves as a foundation for building more sophisticated DLP solutions in AWS environments.






