Wednesday, September 2, 2026
HomeBig DataConstruct an information pipeline to mechanically uncover and masks PII knowledge with...

Construct an information pipeline to mechanically uncover and masks PII knowledge with AWS Glue DataBrew

[ad_1]

Personally identifiable info (PII) knowledge dealing with is a standard requirement when working an information lake at scale. Companies typically have to mitigate the chance of exposing PII knowledge to the information science crew whereas not hindering the productiveness of the crew to get to the information they want with a view to generate precious knowledge insights. Nonetheless, there are challenges in putting the precise stability between knowledge governance and agility:

  • Proactively figuring out the dataset that accommodates PII knowledge, if it’s not labeled by the information suppliers
  • Figuring out to what extent the information scientists can entry the dataset
  • Minimizing possibilities that the information lake operator is visually uncovered to PII knowledge after they course of the information

To assist overcome these challenges, we will construct an information pipeline that mechanically scans knowledge upon its arrival to the information lake, then additional masks the portion of information that’s labeled as PII knowledge. Automating the PII knowledge scanning and masking duties helps forestall human actors processing the information whereas the PII knowledge continues to be offered in plain textual content, but nonetheless supplies knowledge shoppers well timed entry to the newly arrived dataset.

To construct an information pipeline that may mechanically deal with PII knowledge, you should use AWS Glue DataBrew. DataBrew is a no-code knowledge preparation device with pre-built transformations to automate knowledge preparation duties. It natively helps PII knowledge identification, entity detection, and PII knowledge dealing with options. Along with its visible interface for no-code knowledge preparation, it affords APIs to allow you to orchestrate the creation and working of DataBrew profile jobs and recipe jobs.

On this publish, we illustrate how one can orchestrate DataBrew jobs with AWS Step Features to construct an information pipeline to deal with PII knowledge. The pipeline is triggered by Amazon Easy Storage Service (Amazon S3) occasion notifications despatched to Amazon EventBridge at any time when there’s a new knowledge object lands in a S3 bucket. We additionally embrace an AWS CloudFormation template so that you can deploy as a reference.

Resolution overview

The next diagram describes the answer structure.

Architecture Diagram

The answer features a S3 bucket as the information enter bucket and one other S3 bucket as the information output bucket. Knowledge uploaded to the information enter bucket sends an occasion to EventBridge to set off the information pipeline. The pipeline consists of a Step Features state machine, DataBrew jobs, and an AWS Lambda perform used for studying the outcomes of the DataBrew profile job.

The answer workflow contains the next steps:

  1. A brand new knowledge file is uploaded to the information enter bucket.
  2. EventBridge receives an object created occasion from the S3 bucket, and triggers the Step Features state machine.
  3. The state machine makes use of DataBrew to register the S3 object as a brand new DataBrew dataset, and creates a profile job. The profile job outcomes, together with the PII statistics, are written to the information output bucket.
  4. A Lambda perform reads the profile job outcomes and returns whether or not the information file accommodates PII knowledge.
  5. If no PII knowledge is discovered, the workflow is full; in any other case, a DataBrew recipe job is created to focus on the columns that comprise PII knowledge.
  6. When working the DataBrew recipe job, DataBrew makes use of the key (a base64 encoded string, akin to TXlTZWNyZXQ=) saved in AWS Secrets and techniques Supervisor to hash the PII columns.
  7. When the job is full, the brand new knowledge file with PII knowledge hashed is written to the information output bucket.

Stipulations

To deploy the answer, it’s best to have the next conditions:

Deploy the answer utilizing AWS CloudFormation

To deploy the answer utilizing the CloudFormation template, full the next steps.

  1. Check in to your AWS account.
  2. Select Launch Stack:
  3. Navigate to one of many AWS Areas the place DataBrew is obtainable (akin to us-east-1).
  4. For Stack title, enter a reputation for the stack or go away as default (automate-pii-handling-data-pipeline).
  5. For HashingSecretValue, enter a secret (which is base64 encoded through the CloudFormation stack creation) to make use of for knowledge hashing.
  6. For PIIMatchingThresholdValue, enter a threshold worth (1–100 by way of share, default is 80) to point the specified share of data the DataBrew profile job should determine as PII knowledge in a given column, in order that the information within the column is additional hashed by the next DataBrew PII recipe job.
  7. Choose I acknowledge that AWS CloudFormation would possibly create IAM assets.
  8. Select Create stack.

CloudFormation Quick Launch Page

The CloudFormation stack creation course of takes round 3-4 minutes to finish.

Take a look at the information pipeline

To check the information pipeline, you possibly can obtain the pattern artificial knowledge generated by Mockaroo. The dataset accommodates artificial PII fields akin to e-mail, contact quantity, and bank card quantity.

Data Preview

The pattern knowledge accommodates columns of PII knowledge as an illustration; you should use DataBrew to detect PII values right down to the cell stage.

  1. On the AWS CloudFormation console, navigate to the Outputs tab for the stack you created.
  2. Select the URL worth for AmazonS3BucketForGlueDataBrewDataInput to navigate to the S3 bucket created for DataBrew knowledge enter.
    CloudFormation Stack Output 1
  3. Select Add.
    S3 Object Upload Page
  4. Select Add information to add the information file you downloaded.
  5. Select Add once more.
  6. Return to the Outputs tab for the CloudFormation stack.
  7. Select the URL worth for AWSStepFunctionsStateMachine.
    CloudFormation Stack Output 2
    You’re redirected to the Step Features console, the place you possibly can overview the state machine you created. The state machine ought to be in a Working state.
  1. Within the Executions listing, select the present run of the state machine.
    Step Functions State Machine
    A graph inspector visualizes which step of the pipeline is being run. You may also examine the step enter and output of every step accomplished.Step Functions Graph Inspector
    For the offered pattern dataset, with 8 columns containing 1,000 rows of data, the entire run takes roughly 7–8 minutes.

Knowledge pipeline particulars

Whereas we’re ready for the steps to finish, let’s clarify extra of how this knowledge pipeline is constructed. The next determine is the detailed workflow of the Step Features state machine.

Step Functions Workflow

The important thing step within the state machine is the Lambda perform used to parse the DataBrew profile job end result. The next code is a snippet of the profile job lead to JSON format:

{
    "defaultProfileConfiguration": {...
    },
    "entityDetectorConfigurationOverride": {
        "AllowedStatistics": [...
        ],
        "EntityTypes": [
            "USA_ALL",
            "PERSON_NAME"
        ]
    },
    "datasetConfigurationOverride": {},
    "sampleSize": 1000,
    "duplicateRowsCount": 0,
    "columns": [
        {...
        },
        {
            "name": "email_address",
            "type": "string",
            "entity": {
                "rowsCount": 1000,
                "entityTypes": [
                    {
                        "entityType": "EMAIL",
                        "rowsCount": 1000
                    }
                ]
            }...
        }...
    ]...
}

Inside columns, every column object has the property entity if it’s detected to be a column containing PII knowledge. rowsCount inside entity tells us what number of rows out of the entire pattern are recognized as PII, adopted by entityTypes to point the kind of PII recognized.

The next is the Python code used within the Lambda perform:

import json
import boto3
import os

def lambda_handler(occasion, context):

  s3Bucket = occasion["Outputs"][0]["Location"]["Bucket"]
  s3ObjKey = occasion["Outputs"][0]["Location"]["Key"]

  s3 =boto3.shopper('s3')
  glueDataBrewProfileResultFile = s3.get_object(Bucket=s3Bucket, Key=s3ObjKey)
  glueDataBrewProfileResult = json.masses(glueDataBrewProfileResultFile['Body'].learn().decode('utf-8'))
  columnsProfiled = glueDataBrewProfileResult["columns"]
  PIIColumnsList = []

  for merchandise in columnsProfiled:
    if "entityTypes" in merchandise["entity"]:
      if (merchandise["entity"]["rowsCount"]/glueDataBrewProfileResult["sampleSize"]) >= int(os.environ.get("threshold"))/100:
        PIIColumnsList.append(merchandise["name"])

  if PIIColumnsList == []:
    return 'No PII columns discovered.'
  else:
    return PIIColumnsList

To summarize what the logic of the Lambda perform is, a for-loop is applied to combination a listing of column names, wherein the ratio of PII rows over the entire pattern dimension of that column is bigger than or equal to the edge worth set earlier within the CloudFormation stack creation step. The Lambda perform returns the listing of column names to the Step Features state machine to creator a DataBrew recipe that masks solely the columns within the returned listing, as a substitute of all of the columns of the dataset. This manner, we retain the content material of non-PII columns for the information client whereas not exposing the PII knowledge in plain textual content.

Step Functions Workflow Studio

We use CRYPTOGRAPHIC_HASH on this answer for the Operation parameter of the DataBrew CreateRecipe step. As a result of the profile job end result and threshold worth have already been used to find out which columns comprise PII knowledge to masks, the recipe step doesn’t embrace the parameter entityTypeFilter to implement all rows of the columns getting hashed. In any other case, some rows within the column may not be hashed by the operation if the actual rows of information aren’t recognized by DataBrew as PII.

In case your dataset probably accommodates free-text columns akin to physician notes and e-mail physique, it could be useful to incorporate the parameter entityTypeFilter in an extra recipe step to deal with the free-text columns. For extra info, check with the values supported for this parameter.

To customise the answer additional, you can even select different PII recipe steps obtainable from DataBrew to masks, exchange, or rework the information in approaches greatest suited in your use circumstances.

Knowledge pipeline outcomes

After a deeper dive into the answer elements, let’s test if all of the steps within the Step Features state machine are full and overview the outcomes.

  1. Navigate to the Datasets web page on the DataBrew console to view the information profile results of the dataset you simply uploaded.
    Glue DataBrew Datasets
    5 columns of the dataset have been recognized as columns containing PII knowledge. Relying on the edge worth you set when creating the CloudFormation stack (the default is 80), the column spoken_language wouldn’t be included within the PII knowledge masking step as a result of solely 14% of the rows had been recognized as a reputation of an individual.
  1. Navigate to the Jobs web page to examine the output of the information masking step.
  2. Select 1 output to see the S3 bucket containing the information output.
    Glue DataBrew Job Ouput
  3. Select the worth for Vacation spot to navigate to the S3 bucket.
    Glue DataBrew Job Output Destination
    The info output S3 bucket accommodates a .json file, which is the information profile end result you simply reviewed in JSON format. There may be additionally a folder path that accommodates the information output of the PII knowledge masking job.
  1. Select the folder path.
    Glue DataBrew Output in S3
  2. Choose the CSV file, which is the output of the DataBrew recipe job.
  3. On the Actions menu, select Question with S3 Choose.
    S3 Select
  4. Within the SQL question part, select Run SQL question.
    Query Result
    The question outcomes sampled 5 rows from the information output of the DataBrew recipe job; the columns recognized as PII (full_name, email_address, and contact_phone_number) have been masked. Congratulations! You have got efficiently produced a dataset from an information pipeline that detects and masks PII knowledge mechanically.

Clear up

To keep away from incurring future prices, delete the assets you created as a part of this publish.

On the AWS CloudFormation console, delete the stack you created (default title is automate-pii-handling-data-pipeline).

Conclusion

On this publish, you discovered construct an information pipeline that mechanically detects PII knowledge and masks the information accordingly when a brand new knowledge file arrives in an S3 bucket. With DataBrew profile jobs, you possibly can develop logics with low code to run mechanically on the profile outcomes. For this publish, our job decided which columns to masks. You may also creator the DataBrew recipe job in an automatic method, which helps restrict events when human actors can entry the PII knowledge whereas it’s nonetheless in plain textual content.

You possibly can be taught extra about this answer and the supply code by visiting the GitHub repository. To be taught extra about what DataBrew can do in dealing with PII knowledge, check with Introducing PII knowledge identification and dealing with utilizing AWS Glue DataBrew and Personally identifiable info (PII) recipe steps.


In regards to the Creator

Author

Samson Lee is a Options Architect with a give attention to the information analytics area. He works with clients to construct enterprise knowledge platforms, discovering and designing options on AI/ML use circumstances. Samson additionally enjoys espresso and wine tasting exterior of labor.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments