├── 801-Transcribing-a-podcast ├── .gitignore └── README.md ├── 807-Determining-Location-of-Text-in-an-Image ├── .gitignore ├── book_cover.png └── README.md ├── 806-Physician-Dictation-Analysis ├── .gitignore ├── dictation.mp3 ├── awscookbook806-template.json └── README.md ├── 804-Redacting-PII-from-text-using-Comprehend ├── .gitignore ├── RedactingPIIDataFromaDocumentWithAmazonComprehend.png ├── assume-role-policy.json └── README.md ├── 805-Detecting-Text-in-a-Video ├── sample_movie.mp4 └── README.md ├── 803-Computer-Vision-Analysis-of-Handwritten-Form-Data ├── registration_form.png ├── .gitignore └── README.md ├── README.md ├── .github └── ISSUE_TEMPLATE │ ├── recipe-request.md │ └── bug_report.md └── LICENSE /801-Transcribing-a-podcast/.gitignore: -------------------------------------------------------------------------------- 1 | podcast.mp3 2 | -------------------------------------------------------------------------------- /807-Determining-Location-of-Text-in-an-Image/.gitignore: -------------------------------------------------------------------------------- 1 | output.json 2 | -------------------------------------------------------------------------------- /806-Physician-Dictation-Analysis/.gitignore: -------------------------------------------------------------------------------- 1 | awscookbook806.json 2 | aws-cookbook-806.json 3 | -------------------------------------------------------------------------------- /804-Redacting-PII-from-text-using-Comprehend/.gitignore: -------------------------------------------------------------------------------- 1 | sample_data.txt 2 | sample_data.txt.out 3 | -------------------------------------------------------------------------------- /805-Detecting-Text-in-a-Video/sample_movie.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AWSCookbook/ArtificialIntelligence/HEAD/805-Detecting-Text-in-a-Video/sample_movie.mp4 -------------------------------------------------------------------------------- /806-Physician-Dictation-Analysis/dictation.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AWSCookbook/ArtificialIntelligence/HEAD/806-Physician-Dictation-Analysis/dictation.mp3 -------------------------------------------------------------------------------- /807-Determining-Location-of-Text-in-an-Image/book_cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AWSCookbook/ArtificialIntelligence/HEAD/807-Determining-Location-of-Text-in-an-Image/book_cover.png -------------------------------------------------------------------------------- /803-Computer-Vision-Analysis-of-Handwritten-Form-Data/registration_form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AWSCookbook/ArtificialIntelligence/HEAD/803-Computer-Vision-Analysis-of-Handwritten-Form-Data/registration_form.png -------------------------------------------------------------------------------- /804-Redacting-PII-from-text-using-Comprehend/RedactingPIIDataFromaDocumentWithAmazonComprehend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AWSCookbook/ArtificialIntelligence/HEAD/804-Redacting-PII-from-text-using-Comprehend/RedactingPIIDataFromaDocumentWithAmazonComprehend.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chapter 8 - Artificial Intelligence 2 | ## Set and export your default region 3 | export AWS_REGION=us-east-1 4 | ## Set your AWS ACCOUNT ID 5 | AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) 6 | ## Validate AWS Cli Setup and access 7 | aws ec2 describe-instances 8 | -------------------------------------------------------------------------------- /804-Redacting-PII-from-text-using-Comprehend/assume-role-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Principal": { 7 | "Service": "comprehend.amazonaws.com" 8 | }, 9 | "Action": "sts:AssumeRole" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /806-Physician-Dictation-Analysis/awscookbook806-template.json: -------------------------------------------------------------------------------- 1 | { 2 | "MedicalTranscriptionJobName": "aws-cookbook-806", 3 | "LanguageCode": "en-US", 4 | "Specialty": "PRIMARYCARE", 5 | "Type": "DICTATION", 6 | "OutputBucketName":"awscookbook806-RANDOM_STRING", 7 | "Media": { 8 | "MediaFileUri": "s3://awscookbook806-RANDOM_STRING/dictation.mp3" 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /803-Computer-Vision-Analysis-of-Handwritten-Form-Data/.gitignore: -------------------------------------------------------------------------------- 1 | helper.py 2 | og.py 3 | requirements.txt 4 | ta.py 5 | tdp.py 6 | temp-response.json 7 | textractor.py 8 | textractor.zip 9 | trp.py 10 | trptest.py 11 | output.json 12 | .venv 13 | __pycache__ 14 | .env 15 | registration_form-png-response.json 16 | registration_form-png-page-1-response.json 17 | registration_form-png-page-1-words.csv 18 | registration_form-png-page-1-text.txt 19 | registration_form-png-page-1-text-inreadingorder.txt 20 | registration_form-png-page-1-forms.csv -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/recipe-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Recipe request 3 | about: Suggest a recipe for this Chapter 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your recipe request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe what you'd like to learn** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. -------------------------------------------------------------------------------- /805-Detecting-Text-in-a-Video/README.md: -------------------------------------------------------------------------------- 1 | # Detecting Text in a Video 2 | ## Preparation 3 | ### Set a unique suffix to use for the S3 bucket name: 4 | ``` 5 | RANDOM_STRING=$(aws secretsmanager get-random-password \ 6 | --exclude-punctuation --exclude-uppercase \ 7 | --password-length 6 --require-each-included-type \ 8 | --output text \ 9 | --query RandomPassword) 10 | ``` 11 | 12 | ### Create S3 bucket: 13 | 14 | `aws s3api create-bucket --bucket awscookbook805-$RANDOM_STRING` 15 | 16 | 17 | 18 | ## Clean up 19 | ### Delete the file you copied to your S3 bucket: 20 | 21 | `aws s3 rm s3://awscookbook805-$RANDOM_STRING/sample_movie.mp4` 22 | 23 | ### Delete the S3 bucket: 24 | 25 | `aws s3api delete-bucket --bucket awscookbook805-$RANDOM_STRING` 26 | 27 | ### Unset the environment variable that you created manually: 28 | ``` 29 | unset RANDOM_STRING 30 | unset JOB_ID 31 | ``` 32 | -------------------------------------------------------------------------------- /807-Determining-Location-of-Text-in-an-Image/README.md: -------------------------------------------------------------------------------- 1 | # Determining Location of Text in an Image 2 | ## Preparation 3 | ### Set a unique suffix to use for the S3 bucket name: 4 | ``` 5 | RANDOM_STRING=$(aws secretsmanager get-random-password \ 6 | --exclude-punctuation --exclude-uppercase \ 7 | --password-length 6 --require-each-included-type \ 8 | --output text \ 9 | --query RandomPassword) 10 | ``` 11 | 12 | ### Create S3 bucket: 13 | 14 | `aws s3api create-bucket --bucket awscookbook807-$RANDOM_STRING` 15 | 16 | 17 | 18 | ## Clean up 19 | 20 | ### Delete the file you copied to your S3 bucket: 21 | 22 | `aws s3 rm s3://awscookbook807-$RANDOM_STRING/book_cover.png` 23 | 24 | ### Delete the S3 bucket: 25 | 26 | `aws s3api delete-bucket --bucket awscookbook807-$RANDOM_STRING` 27 | 28 | ### Unset the environment variable that you created manually: 29 | 30 | `unset RANDOM_STRING` 31 | 32 | -------------------------------------------------------------------------------- /803-Computer-Vision-Analysis-of-Handwritten-Form-Data/README.md: -------------------------------------------------------------------------------- 1 | # Computer Vision Analysis of Handwritten Form Data 2 | ## Preparation 3 | ### Set a unique suffix to use for the S3 bucket name: 4 | ``` 5 | RANDOM_STRING=$(aws secretsmanager get-random-password \ 6 | --exclude-punctuation --exclude-uppercase \ 7 | --password-length 6 --require-each-included-type \ 8 | --output text \ 9 | --query RandomPassword) 10 | ``` 11 | 12 | ### Create a S3 bucket: 13 | 14 | `aws s3api create-bucket --bucket awscookbook803-$RANDOM_STRING` 15 | 16 | 17 | 18 | ## Clean up 19 | ### Delete the file you copied to your S3 bucket: 20 | 21 | `aws s3 rm s3://awscookbook803-$RANDOM_STRING/registration_form.png` 22 | 23 | ### Delete the S3 bucket: 24 | 25 | `aws s3api delete-bucket --bucket awscookbook803-$RANDOM_STRING` 26 | 27 | ### Unset the environment variable that you created manually 28 | 29 | `unset RANDOM_STRING` 30 | 31 | ### Deactivate your Python virtual environment and go to the root of the chapter: 32 | 33 | `deactivate && cd ..` 34 | 35 | -------------------------------------------------------------------------------- /801-Transcribing-a-podcast/README.md: -------------------------------------------------------------------------------- 1 | # Transcribing a podcast 2 | ## Preparation 3 | ### Set a unique suffix to use for the S3 bucket name: 4 | ``` 5 | RANDOM_STRING=$(aws secretsmanager get-random-password \ 6 | --exclude-punctuation --exclude-uppercase \ 7 | --password-length 6 --require-each-included-type \ 8 | --output text \ 9 | --query RandomPassword) 10 | ``` 11 | 12 | ### Create a S3 bucket: 13 | 14 | `aws s3api create-bucket --bucket awscookbook801-$RANDOM_STRING` 15 | 16 | 17 | 18 | ## Clean up 19 | ### Remove the S3 objects: 20 | ``` 21 | aws s3 rm s3://awscookbook801-$RANDOM_STRING/awscookbook-801.json 22 | aws s3 rm s3://awscookbook801-$RANDOM_STRING/podcast.mp3 23 | aws s3 rm s3://awscookbook801-$RANDOM_STRING/.write_access_check_file.temp 24 | ``` 25 | 26 | ### Delete the S3 bucket: 27 | 28 | `aws s3api delete-bucket --bucket awscookbook801-$RANDOM_STRING` 29 | 30 | ### Delete the transcription job: 31 | ``` 32 | aws transcribe delete-transcription-job \ 33 | --transcription-job-name awscookbook-801 34 | ``` 35 | 36 | `unset $RANDOM_STRING` 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 AWS Cookbook 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /806-Physician-Dictation-Analysis/README.md: -------------------------------------------------------------------------------- 1 | # Physician Dictation Analysis 2 | ### Set a unique suffix to use for the S3 bucket name: 3 | ``` 4 | RANDOM_STRING=$(aws secretsmanager get-random-password \ 5 | --exclude-punctuation --exclude-uppercase \ 6 | --password-length 6 --require-each-included-type \ 7 | --output text \ 8 | --query RandomPassword) 9 | ``` 10 | 11 | ### Create a S3 bucket: 12 | 13 | `aws s3api create-bucket --bucket awscookbook806-$RANDOM_STRING` 14 | 15 | ### Use Amazon Polly to generate a sample primary care physician dictation of patient information and save as dictation.mp3: 16 | ``` 17 | aws polly synthesize-speech \ 18 | --output-format mp3 \ 19 | --voice-id Joanna \ 20 | --engine neural \ 21 | --text 'Patient Jane Doe experiencing symptoms of headache. Administer 200mg Ibuprofen twice daily.' \ 22 | dictation.mp3 23 | ``` 24 | 25 | ### Upload the mp3 file to your S3 bucket: 26 | 27 | `aws s3 cp ./dictation.mp3 s3://awscookbook806-$RANDOM_STRING/` 28 | 29 | 30 | ## Clean up 31 | ### Remove the S3 objects: 32 | ``` 33 | aws s3 rm \ 34 | s3://awscookbook806-$RANDOM_STRING/medical/aws-cookbook-806.json 35 | aws s3 rm \ 36 | s3://awscookbook806-$RANDOM_STRING/awscookbook806.json 37 | aws s3 rm \ 38 | s3://awscookbook806-$RANDOM_STRING/dictation.mp3 39 | aws s3 rm \ 40 | s3://awscookbook806-$RANDOM_STRING/.write_access_check_file.temp 41 | ``` 42 | 43 | ### Delete the S3 bucket: 44 | 45 | `aws s3api delete-bucket --bucket awscookbook806-$RANDOM_STRING` 46 | 47 | ### Delete the medical transcription job: 48 | ``` 49 | aws transcribe delete-medical-transcription-job \ 50 | --medical-transcription-job-name aws-cookbook-806 51 | ``` 52 | 53 | -------------------------------------------------------------------------------- /804-Redacting-PII-from-text-using-Comprehend/README.md: -------------------------------------------------------------------------------- 1 | # Redacting PII from text using Amazon Comprehend 2 | 3 | 4 | ## Problem 5 | You have a document with potential personally identifiable information (PII) in it. You would like to remove the PII before more processing of the document occurs. 6 | 7 | ## Solution 8 | Create sample data and store it in an S3 bucket. Launch an Amazon Comprehend job to detect and redact PII entities. Finally, view the results (see Figure 8-4). 9 | 10 | ![Figure 8.4](RedactingPIIDataFromaDocumentWithAmazonComprehend.png) 11 | 12 | ### Prerequisite 13 | * S3 bucket with file for analysis and path for output 14 | 15 | ## Preparation 16 | ### Set a unique suffix to use for the S3 BucketName: 17 | ``` 18 | RANDOM_STRING=$(aws secretsmanager get-random-password \ 19 | --exclude-punctuation --exclude-uppercase \ 20 | --password-length 6 --require-each-included-type \ 21 | --output text \ 22 | --query RandomPassword) 23 | ``` 24 | 25 | ### Create a S3 Bucket: 26 | 27 | ``` 28 | aws s3api create-bucket --bucket awscookbook804-$RANDOM_STRING 29 | ``` 30 | 31 | ### Create a path for output in your S3 bucket: 32 | ``` 33 | aws s3api put-object --bucket awscookbook804-$RANDOM_STRING \ 34 | --key redacted_output/ 35 | ``` 36 | 37 | ## Steps 38 | 1. Create a file named assume-role-policy.json with the following content (file provided in the repository): 39 | ``` 40 | { 41 | "Version": "2012-10-17", 42 | "Statement": [ 43 | { 44 | "Effect": "Allow", 45 | "Principal": { 46 | "Service": "comprehend.amazonaws.com" 47 | }, 48 | "Action": "sts:AssumeRole" 49 | } 50 | ] 51 | } 52 | ``` 53 | 54 | 2. Create a role for the Comprehend job to use to read and write data from S3: 55 | ``` 56 | aws iam create-role --role-name AWSCookbook804Comprehend \ 57 | --assume-role-policy-document file://assume-role-policy.json 58 | ``` 59 | You should see output similar to the following: 60 | ``` 61 | { 62 | "Role": { 63 | "Path": "/", 64 | "RoleName": "AWSCookbook804Comprehend", 65 | "RoleId": "<>", 66 | "Arn": "arn:aws:iam::111111111111:role/AWSCookbook804Comprehend", 67 | "CreateDate": "2021-09-22T13:12:22+00:00", 68 | "AssumeRolePolicyDocument": { 69 | "Version": "2012-10-17", 70 | "Statement": [ 71 | { 72 | ... 73 | ``` 74 | 75 | 3. Attach the IAM managed policy for `AmazonS3FullAccess` to the IAM role: 76 | ``` 77 | aws iam attach-role-policy --role-name AWSCookbook804Comprehend \ 78 | --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess 79 | ``` 80 | 81 | 4. Create some sample PII data using [Faker](https://faker.readthedocs.io/en/master/) (or by hand): 82 | ``` 83 | pip install faker 84 | faker -r=10 profile > sample_data.txt 85 | ``` 86 | 87 | 5. Copy your sample data to the bucket: 88 | ``` 89 | aws s3 cp ./sample_data.txt s3://awscookbook804-$RANDOM_STRING 90 | ``` 91 | 92 | You should see output similar to the following: 93 | ``` 94 | upload: ./sample_data.txt to s3://awscookbook804-<>/sample_data.txt 95 | ``` 96 | 97 | 6. Create a start-pii-entities-detection-job with Comprehend: 98 | ``` 99 | JOB_ID=$(aws comprehend start-pii-entities-detection-job \ 100 | --input-data-config S3Uri="s3://awscookbook804-$RANDOM_STRING/sample_data.txt" \ 101 | --output-data-config S3Uri="s3://awscookbook804-$RANDOM_STRING/redacted_output/" \ 102 | --mode "ONLY_REDACTION" \ 103 | --redaction-config PiiEntityTypes="BANK_ACCOUNT_NUMBER","BANK_ROUTING","CREDIT_DEBIT_NUMBER","CREDIT_DEBIT_CVV","CREDIT_DEBIT_EXPIRY","PIN","EMAIL","ADDRESS","NAME","PHONE","SSN",MaskMode="REPLACE_WITH_PII_ENTITY_TYPE" \ 104 | --data-access-role-arn "arn:aws:iam::${AWS_ACCOUNT_ID}:role/AWSCookbook804Comprehend" \ 105 | --job-name "aws cookbook 804" \ 106 | --language-code "en" \ 107 | --output text --query JobId) 108 | ``` 109 | 110 | > TIP: You can alternatively use the [detect-pii-entities](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/comprehend/detect-pii-entities.html) command if you are interested in the location of PII data in a document. This is helpful if you need to process the PII in a certain way. 111 | 112 | 7. Monitor the job until it is COMPLETED; this will take a few minutes: 113 | ``` 114 | aws comprehend describe-pii-entities-detection-job \ 115 | --job-id $JOB_ID 116 | ``` 117 | 118 | You should see output similar to the following: 119 | ``` 120 | { 121 | "PiiEntitiesDetectionJobProperties": { 122 | "JobId": "<>", 123 | "JobName": "aws cookbook 804", 124 | "JobStatus": "COMPLETED", 125 | "SubmitTime": "2021-06-29T18:35:14.701000-04:00", 126 | "EndTime": "2021-06-29T18:43:21.200000-04:00", 127 | "InputDataConfig": { 128 | "S3Uri": "s3://awscookbook804-<>/sample_data.txt", 129 | "InputFormat": "ONE_DOC_PER_LINE" 130 | }, 131 | "OutputDataConfig": { 132 | "S3Uri": "s3://awscookbook804-<>/redacted_output/<>-PII-<>/output/" 133 | }, 134 | ``` 135 | 136 | ## Validation checks 137 | When the job is complete, get the location of the outputted data in S3: 138 | ``` 139 | S3_LOCATION=$(aws comprehend describe-pii-entities-detection-job \ 140 | --job-id $JOB_ID --output text \ 141 | --query PiiEntitiesDetectionJobProperties.OutputDataConfig.S3Uri) 142 | ``` 143 | 144 | Get the output file from S3: 145 | ``` 146 | aws s3 cp ${S3_LOCATION}sample_data.txt.out . 147 | ``` 148 | 149 | You should see output similar to the following: 150 | ``` 151 | download: s3://awscookbook804-<>/redacted_output/111111111111-PII-cb5991dd58105db185a4cc1906e38411/output/sample_data.txt.out to ./sample_data.txt.out 152 | ``` 153 | 154 | View the output: 155 | ``` 156 | cat sample_data.txt.out 157 | ``` 158 | 159 | You should see output similar to the following. Notice the PII has been redacted: 160 | ``` 161 | {'job': 'Arts development officer', 'company': 'Vance Group', 'ssn': '[SSN]', 'residence': 162 | '[ADDRESS]\[ADDRESS]', 'current_location': (Decimal('77.6093685'), Decimal('-90.497660')), 'blood_group': 163 | 'O-', 'website': ['http://cook.com/', 'http://washington.biz/', 'http://owens.net/', 164 | 'http://www.benson.com/'], 'username': 'rrobinson', 'name': '[NAME]', 'sex': 'M', 'address': 165 | '[ADDRESS]\[ADDRESS]', 'mail': '[EMAIL]', 'birthdate': datetime.date(1989, 10, 27)} 166 | ``` 167 | 168 | ## Clean up 169 | ### Detach the AmazonS3FullAccess policy from the role: 170 | ``` 171 | aws iam detach-role-policy --role-name AWSCookbook804Comprehend \ 172 | --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess 173 | ``` 174 | 175 | ### Delete the IAM Role: 176 | 177 | ``` 178 | aws iam delete-role --role-name AWSCookbook804Comprehend 179 | ``` 180 | 181 | ### Delete the objects in your S3 bucket: 182 | ``` 183 | aws s3 rm s3://awscookbook804-$RANDOM_STRING/sample_data.txt 184 | aws s3 rm s3://awscookbook804-$RANDOM_STRING/redacted_output/.write_access_check_file.temp 185 | aws s3 rm ${S3_LOCATION}sample_data.txt.out 186 | aws s3 rm ${S3_LOCATION} 187 | aws s3 rm s3://awscookbook804-$RANDOM_STRING/redacted_output/ 188 | ``` 189 | 190 | ### Delete the S3 bucket: 191 | 192 | ``` 193 | aws s3api delete-bucket --bucket awscookbook804-$RANDOM_STRING 194 | ``` 195 | 196 | ### Unset the environment variable that you created manually: 197 | ``` 198 | unset RANDOM_STRING 199 | unset JOB_ID 200 | unset S3_LOCATION 201 | ``` 202 | 203 | ## Discussion 204 | PII is closely associated with many security and compliance standards that you may come across in your career responsibilities. Generally, if you are responsible for handling PII for your customers, you need to implement security mechanisms to ensure the safety of that data. Furthermore, you may need to detect and analyze the kind of PII you store. While [Amazon Macie](https://aws.amazon.com/macie/) can do this at scale within your S3 buckets or data lake, you may want to detect PII within your application to implement your own checks and workflows. For example, you may have a user fill out a form and submit it, and then detect if they have accidentally disclosed specific types of PII that you are not allowed to store, and reject the upload. 205 | 206 | You can leverage Amazon Comprehend to detect this type of information for you. When you use Comprehend, the predefined feature detection is backed by detection models that are trained using large datasets to ensure quality results. 207 | 208 | ### Challenge 209 | Use Comprehend to label the type of PII rather than just redacting it. (This [documentation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/comprehend/contains-pii-entities.html) provides a hint.) 210 | --------------------------------------------------------------------------------