Analyze object storage data using a serverless SQL query

Summary

This code pattern demonstrates how to deploy serverless functions that analyze user uploaded images using visual recognition, store the results in a cloud object storage bucket, and trigger an SQL query that aggregates the various image classes and tags.

Description

In this application, you first upload an image to a cloud object storage bucket, which triggers serverless functions to run visual recognition on the image and store the results into a different bucket. The storage of the results into that bucket triggers your SQL query to aggregate all of the stored image processing results, counting the various types of classes and tags found in all of the uploaded images.

When you have completed this code pattern, you will understand how to:

  • Set up a cloud object storage instance on IBM Cloud.
  • Set up an SQL query instance on IBM Cloud.
  • Create and deploy IBM Cloud Functions from a manifest.yaml file.
  • Access IBM Cloud Object Storage and IBM Cloud SQL Query from IBM Cloud Functions.
  • Create triggers that react to changes in your cloud object storage buckets.

Flow

serverless sql query architecture flow diagram

  1. A new image is uploaded to the Cloud Object Storage bucket.
  2. A trigger listening to the Cloud Object Storage bucket is fired.
  3. That trigger fires the visual recognition functions to run, which use the IBM Cloud Visual Recognition service to analyze the content of the image and then parse the results. Those parsed results are written back to Cloud Object Storage, in a new bucket.
  4. A trigger listening to that bucket is fired.
  5. That trigger fires the SQL query functions to run, which use the IBM Cloud SQL Query service to aggregate all of the visual recognition results stored in Cloud Object Storage.
  6. The results are stored in Cloud Object Storage.

Instructions

Ready to give it a try? See the README file for detailed instructions.

  1. Create required services on IBM Cloud.
  2. Log in and set up your IBM Cloud CLI with the Cloud Functions plugin.
  3. Create the required IAM policy for Cloud Functions to access Cloud Object Storage.
  4. Deploy the SQL Query and Cloud Object Storage packages.
  5. Bind the required service credentials to the Cloud Object Storage package.
  6. Create the required environment variables and deploy cloud functions.
  7. Try out your new actions.
Belinda Vennam