top of page
  • Writer's picturevP

AWS Project Integration Guide - Day 96

Greetings readers! We've reached the last phase of our #100DaysOfAWS journey, and it's time to roll up our sleeves for a hands-on experience. Today, we're not just talking; we're doing. Today we will work on a sample project that brings together the symphony of various AWS services.


The Project Blueprint:

Our project is simple yet powerful. We'll create a serverless application that allows users to upload images, performs image recognition using Amazon Rekognition, stores the results in DynamoDB, and notifies the user through Amazon SNS. It's a blend of AWS services working in harmony.


Step 1: Set Up an S3 Bucket for Image Uploads

Let's kick things off by creating an S3 bucket to store our users' uploaded images. Follow these steps:

aws s3api create-bucket --bucket your-unique-bucket-name --region your-preferred-region

Step 2: Design a Lambda Function for Image Recognition

Now, let's create a Lambda function that triggers image recognition using Amazon Rekognition when a new image is uploaded. Here's a basic function:

import boto3

def lambda_handler(event, context):
    s3 = boto3.client('s3')
    rekognition = boto3.client('rekognition')

    # Get the uploaded image details
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = event['Records'][0]['s3']['object']['key']

    # Perform image recognition
    response = rekognition.detect_labels(
        Image={
            'S3Object': {
                'Bucket': bucket,
                'Name': key
            }
        }
    )

    # Process the recognition results
    # Add your logic here

    return {
        'statusCode': 200,
        'body': 'Image recognition complete!'
    }

Step 3: Configure DynamoDB for Storing Results

Let's set up a DynamoDB table to store the results of our image recognition. Use the AWS Management Console or the AWS CLI:

aws dynamodb create-table --table-name ImageRecognitionResults \
--attribute-definitions AttributeName=ImageID,AttributeType=S \
--key-schema AttributeName=ImageID,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--region your-preferred-region

Step 4: Extend Lambda Function to Store Results

Enhance our Lambda function to store image recognition results in DynamoDB:

import boto3

def lambda_handler(event, context):
    s3 = boto3.client('s3')
    rekognition = boto3.client('rekognition')
    dynamodb = boto3.client('dynamodb')
   
    # Get the uploaded image details
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = event['Records'][0]['s3']['object']['key']
   
    # Perform image recognition
    response = rekognition.detect_labels(
        Image={
            'S3Object': {
                'Bucket': bucket,
                'Name': key
            }
        }
    )
  
    # Store the results in DynamoDB
    dynamodb.put_item(
        TableName='ImageRecognitionResults',
        Item={
            'ImageID': {'S': key},
            'Labels': {'SS': response['Labels']}
        }
    )
    return {
        'statusCode': 200,
        'body': 'Image recognition results stored in DynamoDB!'
    }

Step 5: Implement SNS for User Notification

Lastly, let's set up an SNS topic to notify users when the image recognition is complete. Use the AWS Management Console or the AWS CLI:

aws sns create-topic --name ImageRecognitionTopic --region your-preferred-region

Congratulations! You've just orchestrated a harmonious collaboration between AWS services. This project showcases the seamless integration of S3, Lambda, Rekognition, DynamoDB, and SNS. The beauty lies in how these services, like instruments in an orchestra, work together to create a symphony of functionality.


In our final day, we'll reflect on the journey, celebrate our accomplishments, and look forward to the boundless possibilities that AWS offers.


Thank you for reading!


*** Explore | Share | Grow ***

13 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page