Package: cdk-comprehend-s3olap
cdk-comprehend-s3olapnpm (JS/TS)PyPI (Python)Maven (Java)GoNuGetLinkLinkLinkLinkLinkThis construct creates the foundation for developers to explore the combination of Amazon S3 Object Lambda and Amazon Comprehend for PII scenarios and it is designed with flexibility, i.e, the developers could tweak arguments via CDK to see how AWS services work and behave.Table of ContentsServerless ArchitectureAccess ControlRedactionIntroductionExampleTypescriptPythonJavaC#Some NotesServerless ArchitectureAccess ControlData FlowRam R. and Austin Q., 2021ArhictectureRam R. and Austin Q., 2021RedactionRam R. and Austin Q., 2021Ram R. and Austin Q., 2021IntroductionThe architecture was introduced byRam RamaniandAustin Quamand was posted on the AWS Blog asProtect PII using Amazon S3 Object Lambda to process and modify data during retrieval.
I converted the architecture into a CDK constrcut for 4 programming languages. With this construct, you could manage the properties of IAM roles, the Lambda functions with Amazon Comprehend, and few for the constrcut.
Before deploying the construct via the CDK, you could either places the text files, i.e., those for the access control case and redaction case, under a directory with a specific name as the following or just deploying directly yet you need to upload the text files onto the S3 buckets manually yourself. It's all your choie.# For the access control case.$cd${ROOT_DIRECTORY_CDK_APPLICATION}$mkdir-pfiles/access_control
$curl-osurvey-results.txthttps://raw.githubusercontent.com/aws-samples/amazon-comprehend-examples/master/s3_object_lambda_pii_protection_blog/access-control/survey-results.txt
$curl-oinnocuous.txthttps://raw.githubusercontent.com/aws-samples/amazon-comprehend-examples/master/s3_object_lambda_pii_protection_blog/access-control/innocuous.txt# For the redaction case.$cd${ROOT_DIRECTORY_CDK_APPLICATION}$mkdir-pfiles/redaction
$curl-otranscript.txthttps://raw.githubusercontent.com/aws-samples/amazon-comprehend-examples/master/s3_object_lambda_pii_protection_blog/redaction/transcript.txtExampleTypescriptYou could also refer tohere.$cdk--initlanguagetypescript
$yarnaddcdk-comprehend-s3olapimport*ascdkfrom'@aws-cdk/core';import{ComprehendS3olab}from'cdk-comprehend-s3olap';classTypescriptStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);consts3olab=newComprehendS3olab(this,'PiiDemo',{adminRedactionLambdaConfig:{maskCharacter:' ',unsupportedFileHandling:'PASS',},billingRedactionLambdaConfig:{maskMode:'REPLACE_WITH_PII_ENTITY_TYPE',piiEntityTypes:'AGE,DRIVER_ID,IP_ADDRESS,MAC_ADDRESS,PASSPORT_NUMBER,PASSWORD,SSN',},cusrtSupportRedactionLambdaConfig:{maskMode:'REPLACE_WITH_PII_ENTITY_TYPE',piiEntityTypes:' BANK_ACCOUNT_NUMBER,BANK_ROUTING,CREDIT_DEBIT_CVV,CREDIT_DEBIT_EXPIRY,CREDIT_DEBIT_NUMBER,SSN',},});newcdk.CfnOutput(this,'OPiiAccessControlLambdaArn',{value:s3olab.piiAccessConrtolLambdaArn});newcdk.CfnOutput(this,'OAdminLambdaArn',{value:s3olab.adminLambdaArn});newcdk.CfnOutput(this,'OBillingLambdaArn',{value:s3olab.billingLambdaArn});newcdk.CfnOutput(this,'OCustomerSupportLambdaArn',{value:s3olab.customerSupportLambdaArn});newcdk.CfnOutput(this,'OS3ObjectLambdaGeneralArn',{value:s3olab.s3objectLambdaAccessControlArn});newcdk.CfnOutput(this,'OS3ObjectLambdaAdminArn',{value:s3olab.s3objectLambdaAdminArn});newcdk.CfnOutput(this,'OS3ObjectLambdaBillingArn',{value:s3olab.s3objectLambdaBillingArn});newcdk.CfnOutput(this,'OS3ObjectLambdaCustomerSupportArn',{value:s3olab.customerSupportLambdaArn});}}constapp=newcdk.App();newTypescriptStack(app,'TypescriptStack',{stackName:'Comprehend-S3olap',});PythonYou could also refer tohere.# upgrading related Python packages$python-mensurepip--upgrade
$python-mpipinstall--upgradepip
$python-mpipinstall--upgradevirtualenv# initialize a CDK Python project$cdkinit--languagepython# make packages installed locally instead of globally$source.venv/bin/activate
$# add "cdk-comprehend-s3olap==2.0.113" into `setup.py`$python-mpipinstall--upgrade-rrequirements.txtThe demonstration sample code of Python can be viewed via the Python tab of this package on theConstrcut Hub.JavaYou could also refer tohere.$cdkinit--languagejava
$mvnpackage# If you include the construct, you need to tweak the test case for Java in order to package with success via Maven.```xml
.
.
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><cdk.version>2.72.1</cdk.version><constrcut.verion>2.0.113</constrcut.verion><junit.version>5.7.1</junit.version>
</properties>
.
.
<dependencies><!--AWSCloudDevelopmentKit--><dependency><groupId>software.amazon.awscdk</groupId><artifactId>core</artifactId><version>${cdk.version}</version></dependency><dependency><groupId>io.github.hsiehshujeng</groupId><artifactId>cdk-comprehend-s3olap</artifactId><version>${constrcut.verion}</version></dependency>...
</dependencies>packagecom.myorg;importsoftware.amazon.awscdk.core.CfnOutput;importsoftware.amazon.awscdk.core.CfnOutputProps;importsoftware.amazon.awscdk.core.Construct;importsoftware.amazon.awscdk.core.Stack;importsoftware.amazon.awscdk.core.StackProps;importio.github.hsiehshujeng.cdk.comprehend.s3olap.RedactionLambdaProps;importio.github.hsiehshujeng.cdk.comprehend.s3olap.ComprehendS3olab;importio.github.hsiehshujeng.cdk.comprehend.s3olap.ComprehendS3olabProps;publicclassJavaStackextendsStack{publicJavaStack(finalConstructscope,finalStringid){this(scope,id,null);}publicJavaStack(finalConstructscope,finalStringid,finalStackPropsprops){super(scope,id,props);ComprehendS3olabs3olab=newComprehendS3olab(this,"PiiDemo",ComprehendS3olabProps.builder().adminRedactionLambdaConfig(RedactionLambdaProps.builder().maskCharacter(" ").unsupportedFileHandling("PASS").build()).billingRedactionLambdaConfig(RedactionLambdaProps.builder().maskMode("REPLACE_WITH_PII_ENTITY_TYPE").piiEntityTypes("AGE,DRIVER_ID,IP_ADDRESS,MAC_ADDRESS,PASSPORT_NUMBER,PASSWORD,SSN").build()).cusrtSupportRedactionLambdaConfig(RedactionLambdaProps.builder().maskMode("REPLACE_WITH_PII_ENTITY_TYPE").piiEntityTypes("BANK_ACCOUNT_NUMBER,BANK_ROUTING,CREDIT_DEBIT_CVV,CREDIT_DEBIT_EXPIRY,CREDIT_DEBIT_NUMBER,SSN").build()).exampleFileDir("/opt/learning/cdk-comprehend-s3olap/src/demo/java").build());newCfnOutput(this,"OPiiAccessControlLambdaArn",CfnOutputProps.builder().value(s3olab.getPiiAccessConrtolLambdaArn()).build());newCfnOutput(this,"OAdminLambdaArn",CfnOutputProps.builder().value(s3olab.getAdminLambdaArn()).build());newCfnOutput(this,"OBillingLambdaArn",CfnOutputProps.builder().value(s3olab.getBillingLambdaArn()).build());newCfnOutput(this,"OCustomerSupportLambdaArn",CfnOutputProps.builder().value(s3olab.getCustomerSupportLambdaArn()).build());newCfnOutput(this,"OS3ObjectLambdaGeneralArn",CfnOutputProps.builder().value(s3olab.getS3objectLambdaAccessControlArn()).build());newCfnOutput(this,"OS3ObjectLambdaAdminArn",CfnOutputProps.builder().value(s3olab.getS3objectLambdaAdminArn()).build());newCfnOutput(this,"OS3ObjectLambdaBillingArn",CfnOutputProps.builder().value(s3olab.getS3objectLambdaBillingArn()).build());newCfnOutput(this,"OS3ObjectLambdaCustomerSupportArn",CfnOutputProps.builder().value(s3olab.getCustomerSupportLambdaArn()).build());}}C#You could also refer tohere.$cdkinit--languagecsharp
$dotnetaddsrc/CsharppackageComprehend.S3olap--version2.0.113usingAmazon.CDK;usingScottHsieh.Cdk;namespaceCsharp{publicclassCsharpStack:Stack{internalCsharpStack(Constructscope,stringid,IStackPropsprops=null):base(scope,id,props){varS3olab=newComprehendS3olab(this,"PiiDemo",newComprehendS3olabProps{AdminRedactionLambdaConfig=newRedactionLambdaProps{MaskCharacter=" ",UnsupportedFileHandling="PASS"},BillingRedactionLambdaConfig=newRedactionLambdaProps{MaskMode="REPLACE_WITH_PII_ENTITY_TYPE",PiiEntityTypes="AGE,DRIVER_ID,IP_ADDRESS,MAC_ADDRESS,PASSPORT_NUMBER,PASSWORD,SSN"},CusrtSupportRedactionLambdaConfig=newRedactionLambdaProps{MaskMode="REPLACE_WITH_PII_ENTITY_TYPE",PiiEntityTypes="BANK_ACCOUNT_NUMBER,BANK_ROUTING,CREDIT_DEBIT_CVV,CREDIT_DEBIT_EXPIRY,CREDIT_DEBIT_NUMBER,SSN"},ExampleFileDir="/opt/learning/cdk-comprehend-s3olap/src/demo/csharp"});newCfnOutput(this,"OPiiAccessControlLambdaArn",newCfnOutputProps{Value=S3olab.PiiAccessConrtolLambdaArn});newCfnOutput(this,"OAdminLambdaArn",newCfnOutputProps{Value=S3olab.AdminLambdaArn});newCfnOutput(this,"OBillingLambdaArn",newCfnOutputProps{Value=S3olab.BillingLambdaArn});newCfnOutput(this,"OCustomerSupportLambdaArn",newCfnOutputProps{Value=S3olab.CustomerSupportLambdaArn});newCfnOutput(this,"OS3ObjectLambdaGeneralArn",newCfnOutputProps{Value=S3olab.S3objectLambdaAccessControlArn});newCfnOutput(this,"OS3ObjectLambdaAdminArn",newCfnOutputProps{Value=S3olab.S3objectLambdaAdminArn});newCfnOutput(this,"OS3ObjectLambdaBillingArn",newCfnOutputProps{Value=S3olab.S3objectLambdaBillingArn});newCfnOutput(this,"OS3ObjectLambdaCustomerSupportArn",newCfnOutputProps{Value=S3olab.CustomerSupportLambdaArn});}}}Some NotesYou should see similar items as the following diagram displays after deploying the constrcut.After creating the foundation with success, you could switch roles that the consrtcut creates for you and see howAmazon S3 Object Lambdaworks. For what switching roles is, please refer toherefor the detail.You exploreAmazon S3 Object Lambdathrough the Object Lambda access points on the AWS Console and open or download the text files via one of the IAM roles.Lambda code that incorporates withAmazon Comprehendcould be seehere.