<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christian Nuss</title>
    <description>The latest articles on DEV Community by Christian Nuss (@cnuss).</description>
    <link>https://dev.to/cnuss</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F86419%2F3493745c-758b-460e-8db6-09ab0f1555c6.jpeg</url>
      <title>DEV Community: Christian Nuss</title>
      <link>https://dev.to/cnuss</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cnuss"/>
    <language>en</language>
    <item>
      <title>Deploy Hugging Face Models to AWS Lambda in 3 steps</title>
      <dc:creator>Christian Nuss</dc:creator>
      <pubDate>Tue, 26 Nov 2024 13:17:13 +0000</pubDate>
      <link>https://dev.to/cnuss/deploy-hugging-face-models-to-aws-lambda-in-3-steps-5f18</link>
      <guid>https://dev.to/cnuss/deploy-hugging-face-models-to-aws-lambda-in-3-steps-5f18</guid>
      <description>&lt;p&gt;Ever wanted to deploy a Hugging Face model to AWS Lambda but got stuck with container builds, cold starts, and model caching? Here's how to do it in under 5 minutes using &lt;a href="http://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;Scaffoldly&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create an EFS filesystem named &lt;code&gt;.cache&lt;/code&gt; in AWS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to AWS EFS Console&lt;/li&gt;
&lt;li&gt;Click "Create File System"&lt;/li&gt;
&lt;li&gt;Name it &lt;code&gt;.cache&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select any VPC (Scaffoldly will take care of the rest!)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create your app from the &lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/python-huggingface" rel="noopener noreferrer"&gt;&lt;code&gt;python-huggingface&lt;/code&gt;&lt;/a&gt; branch:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; npx scaffoldly create app &lt;span class="nt"&gt;--template&lt;/span&gt; python-huggingface
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Deploy it:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;my-app &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npx scaffoldly deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it! You'll get a Hugging Face model running on Lambda (using &lt;a href="https://huggingface.co/openai-community/gpt2" rel="noopener noreferrer"&gt;openai-community/gpt2&lt;/a&gt; as an example), complete with proper caching and container deployment.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Pro-Tip&lt;/strong&gt;: For the EFS setup, you can customize it down to a Single AZ in Burstable mode for even more cost savings. Scaffoldly will match the Lambda Function to the EFS's VPC, Subnets, and Security Group.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;✨ Check out the &lt;a href="https://mrrva4a2ncoydup72wocmha6l40xojwg.lambda-url.us-east-1.on.aws" rel="noopener noreferrer"&gt;Live Demo&lt;/a&gt; and the &lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/python-huggingface" rel="noopener noreferrer"&gt;example code&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Deploying ML models to AWS Lambda traditionally involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building and managing Docker containers&lt;/li&gt;
&lt;li&gt;Figuring out model caching and storage&lt;/li&gt;
&lt;li&gt;Dealing with Lambda's size limits&lt;/li&gt;
&lt;li&gt;Managing cold starts&lt;/li&gt;
&lt;li&gt;Setting up API endpoints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's a lot of infrastructure work when you just want to serve a model!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;Scaffoldly&lt;/a&gt; handles all this complexity with a simple configuration file. Here's a &lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/python-huggingface" rel="noopener noreferrer"&gt;complete application&lt;/a&gt; that serves a Hugging Face model (using &lt;a href="https://huggingface.co/openai-community/gpt2" rel="noopener noreferrer"&gt;openai-community/gpt2&lt;/a&gt; as an example):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;generator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;text-generation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;openai-community/gpt2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello_world&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, world,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;generated_text&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// requirements.txt
Flask ~= 3.0
gunicorn ~= 23.0
torch ~= 2.5
numpy ~= 2.1
transformers ~= 4.46
huggingface_hub[cli] ~= 0.26
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;scaffoldly.json&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python-huggingface"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"runtime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python:3.12"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"handler"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"localhost:8000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"app.py"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"packages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pip:requirements.txt"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"resources"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"arn::elasticfilesystem:::file-system/.cache"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"schedules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@immediately"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"huggingface-cli download openai-community/gpt2"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"gunicorn app:app"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"memorySize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;Scaffoldly&lt;/a&gt; does some clever things behind the scenes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Smart Container Building&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatically creates a Docker container optimized for Lambda&lt;/li&gt;
&lt;li&gt;Handles all Python dependencies including PyTorch&lt;/li&gt;
&lt;li&gt;Pushes to ECR without you writing any Docker commands&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Efficient Model Handling&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses Amazon EFS to cache the model files&lt;/li&gt;
&lt;li&gt;Pre-downloads models after deployment for faster cold starts&lt;/li&gt;
&lt;li&gt;Mounts the cache automatically in Lambda&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lambda-Ready Setup&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rus up a proper WSGI server (gunicorn)&lt;/li&gt;
&lt;li&gt;Creates a public Lambda Function URL&lt;/li&gt;
&lt;li&gt;Proxies Function URL requests to gunicorn&lt;/li&gt;
&lt;li&gt;Manages IAM roles and permissions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What &lt;code&gt;deploy&lt;/code&gt; looks like
&lt;/h2&gt;

&lt;p&gt;Here's output from a &lt;code&gt;npx scaffoldly deploy&lt;/code&gt; command I ran on this example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9w19p13sstmttzp13rlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9w19p13sstmttzp13rlm.png" alt=" raw `npx scaffoldly deploy` endraw  output" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Real World Performance &amp;amp; Costs
&lt;/h2&gt;

&lt;p&gt;✅ &lt;strong&gt;Costs&lt;/strong&gt;: ~$0.20/day for AWS Lambda, ECR, and EFS&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Cold Start&lt;/strong&gt;: ~20s for first request (model loading)&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Warm Requests&lt;/strong&gt;: 5-20s (CPU-based inference)  &lt;/p&gt;

&lt;p&gt;While this setup uses CPU inference (which is slower than GPU), it's an incredibly cost-effective way to experiment with ML models or serve low-traffic endpoints.&lt;/p&gt;
&lt;h2&gt;
  
  
  Customizing for Other Models
&lt;/h2&gt;

&lt;p&gt;Want to use a different model? Just update two files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Change the model in &lt;code&gt;app.py&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;generator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;text-generation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;your-model-here&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Update the download in &lt;code&gt;scaffoldly.json&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"schedules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"@immediately"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"huggingface-cli download your-model-here"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Using Private or Gated Models
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;Scaffoldly&lt;/a&gt; supports private and gated models via the &lt;code&gt;HF_TOKEN&lt;/code&gt; environment variable. You can add your Hugging Face token in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Development&lt;/strong&gt;: Add to your shell profile (&lt;code&gt;.bashrc&lt;/code&gt;, &lt;code&gt;.zprofile&lt;/code&gt;, etc.):
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;HF_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"hf_rH...A"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD&lt;/strong&gt;: Add as a GitHub Actions Secret:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# In your repository settings -&amp;gt; Secrets and Variables -&amp;gt; Actions&lt;/span&gt;
  &lt;span class="na"&gt;HF_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hf_rH...A&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The token will be automatically used for both downloading and accessing your private or gated models.&lt;/p&gt;
&lt;h2&gt;
  
  
  CI/CD Bonus
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;Scaffoldly&lt;/a&gt; even generates a GitHub Action for automated deployments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Scaffoldly Deploy&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;scaffoldly/scaffoldly@v1&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;secrets&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ toJSON(secrets) }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;p&gt;The complete example is available on GitHub:&lt;br&gt;
&lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/python-huggingface" rel="noopener noreferrer"&gt;scaffoldly/scaffoldly-examples#python-huggingface&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you can create your own copy of this example by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx scaffoldly create app --template python-huggingface
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see it running live (though responses might be slow due to CPU inference):&lt;br&gt;
&lt;a href="https://mrrva4a2ncoydup72wocmha6l40xojwg.lambda-url.us-east-1.on.aws" rel="noopener noreferrer"&gt;Live Demo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Try deploying different Hugging Face models&lt;/li&gt;
&lt;li&gt;Join the &lt;a href="https://scaffoldly.dev/community" rel="noopener noreferrer"&gt;Scaffoldly Community&lt;/a&gt; on Discord&lt;/li&gt;
&lt;li&gt;Check out &lt;a href="https://github.com/scaffoldly/scaffoldly-examples" rel="noopener noreferrer"&gt;other examples&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Star our repos if you found this useful!

&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;&lt;code&gt;scaffoldly&lt;/code&gt;&lt;/a&gt; toolchain&lt;/li&gt;
&lt;li&gt;The Scaffoldly &lt;a href="https://github.com/scaffoldly/scaffoldly-examples" rel="noopener noreferrer"&gt;Examples&lt;/a&gt; repository&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Licenses
&lt;/h2&gt;

&lt;p&gt;Scaffoldly is Open Source, and welcome contributions from the community.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://github.com/scaffoldly/scaffoldly-examples" rel="noopener noreferrer"&gt;examples&lt;/a&gt; are licensed with the &lt;a href="https://github.com/scaffoldly/scaffoldly-examples/blob/python-huggingface/LICENSE.md" rel="noopener noreferrer"&gt;Apache-2.0&lt;/a&gt; license.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;&lt;code&gt;scaffoldly&lt;/code&gt;&lt;/a&gt; toolchain is licensed with the &lt;a href="https://github.com/scaffoldly/scaffoldly?tab=License-1-ov-file" rel="noopener noreferrer"&gt;FSL-1.1-Apache-2.0&lt;/a&gt; license.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What other models do you want to run in AWS Lambda? Let me know in the comments!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>machinelearning</category>
      <category>serverless</category>
      <category>python</category>
    </item>
    <item>
      <title>Run Next.js in AWS Lambda</title>
      <dc:creator>Christian Nuss</dc:creator>
      <pubDate>Tue, 15 Oct 2024 13:12:59 +0000</pubDate>
      <link>https://dev.to/cnuss/run-nextjs-in-aws-lambda-5fca</link>
      <guid>https://dev.to/cnuss/run-nextjs-in-aws-lambda-5fca</guid>
      <description>&lt;p&gt;Want to run a serverless Next.js application in your own AWS Account? Use &lt;a href="https://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;&lt;code&gt;scaffoldly&lt;/code&gt;&lt;/a&gt; to build and deploy it!&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;See our &lt;a href="https://inne3tcyuarfqwqz633ojyg2qe0ldglc.lambda-url.us-east-1.on.aws/" rel="noopener noreferrer"&gt;working example&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;See the &lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/node-nextjs" rel="noopener noreferrer"&gt;example project&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⭐️ Please give Scaffoldly a &lt;a href="https://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;star&lt;/a&gt; on GitHub ⭐️&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: Create a Next.js project
&lt;/h2&gt;

&lt;p&gt;(If you haven't already!)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 1: Add &lt;code&gt;scaffoldly&lt;/code&gt; to &lt;code&gt;package.json&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json-doc"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node-nextjs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="c1"&gt;// ... snip ...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scaffoldly"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"runtime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node:22-alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"handler"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"localhost:3000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"services"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"package.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".next"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node_modules"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"package-lock.json"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"install"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm ci"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"next start"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;next build&lt;/code&gt; script generates the &lt;code&gt;.next&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;files&lt;/code&gt; lists any files/directories to include in the container&lt;/li&gt;
&lt;li&gt;Handling different &lt;code&gt;output&lt;/code&gt; types in &lt;code&gt;next.config.mjs&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/node-nextjs-standalone" rel="noopener noreferrer"&gt;&lt;code&gt;standalone&lt;/code&gt;&lt;/a&gt; mode&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/node-nextjs-export" rel="noopener noreferrer"&gt;&lt;code&gt;export&lt;/code&gt;&lt;/a&gt; mode&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Deploy to AWS Lambda using &lt;code&gt;scaffoldly&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx scaffoldly deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7wf1pucb2dsy0wn2ur8h.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7wf1pucb2dsy0wn2ur8h.gif" alt=" raw `scaffoldly deploy` endraw  output" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scaffoldly will manage or create:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IAM Roles&lt;/li&gt;
&lt;li&gt;ECR Repository&lt;/li&gt;
&lt;li&gt;Lambda Functions&lt;/li&gt;
&lt;li&gt;a Function URL&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;scaffoldly show dockerfile&lt;/code&gt; to show the generated &lt;code&gt;Dockerfile&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Check out our &lt;a href="https://scaffoldly.dev/docs" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;See our &lt;a href="https://inne3tcyuarfqwqz633ojyg2qe0ldglc.lambda-url.us-east-1.on.aws/" rel="noopener noreferrer"&gt;working example&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;See the &lt;a href="https://github.com/scaffoldly/scaffoldly-examples/tree/node-nextjs" rel="noopener noreferrer"&gt;example project&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Add our &lt;a href="https://scaffoldly.dev/docs/gha/" rel="noopener noreferrer"&gt;GitHub Action&lt;/a&gt; to automate your deploys&lt;/li&gt;
&lt;li&gt;Add a &lt;a href="https://scaffoldly.dev/docs/cloud/cdn/" rel="noopener noreferrer"&gt;Custom Domain&lt;/a&gt; to use a memorable URL&lt;/li&gt;
&lt;li&gt;Check out other &lt;a href="https://github.com/scaffoldly/scaffoldly-examples" rel="noopener noreferrer"&gt;frameworks&lt;/a&gt; that &lt;code&gt;scaffoldly&lt;/code&gt; supports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⭐️ Please give Scaffoldly a &lt;a href="https://github.com/scaffoldly/scaffoldly" rel="noopener noreferrer"&gt;star&lt;/a&gt; on GitHub ⭐️&lt;/p&gt;

&lt;h2&gt;
  
  
  About Scaffoldly
&lt;/h2&gt;

&lt;p&gt;At Scaffoldly, our mission is to empower developers by simplifying the deployment of modern web applications the Cloud. We strive to eliminate the complexities of cloud infrastructure, allowing you to focus on what you do best—building exceptional applications and APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our Vision
&lt;/h3&gt;

&lt;p&gt;We envision a development ecosystem where deploying to the cloud is as straightforward as running a local development server. By abstracting away the intricacies of cloud infrastructure, Scaffoldly aims to democratize cloud deployment, making it accessible and effortless for developers of all skill levels.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Scaffoldly Offers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unified Deployment CLI&lt;/strong&gt;: A single command-line tool that streamlines the deployment of both front-end, back-end, and full-stack applications to AWS Lambda.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seamless Framework Support&lt;/strong&gt;: Native support for modern frameworks like Next.js, Express, Flask, Golang, Rust without the need for complex configurations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Entrypoints&lt;/strong&gt;: Proprietary entrypoints that make Next.js and other applications compatible with AWS Lambda's environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Eliminated Complexity&lt;/strong&gt;: No more wrestling with Terraform scripts or CloudFormation templates—Scaffoldly handles infrastructure setup using AWS SDK calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker Integration&lt;/strong&gt;: Efficient packaging of applications into Docker containers, automated and managed within the Scaffoldly CLI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Learn more at &lt;a href="https://scaffoldly.dev" rel="noopener noreferrer"&gt;&lt;code&gt;scaffoldly.dev&lt;/code&gt;&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>lambda</category>
      <category>nextjs</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
