top of page
Image by Pascal Meier

Lambda Functions - Hosting Deep Learning apps on AWS (Stage 1): Creating a Serverless (react.js) app

As a follow up on a previous Case Study, how easy is it to host a large trained Deep Learning app on AWS ?


There are seemingly an abundance of different ways to do this, but besides cost, almost all run into difficulties around five major areas:


  1. the size of the model you are hosting

  2. the size of the dependencies required to run the inference process, the largest of which is likely to be TensorFlow.

  3. size limits around AWS tooling

  4. problematic routing between front-end, S3 and back end (python) code

  5. authentication between AWS services


Generative AI could probably give you the above information, and there are a few videos out there showing prompts for automated web app deployment via e.g. AutoGPT / GPT Agents. But we have not (yet) seen an end-end, multi-modal push button cloud deployment for a Deep Learning Full Stack GUI or an attempt to address a growing chorus of Explainable AI (XAI) concerns.


Below is the architecture and tooling we used for this:



There are a number of end to end sub-processes underpinning the six stages shown in this diagram, which we will walk through now. If you are following along, follow the steps carefully – environment-dependent errors may occur so we recommend using Genie AI to help with debugging / troubleshooting along the way.






1. Creating a Serverless (react.js) app on AWS


This stage is all about using a serverless boilerplate infrastructure-as-code template to get a basic react app up and running. Its not completely necessary to complete this stage but is recommended as the key deployment process and many of the integrations are replicated in the full deep learning model deployment.


There are six sub-processes:


i. Installing App Development Dependencies


Essentially this is node.js, npm and Visual Studio Code, if you don’t already have these installed:



Plus of course AWS Console access – if its your first time – lucky you, you should get create a Free Tier account: https://aws.amazon.com/free


ii. Clone Public Repo


As mentioned, we are using Serverless IaC to deploy to AWS Lambda. We need a template for this, which we recommend is first forked from this GitHub repo.


You can then create a local project folder in Visual Studio Code and clone your forked GitHub repo:


git clone [FORKED_REPO_URL]

iii. Install node serverless dependency & Run locally


Still in Visual Studio Code, cd inside your local project folder and install serverless with:


npm install -g serverless 

and check the local app is running successfully with


npm run start


iv. Set AWS Credentials


AWS Credentials and authentication is typically the number 1 reason an app deployment fails. First generate your IAM AWS access key and secret here, then set these inside your local project folder like this:


serverless config credentials --provider provider --key key --secret secret

v. Deploy app


This step is technically the last step in this first stage, but we recommend carrying it out before setting AWS Policies as the error messages shown are relatively helpful as to how to ensure all the correct AWS Roles and Policies have been setup.


Make sure you are still in your local project folder and deploy with:

npx sls deploy

The above command uses Serverless AWS CloudFormation template to provision AWS resources for your app. In the AWS Console, search for S3, then Lambda to check that an S3 bucket and a Lambda function have been provisioned


vi. AWS Policies


As mentioned in step 5, the first attempt at deploying is likely to raise an error – get familiar with these as they are (usually) relatively clear as to how to resolve. In summary, there are three steps, all configured via the AWS Console under IAM


• Define and attach IAM (CloudFormation) policy

• Define custom policy

• Attach new policy to user


Its recommended to do the above steps one by one and redeploy after each step, but on completion of the last step and redeploying as in step 5, you should now be presented with a url to your new app hosted on AWS Lambda


This completes the first (optional) stage of the overall process – as a refresher, or for more prescriptive steps, you can also take a look revisit our video series. Or click below to proceed to the next stage in the process.






6 views0 comments

Recent Posts

See All

Comments


bottom of page