Tutorial source: https://aws.amazon.com/blogs/machine-learning/blur-faces-in-videos-automatically-with-amazon-rekognition-video/
Face blurring is one of the best-known practices when anonymizing both images and videos. We will implement an event-driven system for face blurring using composition of different Lambda functions and a state machine.
Here is the high level architecture:
Let’s get started.
* Deploy your resources in a region where Amazon Rekognition is supported.
Python 3.9
runtime function from scratch.face-blur-lambdas/face-detection/*.py
as the function source code (use the console code editor).AmazonS3FullAccess
, AmazonRekognitionFullAccess
and AWSStepFunctionsFullAccess
. It’s recommended to use the same IAM role for all functions!.mp4
suffix (create a bucket and enable event notification if needed).Python 3.9
runtime function from scratch. Choose the same IAM role as the above function.face-blur-lambdas/check-rekognition-job-status/lambda_function.py
as the function source code.Python 3.9
runtime function from scratch. Choose the same IAM role as the above function.face-blur-lambdas/get-rekognized-faces/lambda_function.py
as the function source code.Create a Container image Lambda function based on the Docker image built from face-blur-lambdas/blur-faces/Dockerfile
. Use an existing Docker image, or create an ECR and build the image by:
OUTPUT_BUCKET=<bucket-name>
where <bucket-name>
is another bucket to which the processes videos will be uploaded (create one if needed).face-blur-lambdas/state_machine.json
<check-rekognition-job-status ARN>
, <get-rekognized-faces ARN>
and <blur-faces ARN>
according to the corresponding Lambda functions ARN.STATE_MACHINE_ARN=<state-machine-ARN>
Enter the interactive self-check page
Open the IAM console at https://console.aws.amazon.com/iam/.
In the navigation pane, choose Roles, Create role.
On the Trusted entity type page, choose AWS service and the Lambda use case.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:<region>:<accountID>:function:<lambda-func-name>*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:<region>:<accountID>:*"
},
{
"Effect": "Allow",
"Action": [
"dynamodb:DescribeStream",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:ListStreams"
],
"Resource": "arn:aws:dynamodb:<region>:<accountID>:table/<dynamo-table-name>/stream/*"
},
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": [
"*"
]
}
]
}
Change the following placeholders to the appropriate values: <region>
, <accountID>
, <dynamo-table-name>
, <lambda-func-name>
The policy has four statements that allow your role to do the following:
Open the Functions page of the Lambda console.
Choose Create function.
Under Basic information, do the following:
Enter Function name.
For Runtime, confirm that Node.js 16.x is selected.
For Permissions use your created role.
dynamodb_lambda_func/publishNewSong.js
and paste it in the Code source. Change <TOPIC-ARN>
to your SNS topic ARN you created in the previous exercise.