Skip to content

sshvans/ddr

Repository files navigation

DDR

DDR Architecture

Pre-requisites

This project uses Amazon Rekognition and can be run in one of three regions:

  • US East (N. Virginia)
  • US West (Oregon)
  • EU (Ireland)

3 Lambda functions with Python 3.6 runtime are deployed as part of this project. The scripts are located in lambdas directory.

A cloudformation template: ddr.template has been provided to automate the server side infrastructure. The lambda scripts are uploaded as zip files and can be sourced only from S3 buckets in the same region.

[Optional] Create or re-use a key pair

You can re-use a pre-existing key pair in the region if you already have one. Command to generate a key pair is below.

aws ec2 create-key-pair --key-name ddr-pdx --query 'KeyMaterial' --output text > ~/.ssh/ddr-pdx.pem; chmod 600 ~/.ssh/ddr-pdx.pem

Up & Running

A helper script deploy_lambda_cfn.sh has been provided to automate the server setup. See testing.md for individual steps. The script expects three arguments, in this order:

  • region: has to be one of us-east-1, us-west-2, eu-west-1
  • key_name: name of existing imported key pair in the chosen region
  • lambda_assets_bucket: name of a new bucket to host lambda assets

The script creates the above named buckets, hosts all lambda assets in the bucket and then launches ddr.template cloudformation stack taking ddr_test_params.json file as input. The file contains three tokens for VPCID, KeyName, ArtifactBucket. The script chooses your default VPC and uses input values for the other two parameters. Please also note that it grants access from anywhere by having 0.0.0.0/0 in the RemoteAccessCIDR parameter. This is strictly for demo purpose and you should change this value to your IP for security. The parameters file can be modified to match your environment.

Run the deploy script

./deploy_lambda_cfn.sh <aws_region> <key_name> <new_assets_bucket>
# e.g. ./deploy_lambda_cfn.sh us-east-1 ddr-pdx my-ddr-assets-bucket

Run scripts on server

  1. After the above script has finished. Use the console or CLI to get the public ip of the instance launched. Substitute STACK_ID and REGION below.
   aws cloudformation describe-stacks --stack ${STACK_ID} --region ${REGION} \
   | jq '.[]|.[]|.Outputs|.[]|select(.OutputKey == "DdrEC2PublicIp")|.OutputValue'
  1. SSH to the EC2 server with the IP identified above ssh -i ddr-pdx.pem ubuntu@<34.236.149.123-REPLACE_THIS>

  2. Execute setup script and run server process

  • setup_bucket_notifications.sh - sets up notification events for s3 bucket and prepares ddr_config.props
  • run_server.sh runs three processes:
    • sqs_poller - Processes incoming files on S3 notified to SQS
    • ddr_runner - computes scores and runs rekognition commands
    • op_server - Openpose server running zeromq endpoint. Listens on incoming requests and processes images
   cd ~/ddr
   git pull
   cd scripts
   ./setup_bucket_notifications.sh
   ./run_server.sh
  1. Deploy webapp to created s3 webapp bucket
   cd ~/ddr
   ./deploy_webapp.sh

Raspberry PI

  • Follow instructions in ddr_raspi/README.md
  • It will create a S3 bucket
  • See instructions in section: Run ddr_camera.py

Final Testing

Ensure the following: