Giter VIP home page Giter VIP logo

appsync-image-rekognition's Introduction

AppSync Image Rekognition

React app for AI image facial recognition processing.

Getting started

  1. Clone the project & change into the new directory
git clone https://github.com/dabit3/appsync-image-rekognition.git

cd appsync-image-rekognition
  1. Install dependencies
npm install
  1. Initialize a new AWS Amplify project
amplify init
  1. Add auth, storage, & AppSync services
amplify add auth

amplify add api

amplify add storage

amplify add function

amplify push
  1. Update the AppSync Schema in your dashboard to the following:
type ImageData {
	data: String!
}

type Query {
	fetchImage(imageInfo: String!): ImageData
}
  1. Add the new Lambda function as a data source in the AppSync API Datasources section.

  2. Update the fetchImage resolver data source to use the new Lambda function as the datasource. Update the fetchImage resolver to the following:

Request mapping template
{
    "version" : "2017-02-28",
    "operation": "Invoke",
    "payload": $util.toJson($context.args)
}
Response mapping template
$util.toJson($context.result)
  1. Update the Lambda function code to the following (make sure to replace the bucket name with your bucket name):
const AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'})
var rekognition = new AWS.Rekognition()

exports.handler = (event, context, callback) => {
  var params = {
    Image: {
      S3Object: {
      Bucket: "<YOURBUCKETNAME>", 
      Name: "public/" + event.imageInfo
      }
    }, 
    Attributes: [
      'ALL'
    ]
  };
 
  rekognition.detectFaces(params, function(err, data) {
   if (err) {
    callback(null, {
     data: JSON.stringify(err.stack)
    })
   } else {
    const myData = JSON.stringify(data)
    callback(null, {
        data: myData
    })
   }
 });
};
  1. Add permissions to Lambda role for Rekognition as well as S3

Your final exports file should look something like this:

const config =  {
    'aws_appsync_graphqlEndpoint': 'https://yourendpoint',
    'aws_appsync_region': 'us-east-2',
    'aws_appsync_authenticationType': 'API_KEY',
    'aws_appsync_apiKey': 'APIKEY',
    'aws_user_pools': 'enable',
    'aws_cognito_region': 'us-east-2',
    'aws_user_pools_id': 'us-east-2_YOURID',
    'aws_user_pools_web_client_id': 'YOURCLIENTID',
    'aws_cognito_identity_pool_id': 'us-east-2:YOURID',
    'aws_user_files_s3_bucket': 'YOURBUCKETNAME',
    'aws_user_files_s3_bucket_region': 'us-east-1'
  }

  export default config

appsync-image-rekognition's People

Contributors

dabit3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.