Understanding the different components of the image recognition application– Programmatic Approach to IaC with AWS CDK

In addition to using Amazon Rekognition under the hood, our test application also depends on a few others to offer an end-to-end workflow for the user. Here is a list of all the components and the role they play:

  • S3 bucket: This is the end user interfacethat can be used for interacting with the application. Once a JPEG image has been uploaded into this bucket, it starts the application workflow for automatic labeling.
  • Event integrations: The S3 service offers event integrations with three other services – Lambda, SQS, and SNS. In this application, we use the Lambda integration, which is automatically invoked as soon as a new object appears.
  • Lambda function: This is the image handlerthat orchestrates all the activities in the application, from monitoring the object upload process to triggering Amazon Rekognition with appropriate inputs, and finally persisting the results in a DynamoDB table.
  • Amazon Rekognition: This is a fully managed image and video analysis tool that uses machine learning models under the hood, but offers a simple HTTP-based API to the user for easier consumption.
  • DynamoDB table: This is the persistence layer of the application and is where all the image labeling results are finally stored.

The entire workflow is depicted in Figure 6.2:

Figure 6.2 – Automatic image labeling with Amazon Rekognition

The advantage of working with toolkits such as AWS CDK is that lot of plumbing and glue code is automatically done for the user, with the least effort, as opposed to the code you would end up writing when working with services such as AWS CloudFormation. We will see a synthesized version of our template that will better explain this point shortly.

From a functional standpoint, the following stages are happening in the workflow depicted in Figure 6.2:

  1. The end user uploads a file into an S3 bucket. I have tried to keep several aspects of this test application simple to demonstrate the capabilities of CDK. As an alternative approach, you could abstract this piece with a web-based UI, where a user drags and drops an image into a defined section of the page, thereby initiating the analysis process.
  2. Once the image has been uploaded, the S3 service generates a notification; this is frequently leveraged in event-driven architectures. You can forward these events to several destinations, such as an SNS topic, SQS queue, or Lambda function.
  3. The Lambda integration is used to invoke a function that would have been deployed already as part of our CDK stack.
  4. The Lambda function delegates the image labeling task to Amazon Rekognition. Rekognition utilizes the underlying machine learning models to come up with a visual analysis categorization and confidence score and returns the response to the Lambda function.
  5. To persist the results of the analysis, the Lambda function stores the information in a DynamoDB table for future use.

Next, let’s start with some hands-on deployment activities for provisioning the previously discussed stack using CDK.

Note For the sake of simplicity, some of the steps (commands or code) from the following sections have already been completed for you, inside the chapter-6/ directory, inside your Cloud9 IDE. You will find a note, just like the one that you are reading now, in the relevant sections asking you to skip the command execution or the code definitions.

Leave a Comment