AI Content Moderation

Purpose and Background

Amazon Rekognition leverages scalable deep learning technology in order to perform image and video analysis without machine learning expertise. Rekognition can be used to detect images that are suggestive or visually disturbing, indicate violence, or contain explict nudity for content moderation.

Curently, Unishop users can upload any image when adding a unicorn to the inventory. We want to moderate the content that appears in our inventory in order to prevent inappropriate or sensitive images from appearing on our website.


  • Environment Setup
  • Facade Configuration
  • Containerized Inventory Service

Implement Content Moderation using AWS Rekognition

Following the repository/service pattern, we have pre-created the RekognitionService interface and the RekognitionService class. However, we have not implemented the Rekognition logic.

  1. Go to your developer desktop. In the Solution Explorer of Visual Studio, right click the “InventoryService” project and select “Manage NuGet Packages”.

    Manage NuGet Packages

  2. At the top, select the “Browse” tab. Search for Rekognition, click “AWSSDK.Rekognition”, and then click “Install”. A pop-up wil appear telling you that you are about to make changes to the solution. Click “OK”.

    Add Rekognition NuGet Package

    Solution Changes Pop-Up

  3. In the Solution Explorer, expand the “Service” folder and open the “RekognitionService.cs” file.

    Open RekognitionService.cs File

  4. Uncomment the following using statements to the top of the “RekognitionService.cs” file:

    Uncomment RekognitionService.cs Header

    Uncomment the definition of “GetContentModerationLabels()” function:

    Uncomment RekognitionService.cs Method

  5. In the Solution Explorer, expand the “Controllers” folder, and open UnicornController.cs. Scroll down to the “CreateUnicorn()” function, and uncomment the function call to the “GetContentModerationLabels()” function that you just visited in last step.

    Uncomment rekognition function call

Redepoloy the modified inventory service to ECS

  1. Rebuild the project before you redeploy the inventory service. Make sure the build succeed.


  2. Redeployment will be largely the same with the deployment process in the part 1 of Containerized Inventory Service. In the solution explorer, right-click the “InventoryService” and select “Publish Container to AWS…” In the wizard, simply click “Next” through the entire interaction since the settings have been saved.

    Choose publish

    After the redeployment, you may notice that the tasks you deployed in previous steps and created by auto-scaling are not instantly stopped. This is because the previous version will be retained for some time before being stopped in the process of updating.

Enable HTTP proxy integration for POST

By default, API Gateway will always return 200 to the frontend even if it receives a 500 response from the backend. To disable this, we need to enable HTTP proxy integration for the POST method under “/unicorn” resource. When you tick this option, API Gateway will send the response from the backend directly to the frontend without any processing.

  1. In your AWS Management Console, navigate to the API Gateway.

  2. Click the POST method under “/unicorn” and click “Integration Request.”

    enable integration for Post

  3. Tick “Use HTTP Proxy integration.”

    tick http proxy inte

Test Content Moderation

  1. Save this image on your developer desktop:

    Rekognition Gun

  2. In your developer desktop, open a browser and direct yourself to app.unishop.local. Log in and click the “Upload” button in the top nav bar.

    Upload Unicorn Action

  3. We will try uploading a gun to our inventory. Enter the following:

    • Unicorn name: Enter UnicornGun

    • Description: Enter a unicorn gun

    • Price: Enter 100

    • Upload Image: Select the image of the gun you downloaded.

    Upload Unicorn Configuration

  4. Click “Upload”. As you can see, you were not able add this unicorn to the inventory as Rekognition detected “Violence” in the uploaded image.

    Upload Unicorn Result