Skip to content

aws-solutions/deepracer-on-aws

DeepRacer on AWS

Overview

DeepRacer on AWS is a solution that allows you to train and evaluate reinforcement learning models in a three-dimensional simulated autonomous-driving environment. The trained model can then be downloaded to a AWS DeepRacer vehicle (a 1/18th scale RC car capable of running inference on a trained AWS DeepRacer model for autonomous driving) so it can drive in a physical environment. You can also submit your model to a virtual race and have its performance ranked against other models in a virtual leaderboard.

Architecture

Deploying this solution with the default parameters deploys the following components in your AWS account.

Solution on AWS architecture

Components

  1. A user accesses the DeepRacer on AWS user interface through an Amazon CloudFront distribution, which delivers static web assets from the UI assets bucket and video streams from simulations.

  2. The user interface assets are hosted in an Amazon S3 bucket that stores the static web assets comprising the user interface.

  3. An Amazon Cognito user pool manages users and user group membership.

  4. An Amazon Cognito identity pool manages federation and authorization.

  5. AWS IAM user group roles define permissions and levels-of-access for each type of user in the system, used for access control and authorization.

  6. AWS Lambda registration hooks execute pre- and post-registration actions including adding new users to the default user group, handling admin profile creation, and more.

  7. AWS WAF provides intelligent protection for the API against common attack vectors and allows customers to define custom rules based on individual use cases and usage patterns.

  8. Amazon API Gateway routes API requests to their appropriate handler using a defined Smithy model.

  9. An AWS DynamoDB table serves as a single table for storing and managing profiles, training jobs, models, evaluation jobs, submissions, and leaderboards.

  10. AWS Lambda functions are triggered in response to requests routed from the API and are responsible for CRUD operations, dispatching training/evaluation jobs, and more.

  11. A global settings handler AWS Lambda function reads and writes application-level settings to the configuration.

  12. AWS AppConfig hosted configuration stores application-level settings, such as usage quotas.

  13. AWS Lambda model export functions retrieve the asset URL and package assets for use in exporting models from the system.

  14. An Amazon SQS dead-letter queue catches failed export jobs thrown from the asset packaging function.

  15. A virtual model bucket (Amazon S3) stores exported models and provides access to them via pre-signed URL.

  16. A model import AWS Lambda function receives requests to import a model onto the system and creates a new import job.

  17. Amazon SQS model import queues (queue and DLQ) receive jobs from the model import function and hold them until they are accepted by the dispatcher.

  18. A failed request handler AWS Lambda function handles failed requests and updates their status to reflect their current state.

  19. An import dispatcher AWS Lambda function takes a job from the queue and dispatches it to the workflow.

  20. A reward function validator AWS Lambda function checks the reward function and validates/sanitizes the customer-provided code before it is saved to the system.

  21. An import model validator AWS Lambda function checks and validates the imported model before it is saved to the system.

  22. An import model assets AWS Lambda function brings in model assets from the upload bucket.

  23. An import completion handler AWS Lambda function handles status updates when a job is completed successfully.

  24. An upload bucket (Amazon S3) stores uploaded (but not yet imported) assets from the user.

  25. An Amazon SQS FIFO queue receives requests for training and evaluation jobs and stores them in FIFO order.

  26. A job dispatcher AWS Lambda function picks a job off the top of the FIFO queue and dispatches it to the workflow.

  27. AWS Lambda workflow functions handle setting up the job, setting status, and other workflow tasks.

  28. Amazon SageMaker performs the actual training and evaluation of the model using the reward function and hyperparameters provided.

  29. Amazon Kinesis Video Streams handles presenting the simulation video to the user from the SageMaker training job.

  30. A user data bucket (Amazon S3) stores all user data including trained models, evaluation results, and other assets generated during the DeepRacer workflow.

  31. An Amazon DynamoDB Stream captures item-level changes from the main table and delivers them to downstream Lambda consumers, enabling event-driven orchestration of live race evaluations and real-time broadcast of race state to spectators.

  32. A AWS Lambda Broadcast Handler (LiveBroadcastHandler) is triggered by the DynamoDB stream and detects relevant state changes — such as evaluation started/completed, leaderboard updates, and winner declarations — and publishes corresponding events to the IoT Core MQTT topic for the active race, delivering real-time updates to connected spectator browsers.

  33. AWS IoT Core provides a managed WebSocket pub/sub channel for delivering live race state updates to spectator and participant browsers. Each live race uses a dedicated MQTT topic scoped by leaderboard ID. Spectators subscribe via WebSocket; the Broadcast Handler publishes via IAM-authorized HTTPS. IoT Core handles connection management, fan-out, and scaling without requiring a connections table or custom connect/disconnect handlers.

  34. AWS EventBridge Schedules triggers the SafetyNet Lambda whenever a live race Step Functions execution reaches a terminal state (succeeded, failed, aborted, or timed out), ensuring the execution lock is cleared and pending evaluations are retriggered without manual intervention.

  35. AWS Lambda Queue API Handlers are a set of Lambda functions that back the live race queue management endpoints. They handle facilitator operations including listing the queue, reordering submissions via fractional indexing, removing submissions, resetting in-progress or failed models, clearing the leaderboard, launching the live race, and declaring a winner.

  36. An AWS Lambda Attach IoT Policy function grants newly authenticated users the IoT Core policy required to subscribe to live race MQTT topics over WebSocket, enabling real-time race state delivery to their browser sessions.

  37. A AWS Lambda Stream Handler is triggered by the DynamoDB stream and is responsible for auto-starting a new Step Functions execution for a live race when one or more submissions with PENDING status exist in the queue, the race is IN_PROGRESS, autolaunch is enabled, and no execution is currently running. It acquires the execution lock via a conditional write before starting the execution.

  38. A AWS Lambda SafetyNet function is invoked by EventBridge when a live race Step Functions execution reaches any terminal state. It clears the execution lock with a conditional write, applies a backoff check if the execution has failed repeatedly, and touches a PENDING queue item to generate a DynamoDB stream event — retriggering the Stream Handler to start a new execution if items remain in the queue.

Package layout

  • The source code for the DeepRacer on AWS is located in ./source.

Repository structure

DeepRacer on AWS is structured as monorepo. See below for package layouts and intended contents.

┣ 📦 deployment
┃  ┗ 📂cdk-solution-helper                  Lightweight helper that cleans-up synthesized templates from the CDK
┗ 📦 source
   ┣ 📂apps                                 Applications - Code not imported/consumed outside of its own package
   ┃  ┣ 📂infra                             CDK application
   ┃  ┃  ┣ 📂bin
   ┃  ┃  ┃  ┗ 📜deepRacerIndy.ts            Main CDK app definition
   ┃  ┃  ┗ 📂lib
   ┃  ┃     ┣ 📂constructs                  CDK constructs
   ┃  ┃     ┗ 📂stacks                      CDK stacks
   ┃  ┗ 📂website                           Website application
   ┃     ┗ 📂src
   ┃        ┣ 📂assets                      Static assets (ie. images)
   ┃        ┣ 📂components                  React components re-used throughout the website
   ┃        ┣ 📂pages                       React components for individual website pages
   ┃        ┗ 📂utils                       Utils specific to the website application
   ┗ 📂libs                                 Libraries - Code consumed/imported by apps or other libraries
      ┣ 📂config                            Config package - App-wide configuration
      ┃  ┗ 📂src
      ┃     ┣ 📂configs                     Domain specific configurations
      ┃     ┣ 📂defaults                    Config default values
      ┃     ┗ 📂types                       Config definitions
      ┣ 📂database                          Database package - Database related implementation
      ┃  ┗ 📂src
      ┃     ┣ 📂constants                   Database constants
      ┃     ┣ 📂dao                         DAO implementations
      ┃     ┣ 📂entities                    ElectroDB entities
      ┃     ┗ 📂utils                       Database specific utils
      ┣ 📂lambda                            Lambda Package - lambda handlers
      ┃  ┗ 📂src
      ┃     ┣ 📂api                         API lambda code
      ┃     ┃  ┣ 📂handlers                 API lambda handler implementations
      ┃     ┃  ┣ 📂types                    API TypeScript types
      ┃     ┃  ┗ 📂utils                    API lambda utils
      ┃     ┣ 📂cognito                     Cognito lambda code
      ┃     ┗ 📂workflow                    Workflow lambda code
      ┣ 📂model                             Model package - API Smithy model
      ┃  ┗ 📂src
      ┃     ┗ 📂main
      ┃        ┗ 📂smithy
      ┃           ┣ 📂operations            Smithy definitions for API operations
      ┃           ┣ 📂types                 Smithy definitions for API types
      ┃           ┗ 📜main.smithy           Smithy API definition
      ┣ 📂typescript-client                 Auto-generated from model - API TypeScript client for website to consume
      ┣ 📂typescript-server-client          Auto-generated from model - API TypeScript client for API lambdas to consume
      ┗ 📂utils                             Utils package - App-wide utils

Deployment

You can launch this solution with one click from the solution home page:

Please ensure you test the templates before updating any production deployments.

Creating a custom build

To customize the solution, follow the steps below:

Prerequisites

Install Java

Follow the instructions for your platform here.

Install Node

It is recommended to manage node installations with a node version manager, such as nvm.

Install nvm

Run the nvm install script:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
Install Node v22

Install Node v22 using nvm:

nvm install 22

Select Node v22 as the version to use:

nvm use 22

Confirm that Node v22 is being used:

node --version

Install pnpm

pnpm is a javascript package manager that is faster and more efficient than npm.

Since v16.13, Node.js is shipping Corepack for managing package managers. This is an experimental feature, so you need to enable it by running:

corepack enable pnpm

Install Nx globally (optional)

Nx can be installed globally to remove the need to prefix nx commands with "pnpm" by running:

pnpm i -g nx

If you go this route, you can remove "pnpm" from any commands that run nx.

For example:

pnpm nx test database

becomes

nx test database

Download or clone this repo

git clone https://github.com/aws-solutions/deepracer-on-aws

Install dependencies

Install package dependencies by running the following from the monorepo root (source folder):

pnpm install

This will install package.json dependencies for all apps and libs in the monorepo, as well as shared dev dependencies from package.json in the monorepo root.

After introducing changes, run the unit tests to make sure the customizations don't break existing functionality

cd ./deployment
chmod +x ./run-unit-tests.sh
./run-unit-tests.sh

Build and deploy the solution using the accompanying build scripts

Define the following environment variables in your console session:

REGIONAL_ARTIFACT_BUCKET=my-bucket-name      # S3 bucket name prefix where customized regional code will reside
GLOBAL_ARTIFACT_BUCKET=my-bucket-name        # S3 bucket name where customized global code will reside
SOLUTION_NAME=my-solution-name               # customized solution name
VERSION=my-version                           # version number for the customized code

In order to compile the solution, the build-s3 will install the AWS CDK.

cd ./deployment
chmod +x ./build-s3-dist.sh
./build-s3-dist.sh $REGIONAL_ARTIFACT_BUCKET $SOLUTION_NAME $VERSION $GLOBAL_ARTIFACT_BUCKET

When creating the bucket for solution artifacts it is recommended to

  • Use randomized names as part of your bucket naming strategy.
  • Ensure buckets are not public.
  • Verify bucket ownership prior to uploading templates or code artifacts.

Note: The created bucket for regional artifacts must include the region in the bucket name (for example, mybucket-name-us-east-1).

aws s3 sync ./global-s3-assets s3://$GLOBAL_ARTIFACT_BUCKET/$SOLUTION_NAME/$VERSION --acl bucket-owner-full-control
aws s3 sync ./regional-s3-assets s3://$REGIONAL_ARTIFACT_BUCKET-us-east-1/$SOLUTION_NAME/$VERSION --acl bucket-owner-full-control

Launch the CloudFormation template

  • Get the link of the template uploaded to your Amazon S3 bucket (created as $REGIONAL_ARTIFACT_BUCKET in the previous step)
  • Deploy the solution to your account by launching a new AWS CloudFormation stack

Build and deploy the solution using CDK deploy

Set environment variables

  1. Provide a valid email address as the value for the ADMIN_EMAIL environment variable. This will be used to set up the initial admin profile.
export ADMIN_EMAIL='user@example.com'
  1. If you are deploying more than one instance of DeepRacer on AWS into the same account, provide a unique value for the NAMESPACE environment variable. This will help with labeling and separating the resources created by each deployment. It must use lowercase alphanumeric characters with a minimum length of 3 and a maximum length of 12.
export NAMESPACE='deepracer1'
  1. Choose which delivery method to use for sending authentication emails. DeepRacer on AWS supports both Amazon Cognito and Amazon SES as delivery methods. Amazon Cognito is the default delivery method and requires no prior service approval, but is better suited for low volume use cases due to its limit of 50 emails per day per account. Amazon SES is also supported for higher sending limits and custom sender addresses, but requires a verified email address and production status.

To use SES as the delivery method for authentication emails, follow the instructions in the Prerequisites section of the implementation guide on how to set up a verified sender email address and request production status. Then:

export EMAIL_DELIVERY_METHOD='SES'
export SES_VERIFIED_EMAIL='noreply@example.com'
  1. If you want to use a public image for the reward validation function (or private image with appropriate permissions)
export  PUBLIC_ECR_REGISTRY=${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com

Configuration

The solution uses CDK context values for container image configuration. These are defined in source/apps/infra/cdk.json and can be overridden during deployment:

Default context values:

  • PUBLIC_ECR_REGISTRY: "public.ecr.aws/aws-solutions"
  • MODEL_VALIDATION_REPO_NAME: "deepracer-on-aws-model-validation"
  • REWARD_VALIDATION_REPO_NAME: "deepracer-on-aws-reward-function-validation"
  • SIMAPP_REPO_NAME: "deepracer-on-aws-simapp"

Override context values during deployment:

pnpm nx deploy infra --context PUBLIC_ECR_REGISTRY=my-registry.com --context PUBLIC_ECR_REGISTRY=<PRIVATE_ECR_REPO>

Bootstrap CDK (if not already done)

If this is your first time using CDK in your AWS account and region, you need to bootstrap it:

cdk bootstrap aws://<account-id>/<region>

This creates the necessary resources for CDK deployments in your account.

Build

Run the build command from the source directory

pnpm build

Deploy

Deploy the infrastructure by running the following from the monorepo root (source folder).

pnpm nx deploy infra

Collection of Operational Metrics

This solution sends operational metrics to AWS (the “Data”) about the use of this solution. We use this Data to better understand how customers use this solution and related services and products. AWS’s collection of this Data is subject to the AWS Privacy Notice.


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

About

DeepRacer on AWS is the latest evolution of AWS DeepRacer, delivering a self-hosted reinforcement learning solution you can deploy to your AWS account to train and evaluate autonomous-driving models in a 3D simulated environment.

Resources

License

Code of conduct

Contributing

Security policy

Stars

20 stars

Watchers

4 watching

Forks

Packages

 
 
 

Contributors