Skip to content

Commit 77147c8

Browse files
author
Davide Gallitelli
committed
Initial commit
1 parent 8c4db19 commit 77147c8

24 files changed

+852
-17
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Contributing Guidelines
23

34
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional

LICENSE

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
MIT No Attribution
22

3-
Permission is hereby granted, free of charge, to any person obtaining a copy of
4-
this software and associated documentation files (the "Software"), to deal in
5-
the Software without restriction, including without limitation the rights to
6-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7-
the Software, and to permit persons to whom the Software is furnished to do so.
3+
Copyright (c) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
84

9-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
software and associated documentation files (the "Software"), to deal in the Software
7+
without restriction, including without limitation the rights to use, copy, modify,
8+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so.
1510

11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
13+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
14+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,108 @@
1-
## My Project
1+
# rekognition-video-face-blur-cdk-app
22

3-
TODO: Fill this README out!
3+
## About
44

5-
Be sure to:
5+
This code sample demonstrates how AWS Step Functions can be used to orchestrate AWS Lambda functions that call Amazon Rekognition for face detections, and use OpenCV to blur these detections per frame in the video. Customers can use Amazon Rekognition to enforce privacy/anonymity in videos.
66

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
7+
Original video frame | Blurred video image
8+
:-------------------------:|:-------------------------:
9+
![input](images/input.gif) | ![output](images/output.gif)
10+
11+
### Architecture
12+
13+
This code sample demonstrates how AWS Step Functions can be used to orchestrate AWS Lambda functions that call Amazon Rekognition for face detections, and use OpenCV to blur these detections per frame in the video.
14+
15+
![rekognition-video-face-blur-cdk-app Architecture](images/rekognition-video-face-blur-cdk-app.png)
16+
17+
### Container image support in AWS Lambda
18+
Providing your serverless functions access to OpenCV is easier than ever with [Container Image Support](https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/). Instead of uploading a code package to AWS Lambda, your function's code instead resides in a Docker image that is hosted in [Amazon Elastic Container Registry](https://aws.amazon.com/ecr/).
19+
20+
```dockerfile
21+
FROM public.ecr.aws/lambda/python:3.7
22+
# Install the function's dependencies
23+
# Copy file requirements.txt from your project folder and install
24+
# the requirements in the app directory.
25+
COPY requirements.txt .
26+
RUN pip install -r requirements.txt
27+
# Copy helper functions
28+
COPY video_processor.py video_processor.py
29+
# Copy handler function (from the local app directory)
30+
COPY app.py .
31+
# Overwrite the command by providing a different command directly in the template.
32+
CMD ["app.lambda_function"]
33+
```
34+
35+
### Project structure
36+
37+
This project contains source code and supporting files for a serverless application that you can deploy with the AWS CDK. It includes the following files and folders.
38+
39+
- rekognition_video_face_blurring_cdk/ - CDK python code for deploying the application
40+
- rekopoc-apply-faces-to-video-docker/ - Code for Lambda function: uses OpenCV to blur faces per frame in video, uploads final result to output S3 bucket.
41+
- rekopoc-check-status/ - Code for Lambda function: Gets face detection results for the Amazon Rekognition Video analysis.
42+
- rekopoc-get-timestamps-faces/ - Code for Lambda function: Gets bounding boxes of detected faces and associated timestamps.
43+
- rekopoc-start-face-detect/ - Code for Lambda function: is triggered by a S3 event when a new .mp4 or .mov video file is uploaded, starts asynchronous detection of faces in a stored video and starts the execution of AWS Step Functions' State Machine.
44+
- requirements.txt - Required packages for deploying the AWS CDK application
45+
46+
The application uses several AWS resources, including AWS Step Functions, Lambda functions and S3 buckets. These resources are defined in the `rekognition_video_face_blurring_cdk_stack.py` that resides inside the rekognition_video_face_blurring_cdk folder in this project. You can update the python code to add AWS resources through the same deployment process that updates your application code.
47+
### AWS Step Functions workflow
48+
AWS Step Functions is a low-code visual workflow service used to orchestrate AWS services, automate business processes, and build serverless applications.
49+
In this code sample, AWS Step Functions is used to orchestrate the calls and manage the flow of data between AWS Lambda functions. The AWS Step Functions workflow for this application consists of AWS Lambda functions SFN states as well as Choice, Wait, Fail and Succeed SFN states.
50+
51+
AWS Step Functions Workflow | AWS Step Functions (SFN) States
52+
:-------------------------:|:-------------------------:
53+
![rekognition-video-face-blur-cdk-app Step Functions Workflow](images/rekognition-video-face-blur-cdk-app-step-functions-graph.png) | ![rekognition-video-face-blur-cdk-app Step Functions Workflow](images/rekognition-video-face-blur-cdk-app-step-functions-graph-details.png)
54+
55+
## Deploy the sample application
56+
57+
### Deploy the AWS CDK application
58+
The AWS Cloud Development Kit (AWS CDK) is an open source software development framework to define your cloud application resources using familiar programming languages. This project uses the AWS CDK in Python.
59+
60+
* AWS CDK - [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)
61+
* AWS CDK on GitHub - [AWS CDK on Github - Contribute!](https://github.com/aws/aws-cdk)
62+
* AWS CDK API Reference (for Python) - [AWS CDK Python API Reference](https://docs.aws.amazon.com/cdk/api/latest/python/modules.html)
63+
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
64+
65+
To build and deploy your application for the first time, ensure you have Docker running and have configured your AWS's credentials.
66+
The easiest way to satisfy this requirement is to issue the following command
67+
```bash
68+
aws configure
69+
```
70+
After you have finished with these steps, run the following in your shell:
71+
72+
```bash
73+
npm install -g aws-cdk
74+
pip install -r requirements.txt
75+
cdk bootstrap
76+
cdk deploy
77+
```
78+
79+
- The first command will install the AWS CDK Toolkit globally using Node Package Manager.
80+
- The second command will install all the python packages needed by the AWS CDK using pip package manager.
81+
- The third command will provision initial resources that the AWS CDK needs to perform the deployment.
82+
These resources include an Amazon S3 bucket for storing files and IAM roles that grant permissions needed to perform deployments.
83+
- Finally, `cdk deploy` will deploy the stack.
84+
85+
86+
### Cleanup
87+
88+
To delete the sample application that you created, use the AWS CDK.
89+
```bash
90+
cdk destroy
91+
```
92+
93+
## Resources
94+
95+
See the [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) for an introduction to important AWS CDK concepts and description of how to install and configure the AWS CDK.
96+
97+
Next, you can browse the AWS Samples/AWS CDK repository on GitHub. These examples each provide a demonstration of a common service implementation, or infrastructure pattern that could be useful in your use of the CDK for building your own infrastructure: [AWS CDK Examples](https://github.com/aws-samples/aws-cdk-examples)
98+
99+
## Credits
100+
101+
* Adrian Rosebrock, Blur and anonymize faces with OpenCV and Python, PyImageSearch,
102+
https://www.pyimagesearch.com/2020/04/06/blur-and-anonymize-faces-with-opencv-and-python/,
103+
accessed on 3 August 2021
104+
* Jon Slominski, <a href=https://github.com/aws-samples/rekognition-face-blur-sam-app>aws-samples/rekognition-face-blur-sam-app</a>, accessed on 3 August 2021
105+
* Video by <a href="https://www.pexels.com/@pixabay?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels">Pixabay</a> from <a href="https://www.pexels.com/video/video-of-people-walking-855564/?utm_content=attributionCopyText&utm_medium=referral&utm_source=pexels">Pexels</a>
9106

10107
## Security
11108

app.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
import os
3+
4+
from aws_cdk import core as cdk
5+
6+
# For consistency with TypeScript code, `cdk` is the preferred import name for
7+
# the CDK's core module. The following line also imports it as `core` for use
8+
# with examples from the CDK Developer's Guide, which are in the process of
9+
# being updated to use `cdk`. You may delete this import if you don't need it.
10+
from aws_cdk import core
11+
12+
from stack.rekognition_video_face_blurring_cdk_stack import RekognitionVideoFaceBlurringCdkStack
13+
14+
15+
app = core.App()
16+
RekognitionVideoFaceBlurringCdkStack(app, "RekognitionVideoFaceBlurringCdkStack",
17+
# If you don't specify 'env', this stack will be environment-agnostic.
18+
# Account/Region-dependent features and context lookups will not work,
19+
# but a single synthesized template can be deployed anywhere.
20+
21+
# Uncomment the next line to specialize this stack for the AWS Account
22+
# and Region that are implied by the current CLI configuration.
23+
24+
#env=core.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')),
25+
26+
# Uncomment the next line if you know exactly what Account and Region you
27+
# want to deploy the stack to. */
28+
29+
#env=core.Environment(account='123456789012', region='us-east-1'),
30+
31+
# For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
32+
)
33+
34+
app.synth()

cdk.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"app": "python3 app.py",
3+
"context": {
4+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
5+
"@aws-cdk/core:enableStackNameDuplicates": "true",
6+
"aws-cdk:enableDiffNoFail": "true",
7+
"@aws-cdk/core:stackRelativeExports": "true",
8+
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
9+
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
10+
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
11+
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true,
12+
"@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount": true,
13+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
14+
"@aws-cdk/aws-efs:defaultEncryptionAtRest": true,
15+
"@aws-cdk/aws-lambda:recognizeVersionProps": true
16+
}
17+
}

images/input.gif

19.1 MB
Loading

images/output.gif

17.9 MB
Loading
Loading
Loading
73.5 KB
Loading

requirements.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
attrs==20.3.0
2+
aws-cdk.assets==1.116.0
3+
aws-cdk.aws-apigateway==1.116.0
4+
aws-cdk.aws-applicationautoscaling==1.116.0
5+
aws-cdk.aws-autoscaling==1.116.0
6+
aws-cdk.aws-autoscaling-common==1.116.0
7+
aws-cdk.aws-autoscaling-hooktargets==1.116.0
8+
aws-cdk.aws-certificatemanager==1.116.0
9+
aws-cdk.aws-cloudformation==1.116.0
10+
aws-cdk.aws-cloudfront==1.116.0
11+
aws-cdk.aws-cloudwatch==1.116.0
12+
aws-cdk.aws-codebuild==1.116.0
13+
aws-cdk.aws-codecommit==1.116.0
14+
aws-cdk.aws-codeguruprofiler==1.116.0
15+
aws-cdk.aws-codestarnotifications==1.116.0
16+
aws-cdk.aws-cognito==1.116.0
17+
aws-cdk.aws-dynamodb==1.116.0
18+
aws-cdk.aws-ec2==1.116.0
19+
aws-cdk.aws-ecr==1.116.0
20+
aws-cdk.aws-ecr-assets==1.116.0
21+
aws-cdk.aws-ecs==1.116.0
22+
aws-cdk.aws-efs==1.116.0
23+
aws-cdk.aws-eks==1.116.0
24+
aws-cdk.aws-elasticloadbalancing==1.116.0
25+
aws-cdk.aws-elasticloadbalancingv2==1.116.0
26+
aws-cdk.aws-events==1.116.0
27+
aws-cdk.aws-globalaccelerator==1.116.0
28+
aws-cdk.aws-iam==1.116.0
29+
aws-cdk.aws-kinesis==1.116.0
30+
aws-cdk.aws-kms==1.116.0
31+
aws-cdk.aws-lambda==1.116.0
32+
aws-cdk.aws-lambda-event-sources==1.116.0
33+
aws-cdk.aws-logs==1.116.0
34+
aws-cdk.aws-route53==1.116.0
35+
aws-cdk.aws-route53-targets==1.116.0
36+
aws-cdk.aws-s3==1.116.0
37+
aws-cdk.aws-s3-assets==1.116.0
38+
aws-cdk.aws-s3-notifications==1.116.0
39+
aws-cdk.aws-sam==1.116.0
40+
aws-cdk.aws-secretsmanager==1.116.0
41+
aws-cdk.aws-servicediscovery==1.116.0
42+
aws-cdk.aws-signer==1.116.0
43+
aws-cdk.aws-sns==1.116.0
44+
aws-cdk.aws-sns-subscriptions==1.116.0
45+
aws-cdk.aws-sqs==1.116.0
46+
aws-cdk.aws-ssm==1.116.0
47+
aws-cdk.aws-stepfunctions==1.116.0
48+
aws-cdk.aws-stepfunctions-tasks==1.116.0
49+
aws-cdk.cloud-assembly-schema==1.116.0
50+
aws-cdk.core==1.116.0
51+
aws-cdk.custom-resources==1.116.0
52+
aws-cdk.cx-api==1.116.0
53+
aws-cdk.lambda-layer-awscli==1.116.0
54+
aws-cdk.lambda-layer-kubectl==1.116.0
55+
aws-cdk.region-info==1.116.0
56+
awscli==1.20.12
57+
boto3==1.18.12
58+
botocore==1.21.12
59+
cattrs==1.6.0
60+
colorama==0.4.3
61+
constructs==3.3.112
62+
docutils==0.15.2
63+
jmespath==0.10.0
64+
jsii==1.32.0
65+
numpy==1.21.1
66+
publication==0.0.3
67+
pyasn1==0.4.8
68+
python-dateutil==2.8.2
69+
PyYAML==5.4.1
70+
rsa==4.7.2
71+
s3transfer==0.5.0
72+
six==1.16.0
73+
typing-extensions==3.10.0.0
74+
urllib3==1.26.6

setup.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import setuptools
2+
3+
4+
with open("README.md") as fp:
5+
long_description = fp.read()
6+
7+
8+
setuptools.setup(
9+
name="rekognition_video_face_blurring_cdk",
10+
version="0.0.1",
11+
12+
description="An empty CDK Python app",
13+
long_description=long_description,
14+
long_description_content_type="text/markdown",
15+
16+
author="author",
17+
18+
package_dir={"": "rekognition_video_face_blurring_cdk"},
19+
packages=setuptools.find_packages(where="rekognition_video_face_blurring_cdk"),
20+
21+
install_requires=[
22+
"aws-cdk.core==1.110.1",
23+
],
24+
25+
python_requires=">=3.6",
26+
27+
classifiers=[
28+
"Development Status :: 4 - Beta",
29+
30+
"Intended Audience :: Developers",
31+
32+
"Programming Language :: JavaScript",
33+
"Programming Language :: Python :: 3 :: Only",
34+
"Programming Language :: Python :: 3.6",
35+
"Programming Language :: Python :: 3.7",
36+
"Programming Language :: Python :: 3.8",
37+
38+
"Topic :: Software Development :: Code Generators",
39+
"Topic :: Utilities",
40+
41+
"Typing :: Typed",
42+
],
43+
)

stack/.DS_Store

6 KB
Binary file not shown.

stack/lambdas/.DS_Store

6 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM public.ecr.aws/lambda/python:3.7
2+
# Install the function's dependencies
3+
# Copy file requirements.txt from your project folder and install
4+
# the requirements in the app directory.
5+
6+
COPY requirements.txt .
7+
RUN pip install -r requirements.txt
8+
9+
# Copy helper functions
10+
COPY video_processor.py video_processor.py
11+
12+
# Copy handler function (from the local app directory)
13+
COPY app.py .
14+
15+
# Overwrite the command by providing a different command directly in the template.
16+
CMD ["app.lambda_function"]

0 commit comments

Comments
 (0)