2 min read

AWS Rekognition for 'rekognizing' images.

'Hello World' was the gentle dipping of the toe for learning programming, a baton picked up by image recognition for learning (or starting to learn) AI,

the AWS way.

First: The AWS Architecture.

Second: The Steps.

  • Create a bucket
I named mine 'rekognition2026'
  • Let ACLs be disabled because we will be using a policy to control access
  • Leave all other settings default.
  • Voila... you have an S3 bucket
  • Put a photo of your choice in the S3 bucket.
  • Create a lambda function using Python BUT before that, create the policy below and map it to a role. The function should be allowed to run under either an existing role (or you can create a new if you want).
  • The role you make (or edit) should have the following policies:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "DynamodbLimitedAccess",
            "Action": [
                "rekognition:Get*",
                "rekognition:List*",
                "rekognition:DetectLabels"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Sid": "SecretsManagerLimitedAccess",
            "Action": [
                "s3:Describe*",
                "s3:Get*",
                "s3:List*"
            ],
            "Resource": "*"
        }
    ]
}
  • Add the Python code below to the Lambda
import json
import boto3
def lambda_handler(event, context):
   
    bucket_name = "rekognition2026"
    image_obj_name = "Sample-png-image-1mb.png"

    try:
        rkClient = boto3.client("rekognition", region_name="us-east-1")
        try:
            rkResponse = rkClient.detect_labels(
                Image={
                    'S3Object': {
                        'Bucket': bucket_name,
                        'Name': image_obj_name
                    }
                },
            )
            print(rkResponse['Labels'])
            return rkResponse['Labels']
        except Exception as e:
            print("Get labels failed because ", e)
    except Exception as e:
        print("Client connection to Rekognition failed because ", e)
  • Deploy code
  • Test it
Labels assigned to image

I write to remember, and if, in the process, I can help someone learn about Containers, Orchestration (Docker Compose, Kubernetes), GitOps, DevSecOps, VR/AR, Architecture, and Data Management, that is just icing on the cake.