It’s been a while since, AWS have announced Syntax Analysis feature in the AWS Comprehend service. A quick intro on AWS Comprehend service from documentationAmazon Comprehend uses natural language processing (NLP) to extract insights about the content of documents. Amazon Comprehend processes any text file in UTF-8 format. It develops insights by recognizing the entities, key phrases, language, sentiments, and other common elements in a document. Use Amazon Comprehend to create new products based on understanding the structure of documents. For example, using Amazon Comprehend you can search social networking feeds for mentions of products or scan an entire document repository for key phrases.

I have did couple of video tutorials on extraction Entities, Key Phrase identification and the sentimental analysis on the raw text using AWS Lambda and the AWS Comprehend service. In this article, I’ll show you that how to leverage the power of the Syntax Analysis on the raw text, which is recently announced feature. We will be using three AWS service here, which is IAM, AWS Lambda and the AWS Comprehend. You can also refer the series of the AWS Lambda tutorial.

Here, we will pass the static text to the AWS Comprehend from the Lambda function, but you can also set the trigger on the S3 Bucket to read the raw text from the file itself and pass the same to the AWS Comprehend. To let Lambda access the Comprehend, we need to assign the permission to the Lambda using IAM role. So, let’s get started with creating the IAM role.


Login to the AWS Console. Please follow below steps to create IAM role.

  • Navigate to IAM service
  • Click on Roles from left panel & Create role
  • Choose Lambda under “Choose the service that will use this role” & Next:Permissions
  • Search and select “AWSLambdaExecute” and “ComprehendFullAccess” & Next:Review
  • Define the role name “comprehend_lambda_role” & Create role

AWS Lambda

Now, let’ s go ahead to AWS Lambda service and create the function. Once you are there, follow the below steps.

  • Navigate to AWS Lambda service
  • Click on Create function
  • Define the FunctionName, Runtime as Python 3.6 and choose the role, that we just created in IAM section (i.e. “comprehend_lambda_role”) and click on Create function
  • Under the Function code -> lambda_function, use this code from GitHub and paste and Save.

Now go ahead and test the function and look into the logs for results. You can use that response as per your requirement.


Keep sharing. Stay tuned for more. Follow me on Twitter