Lookout Part 2 - Configure the AWS stack with CloudFormation
This post describes how to deploy the AWS stack for Lookout. The instructions are based on the AWS Serverless Application Model (SAM) and AWS cli. While you could build out the components manually, I highly recommend taking the time to set up SAM + AWS cli.
Requirements
- An AWS account and your administrator credentials
- AWS cli - https://github.com/aws/aws-cli
- AWS sam local - https://github.com/awslabs/aws-sam-local
- boto3 -
pip3 install boto3
- An S3 bucket for CloudFormation deployment use (create in the region you wish to deploy to)
Adding Images for Facial Recognition
The Lookout stack contains a lambda to build a Rekognition collection from face images in S3. The solution contains one test image used to demonstrate the solution. You can add your own face crops to S3 to be included in the index.
Deploy with Makefile
If your system supports make you can use the supplied Makefile to simplify the process:
- Clone the lookout repo.
git clone https://github.com/2412labs/lookout.git cd lookout
- (Optional) - add your own face images to
lookout/img/faces
for indexing. - Edit the Makefile (
vi Makefile
) and update these variables with your S3 bucket and region:BUCKET := YOUR-BUCKET REGION := us-east-1
- Run the release target - this will package, deploy, copy test images and faces, and index faces from img/faces (you can add your own jpg files to this folder for facial recognition and announce by name):
make release
- If the deploy failed, review the cli output and the stack log within the AWS console (services -> management tools -> cloudformation).
- The deploy will print some stack output values similar to the following - save these for future use:
Deploy with shell commands
Use this method if your system doesn’t have make or you want to understand what each command does.
- Clone the lookout repo.
git clone https://github.com/2412labs/lookout.git cd lookout
- (Optional) - add your own face images to
lookout/img/faces
for indexing. - Package the stack artifacts. Substitute your own values for YOUR-BUCKET and YOUR-REGION.
sam package --template-file template.yml --output-template-file project.yml --s3-bucket YOUR-BUCKET --region YOUR-REGION
- Deploy the artifacts. This step actually builds each component in AWS and make take a few minutes.
sam deploy --template-file project.yml --stack-name lookout --capabilities CAPABILITY_NAMED_IAM --region YOUR-REGION
- If the deploy failed, review the cli output and the stack log within the AWS console (services -> management tools -> cloudformation).
- Use the AWS cli to get stack output variables. Save these values for future steps.
aws cloudformation describe-stacks --stack-name lookout --query "Stacks[0].Outputs" --region YOUR-REGION
- That’s it, the full aws solution is deployed! Now lets do a couple things from the cli to set up data for testing. You need the values for “S3BucketName” and “IndexFaces” output keys from the previous step.
aws s3 sync img/ s3://S3BucketName_VALUE_HERE/img/ aws lambda invoke --invocation-type RequestResponse --payload '{}' \ --region YOUR-REGION --function-name IndexFaces_VALUE_HERE /dev/stdout
Related Posts
- Lookout, an AWS Rekognition Enabled Smart Camera
- this post » Lookout Part 2 - Configure the AWS stack with CloudFormation
- Lookout Part 3 - Testing the Lookout Application Stack
- Lookout Part 4 - Configure the Raspberry Pi Camera
- Lookout Part 5 - Configure the Raspberry Pi Notifier