This project contains all necessary components and services for the Video Action Recognizer application.
Serverless Analysis Core
Implemented in Python, this component performs video analysis using TensorFlow and the Movinet kinetics-600 model. It operates as a serverless Fargate task within AWS ECS.
Upload Listener Lambda
A Python AWS Lambda function that responds to S3 'object put' events by initiating the Analysis Core ECS task to process the uploaded video file.
Serverless Backend
In development, this component will provide RESTful APIs, facilitating server-side interactions and integrations with AWS services.
UI
The user interface is built with TypeScript and React.js, allowing for video or GIF file uploads and presenting analysis results. (Under Development)
Infrastructure Code
Infrastructure as Code (IaC) managed through Terraform scripts automates the setup of the required AWS infrastructure.
Ensure the AWS CLI is installed and configured with an access key pair before beginning the deployment process.
Navigate to the infrastructure/init directory and create a terraform.tfvars file:
aws_region = "<AWS_REGION>"
terraform_state_bucket = "<TERRAFORM_STATE_BUCKET_NAME>"
lambda_bucket = "<LAMBDA_BUCKET_NAME>"
# Optional variables:
github_repo = "<GITHUB_REPO>" # e.g. bugfloyd/video-action-recognizer | if you need an IAM role to be assumed with GitHub WebIdentity
main_domain = "<MAIN_DOMAIN_NAME>" # e.g. example.com | if you want to use a custom domainInitialize Terraform:
terraform initDeploy the resources:
terraform plan -out init.tfplan
terraform apply "init.tfplan"Inside the init directory of infra directory:
./generate-cloudfront-key.sh [<AWS_PROFILE_NAME>]Navigate to the upload-listener directory:
cd upload-listenerPackage and deploy the Lambda function:
./deploy.sh --bucket <LAMBDA_BUCKET_NAME> [--profile <name>] [--region <value>]Obtain the uploaded function bundle SHA sum from the script output and use it in the Main Infrastructure section.
For each of backend modules build zip bundle and upload it to S3. Get the bundle SHA sum.
cd rest-backend
./deploy.sh --bucket <LAMBDA_BUCKET_NAME> --skip-infra-update true [--profile <name>] [--region <value>]Accepted values for module name argument are: users, files, results
Navigate to the infrastructure directory and create a backend configuration file backend_config.hcl:
bucket = "<TERRAFORM_STATE_BUCKET_NAME>"
region = "<AWS_REGION>"Create a terraform.tfvars file:
aws_region = "<AWS_REGION>"
input_bucket = "<INPUT_BUCKET_NAME>"
output_bucket = "<OUTPUT_BUCKET_NAME>"
lambda_bucket = "<LAMBDA_BUCKET_NAME>"
upload_listener_lambda_bundle_sha = "<UPLOAD_LISTENER_LAMBDA_BUNDLE_SHA>"
rest_backend_lambda_bundle_sha = "<REST_BACKEND_LAMBDA_BUNDLE_SHA>"
cognito_domain_prefix = "<AWS_COGNITO_DOMAIN_PREFIX>"
# Optional:
setup_vpn = true
main_domain_zone_id = "<MAIN_HOSTED_ZONE_ID>" # Obtained from init infra stepInitialize Terraform with the S3 backend:
terraform init -backend-config="backend_config.hcl"If you pass true for setup_vpn, you have to create a CA certificate and a key using OpenSSL and place them in infrastructure/vpn/vpn_ca.key and infrastructure/vpn/vpn_ca.pem.
Deploy the main infrastructure:
terraform plan -out main.tfplan
terraform apply "main.tfplan"Get api_gateway_id, cognito_user_pool_client_id, cognito_user_pool_domain, cognito_user_pool_id, and cognito_user_pool_resource_server_identifier from terraform output.
To view the state of deployed resources:
terraform state listBuild and push the Docker image:
aws ecr get-login-password --region <AWS_REGION> | \
docker login --username AWS --password-stdin \
<ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.comdocker buildx build --platform=linux/amd64 \
-t <ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/video-action-regognizer:latest \
.docker push <ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/video-action-regognizer:latestIn order to send requests to the deployed serverless RESTful API, you need to create the first admin user in AWS Cognito:
cd rest-backend
./init.sh --user-pool-id <value> --email <value> --given-name <value> --family-name <value> --password <value> [--profile <name>] [--region <value>]- Re-run the code to build and upload the lambda function.
- Replace the
*_lambda_bundle_shainterraform.tfvarswith the newly obtained SHA sum. - Apply the changes using Terraform:
terraform plan -out main.tfplan
terraform apply "main.tfplan"- For the rest backend lambda functions, re-deploy the API for
devstage from AWS console.
You can use AWS SAM to build and invoke backend lambda functions locally. You can find some mock event input in rest-backend/mock-events directory.
Go to one of the backend lambda functions’ directory and compile TypeScript and build the bundle:
cd rest-backend
npm run buildInvoke the lambda locally using AWS SAM CLI and the related mock event:
sam local invoke VarBackend \
-e mock-events/createUser.json \
--template template.yaml \
--parameter-overrides \
UserPoolId=<USER_POOL_ID>Upload a mp4 video or a gif file to S3 <INPUT_BUCKET_NAME> and see the analysis logs and results in CloudWatch.
For more information, see our API Reference.
We welcome contributions from the community. If you'd like to contribute, please fork the repository and make your changes, then create a pull request against the main branch.
Code released under the GNU GPL v3 License.