This project has a lambda function that takes a text string as input, identifies the sentiment of the text through Amazon Comprehend service. If the text is found to have a NEGATIVE sentiment, it triggers a notification to a topic. All subscribers to that topic will receive the notification message.
- Clone the repository to your local machine
- Create an IAM Role and attach the following policies to it
- ComprehendReadOnly
- AmazonSNSFullAccess
- Open serverless.template file and update the Role attribute with the ARN of the IAM Policy you created in the previous step
- Build and make sure there are no build errors
- Right click on the project name and select Publish to AWS Lambda... from the context menu
- Make sure the value for ShouldCreateSNSTopic is set to true when you run the template for the first time and publish
- Once completed successfully, you should be able to see a setup similar to this on the AWS Lambda console
- Navigate to SNS home page on the AWS Console, you should be able to see a new topic called CommentNotifier there
- Create a new email subscription to the topic and set it up to receive emails
- In your project, open CommentsController.cs and update the TargetArn property with the ARN of the CommentNotifier topic from the AWS Console
- Publish the template once again
- You should be able to invoke the Lambda through the API Gateway using Postman or similar tools. If you send a negative text, the Lambda will sense it through AWS Comprehend and send you a notification through SNS
Once you have edited your template and code you can use the following command lines to deploy your application from the command line (these examples assume the project name is CommentsAPI):
Restore dependencies
cd "CommentsAPI"
dotnet restore
Execute unit tests
cd "CommentsAPI/test/CommentsAPI.Tests"
dotnet test
Deploy application
cd "CommentsAPI/src/CommentsAPI"
dotnet lambda deploy-serverless