<?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: Lucas Tonelli</title>
    <description>The latest articles on DEV Community by Lucas Tonelli (@lucastonelli).</description>
    <link>https://dev.to/lucastonelli</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4117551%2F558f3bf2-550f-4113-a250-9d2b9dfdbb5b.jpeg</url>
      <title>DEV Community: Lucas Tonelli</title>
      <link>https://dev.to/lucastonelli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucastonelli"/>
    <language>en</language>
    <item>
      <title>Creating a Lambda deployment script</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/creating-a-lambda-deployment-script-2aoj</link>
      <guid>https://dev.to/lucastonelli/creating-a-lambda-deployment-script-2aoj</guid>
      <description>&lt;p&gt;You've got a Lambda running in production and a shiny new image sitting in ECR. The lazy move is to update the image URI, walk away, and hope for the best. The problem is that this swaps the code for everyone, instantly, with no safety net. If the new version is broken, congratulations, it's broken for 100% of your traffic before you even finish your coffee. What you might be looking for is to publish an immutable version, then shift traffic onto it in a controlled way, all from a single script and preferably in an automated manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  The script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-euo&lt;/span&gt; pipefail

aws lambda &lt;span class="nb"&gt;wait &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="nt"&gt;-updated-v2&lt;/span&gt; &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
aws lambda update-function-code &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--image-uri&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$3&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
aws lambda &lt;span class="nb"&gt;wait &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="nt"&gt;-updated-v2&lt;/span&gt; &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nv"&gt;PUBLISHED_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws lambda publish-version &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.Version'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

aws lambda &lt;span class="nb"&gt;wait &lt;/span&gt;published-version-active &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--qualifier&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PUBLISHED_VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nv"&gt;VERSIONS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws lambda list-versions-by-function &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;CURRENT_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws lambda get-alias &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; LIVE | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.FunctionVersion'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;TARGET_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$VERSIONS&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.Versions[-1].Version'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;APPSPEC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'{"version":1,"Resources":[{"'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'":{"Type":"AWS::Lambda::Function","Properties":{"Name":"'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'","Alias":"LIVE","CurrentVersion":'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;',"TargetVersion":'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TARGET_VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'}}}]}'&lt;/span&gt; | jq &lt;span class="nt"&gt;-R&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;REVISION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{"revisionType":"AppSpecContent","appSpecContent":{"content":'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APPSPEC&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'}}'&lt;/span&gt;
&lt;span class="nv"&gt;DEPLOYMENT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws deploy create-deployment &lt;span class="nt"&gt;--application-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--deployment-group-name&lt;/span&gt; Main &lt;span class="nt"&gt;--revision&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$REVISION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.deploymentId'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

aws deploy &lt;span class="nb"&gt;wait &lt;/span&gt;deployment-successful &lt;span class="nt"&gt;--deployment-id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$DEPLOYMENT_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It takes three arguments: &lt;code&gt;$1&lt;/code&gt; is the Lambda function name, &lt;code&gt;$2&lt;/code&gt; is the CodeDeploy application name, and &lt;code&gt;$3&lt;/code&gt; is the URI of the new image. Everything else is figured out along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tools doing the heavy lifting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html" rel="noopener noreferrer"&gt;Lambda version&lt;/a&gt;, which is an immutable snapshot of your code and config, and its &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html" rel="noopener noreferrer"&gt;alias&lt;/a&gt; (&lt;code&gt;LIVE&lt;/code&gt;), which is the stable pointer to a version you've published that your triggers actually talk to;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html" rel="noopener noreferrer"&gt;CodeDeploy&lt;/a&gt;, which is the thing that moves the alias from the old version to the new one, gradually if you want, and rolls it back if something starts screaming;&lt;/li&gt;
&lt;li&gt;The good old AWS CLI, the tool calling all of the above;&lt;/li&gt;
&lt;li&gt;Lastly, &lt;a href="https://jqlang.github.io/jq/" rel="noopener noreferrer"&gt;jq&lt;/a&gt;, a tool for digging values out of the JSON the CLI hands back, and for building the deployment payload.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Failing loud and early
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-euo&lt;/span&gt; pipefail
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line is the unsung hero here, making the script exit on the first error, treat unset variables as errors, and fail if any command in a pipeline fails. In a deployment script this is exactly what you want: if a step goes sideways, you stop right there instead of merrily shifting traffic to a half-baked version. On a side note, this might not be needed in certain environments, for example in &lt;a href="https://circleci.com/docs/reference/configuration-reference/#default-shell-options" rel="noopener noreferrer"&gt;CircleCI&lt;/a&gt;, where the default shell already runs with &lt;code&gt;-eo pipefail&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shipping the new image
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda &lt;span class="nb"&gt;wait &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="nt"&gt;-updated-v2&lt;/span&gt; &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
aws lambda update-function-code &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--image-uri&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$3&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
aws lambda &lt;span class="nb"&gt;wait &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="nt"&gt;-updated-v2&lt;/span&gt; &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first &lt;code&gt;wait function-updated-v2&lt;/code&gt; makes sure the function isn't already mid-update from something else (Lambda won't let you touch it while it's settling). Then &lt;code&gt;update-function-code&lt;/code&gt; points the function at the new image, and the second &lt;code&gt;wait&lt;/code&gt; blocks until that change has fully propagated. Sandwiching the update between two waits is what keeps the rest of the script from racing ahead of AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing a new version
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;PUBLISHED_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws lambda publish-version &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.Version'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

aws lambda &lt;span class="nb"&gt;wait &lt;/span&gt;published-version-active &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--qualifier&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PUBLISHED_VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling &lt;code&gt;publish-version&lt;/code&gt; takes the current code and config and freezes them into a numbered, immutable version. We pull that number out of the response with &lt;code&gt;.Version&lt;/code&gt; and hang on to it. Then we wait for &lt;code&gt;published-version-active&lt;/code&gt;, because a freshly published version needs a moment before it's ready to serve traffic. No point deploying something that isn't awake yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working out where traffic is and where it's headed
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;VERSIONS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws lambda list-versions-by-function &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;CURRENT_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws lambda get-alias &lt;span class="nt"&gt;--function-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; LIVE | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.FunctionVersion'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;TARGET_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$VERSIONS&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.Versions[-1].Version'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CodeDeploy needs two numbers: where traffic is now, and where it should end up. Doing &lt;code&gt;get-alias&lt;/code&gt; on the &lt;code&gt;LIVE&lt;/code&gt; alias gives us the current one via &lt;code&gt;.FunctionVersion&lt;/code&gt;. For the target, we list every version and grab the last one in the list with &lt;code&gt;.Versions[-1].Version&lt;/code&gt;, which is the one we just published. So we go from "whatever's live now" to "the brand-new version".&lt;/p&gt;

&lt;h2&gt;
  
  
  Describing the shift with an AppSpec
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APPSPEC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'{"version":1,"Resources":[{"'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'":{"Type":"AWS::Lambda::Function","Properties":{"Name":"'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'","Alias":"LIVE","CurrentVersion":'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;',"TargetVersion":'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TARGET_VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'}}}]}'&lt;/span&gt; | jq &lt;span class="nt"&gt;-R&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;REVISION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{"revisionType":"AppSpecContent","appSpecContent":{"content":'&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APPSPEC&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s1"&gt;'}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CodeDeploy is told what to do through an &lt;a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure.html" rel="noopener noreferrer"&gt;AppSpec&lt;/a&gt;. For Lambda it's tiny and it just names the function, the alias, and the two versions to move between.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&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;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&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="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;"your-function-name"&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;"Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"AWS::Lambda::Function"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Properties"&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;"your-function-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"Alias"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"LIVE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"CurrentVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"TargetVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;42&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;p&gt;The slightly weird bit is &lt;code&gt;jq -R&lt;/code&gt;. CodeDeploy wants that whole AppSpec passed as a string, not as nested JSON, so &lt;code&gt;-R&lt;/code&gt; takes the raw content and encodes it as one escaped string. That string then gets dropped into the &lt;code&gt;REVISION&lt;/code&gt; object under &lt;code&gt;appSpecContent&lt;/code&gt;, which is exactly the shape the deployment call expects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handing it over to CodeDeploy
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;DEPLOYMENT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws deploy create-deployment &lt;span class="nt"&gt;--application-name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--deployment-group-name&lt;/span&gt; Main &lt;span class="nt"&gt;--revision&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$REVISION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.deploymentId'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

aws deploy &lt;span class="nb"&gt;wait &lt;/span&gt;deployment-successful &lt;span class="nt"&gt;--deployment-id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$DEPLOYMENT_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;create-deployment&lt;/code&gt; call kicks the whole thing off against your application and the &lt;code&gt;Main&lt;/code&gt; deployment group, and we just grab the returned &lt;code&gt;.deploymentId&lt;/code&gt; from the response. From here CodeDeploy owns the traffic shift. The final &lt;code&gt;wait deployment-successful&lt;/code&gt; just blocks until it's done, so your CI job stays busy until the deployment genuinely finishes (or fails). No fire-and-forget.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worth knowing before you use it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How fast traffic actually shifts (all-at-once, canary, linear) lives in the &lt;a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-configurations.html" rel="noopener noreferrer"&gt;deployment configuration&lt;/a&gt; of the group, not in this script. The script just says "go from A to B";&lt;/li&gt;
&lt;li&gt;Automatic rollback lives on the deployment group too - wire up CloudWatch alarms there and a bad version can undo itself while you watch;&lt;/li&gt;
&lt;li&gt;This assumes the &lt;code&gt;LIVE&lt;/code&gt; alias and the &lt;code&gt;Main&lt;/code&gt; deployment group already exist. &lt;code&gt;get-alias&lt;/code&gt; will blow up on a function that's never had the alias, so your very first deploy needs a bit of bootstrapping;&lt;/li&gt;
&lt;li&gt;Thanks to &lt;code&gt;set -e&lt;/code&gt; and all those waiters, any stuck or failed step aborts the run before CodeDeploy is ever involved, which is precisely the behavior you want.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;A pretty simple shell script you can drop into a CI/CD pipeline that publishes a version, hands the traffic shift over to CodeDeploy, and blocks until it's truly done. No more crossing your fingers right after an update-function-code and doing all this by yourself. It may require a few tweaks to suit your use case, but it's a starting point which can be improved from there on.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>serverless</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>Improving HTML code blocks readability with a syntax highlighter</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/improving-html-code-blocks-readability-with-a-syntax-highlighter-3o0b</link>
      <guid>https://dev.to/lucastonelli/improving-html-code-blocks-readability-with-a-syntax-highlighter-3o0b</guid>
      <description>&lt;p&gt;A code block written by hand is pretty simple: use the 'pre' and 'code' HTML elements and the browser gives you a monospace font and keeps your line breaks, but it stops there. So every keyword, string, comment and variable comes out in the exact same color, which is fine for a few lines of YAML, but for a few hundred lines of TypeScript painted in a single flat tone, maybe not. Improving readability for those cases doesn't require shipping a highlighting library to the reader's browser (unless you want to) and is quite simple to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlighting code blocks with ShikiJS
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://shiki.style/" rel="noopener noreferrer"&gt;ShikiJS&lt;/a&gt; uses the same &lt;a href="https://macromates.com/" rel="noopener noreferrer"&gt;TextMate&lt;/a&gt; grammars and themes that VS Code uses, which means the code on your page ends up looking like the code in your editor. And because it can run anywhere, the highlighting may happen while the page is being built, so the reader downloads plain HTML with the colors already baked in, or may happen in the browser, your choice.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://shiki.style/packages/rehype" rel="noopener noreferrer"&gt;rehype plugin&lt;/a&gt; is the piece that wires ShikiJS into a &lt;a href="https://unifiedjs.com/" rel="noopener noreferrer"&gt;unified&lt;/a&gt; pipeline. So, if you write your posts in Markdown, the plugin sits between the Markdown to HTML conversion and the stringifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:fs/promises&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;rehypeShiki&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@shikijs/rehype&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;rehypeStringify&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rehype-stringify&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;remarkParse&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;remark-parse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;remarkRehype&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;remark-rehype&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;unified&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;unified&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;unified&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;remarkParse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;remarkRehype&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rehypeShiki&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;themes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;light&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vitesse-light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vitesse-dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rehypeStringify&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./post.md&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you write your posts directly in HTML, like I do, there's no Markdown step at all. The plugin works on the syntax tree, not on Markdown, so you can parse the HTML with &lt;code&gt;rehype-parse&lt;/code&gt; and hand it the same tree.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:fs/promises&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;rehypeParse&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rehype-parse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;rehypeShiki&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@shikijs/rehype&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;rehypeStringify&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rehype-stringify&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;unified&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;unified&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;unified&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rehypeParse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fragment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rehypeShiki&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vitesse-dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rehypeStringify&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./post.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Either way, what the plugin looks for is a &lt;code&gt;code&lt;/code&gt; element carrying a specific class, which is exactly what the &lt;code&gt;remark-rehype&lt;/code&gt; plugin produces and what you should be writing when you're not using it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;pre&amp;gt;&amp;lt;code&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"language-typescript"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;const answer = 42&lt;span class="nt"&gt;&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Worth noting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;theme&lt;/code&gt; for a single theme and themes for a light and dark pair. The pair version emits CSS variables, so switching between them is a matter of toggling a couple of custom properties instead of highlighting everything twice;&lt;/li&gt;
&lt;li&gt;The default export shares one highlighter instance across processes, but &lt;a href="https://shiki.style/packages/rehype#fine-grained-bundle" rel="noopener noreferrer"&gt;if you care about bundle size&lt;/a&gt;, import &lt;code&gt;rehypeShikiFromHighlighter&lt;/code&gt; from &lt;code&gt;@shikijs/rehype/core&lt;/code&gt; and pass your own highlighter loaded with only the languages you actually use;&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;postprocess&lt;/code&gt; transformer hook never runs here. The plugin operates on the syntax tree rather than on HTML strings, and that's on purpose, so if you rely on a transformer that rewrites the final HTML, you'll need a &lt;a href="https://shiki.style/packages/rehype#workaround-for-html-based-postprocessing" rel="noopener noreferrer"&gt;workaround&lt;/a&gt; to do that.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Highlighting inline code
&lt;/h2&gt;

&lt;p&gt;Code blocks are the obvious win, but there's always inline code sitting in the middle of a sentence, and by default that stays gray while everything around it is colored. ShikiJS can handle those too, it just needs to be told which language each one is.&lt;/p&gt;

&lt;p&gt;That's what the tailing curly colon syntax is for. It's off by default, so you enable it explicitly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rehypeShiki&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tailing-curly-colon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vitesse-dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From there, you append a marker to the end of the snippet with the language you want, right before the closing tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Call &lt;span class="nt"&gt;&amp;lt;code&amp;gt;&lt;/span&gt;console.log("Hello World"){:javascript}&lt;span class="nt"&gt;&amp;lt;/code&amp;gt;&lt;/span&gt; and move on.&lt;span class="nt"&gt;&amp;lt;/p&amp;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 markdown"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Markdown --&amp;gt;&lt;/span&gt;
This snippet &lt;span class="sb"&gt;`console.log("Hello World"){:javascript}`&lt;/span&gt; will be highlighted.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The marker itself is stripped from the output, so the reader never sees it. It's a bit of noise in the source, but it's the price to pay for highlighting code in the middle of a sentence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Worth noting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The marker has to be the very last thing inside the code element;&lt;/li&gt;
&lt;li&gt;The language has to be one that ShikiJS knows about and, if you went with a fine-grained bundle, it must be one you actually loaded;&lt;/li&gt;
&lt;li&gt;Snippets without a marker are left completely alone, which is convenient. File names, flags and environment variables usually read better plain than syntax highlighted as something they're not.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Two options in a config object and a small marker convention, and your posts go from walls of gray monospace to something people can actually scan. No client-side library, no flash of unstyled code, no extra requests (unless you want them). Your readers won't notice it, and that's kind of the point, they'll just stop bouncing off your code blocks.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>tooling</category>
      <category>ux</category>
      <category>ui</category>
    </item>
    <item>
      <title>Ensuring type safe database queries and migrations with Node</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 10 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/ensuring-type-safe-database-queries-and-migrations-with-node-2gng</link>
      <guid>https://dev.to/lucastonelli/ensuring-type-safe-database-queries-and-migrations-with-node-2gng</guid>
      <description>&lt;p&gt;Talking to a database with Node usually goes one of two ways: you write raw SQL and trust that the strings in your code still match the columns in the database, while dealing with SQL injections and migrations by yourself, or you pull in a full ORM and inherit an entire opinionated world just to run simple queries. Both work fine until someone renames a column and you find out about it in production, or you want to do something slightly different and your ORM just won't let you. Fortunately, there's a middle ground where you can get the best of both worlds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing queries with Kysely
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://kysely.dev/" rel="noopener noreferrer"&gt;Kysely&lt;/a&gt; is a query builder, not an ORM. There's no entity layer, no lazy loading, no magic session flushing things behind your back. You describe your schema once as a TypeScript interface and from there every method on the builder narrows what you're allowed to do next.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PostgresDialect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Generated&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kysely&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Pool&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;UsersTable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Generated&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
  &lt;span class="nx"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Generated&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UsersTable&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;dialect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PostgresDialect&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pool&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_URL&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's worth pointing out that &lt;code&gt;Generated&amp;lt;T&amp;gt;&lt;/code&gt; marks columns the database fills in for you, like a serial primary key. When inserting data, the field is optional, but when you select it, it is always there. This is exactly what you want to prevent mistakes when writing code and it's where handwritten interfaces usually fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Actually querying something
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;selectFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;created_at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;like&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;%@lucastonelli.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;orderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;created_at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;desc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// users: { id: number; email: string; created_at: Date }[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The return type isn't something you annotated, it's inferred from what you selected. If you ask for two columns, you get a type with two columns. Make a typo (&lt;code&gt;emial&lt;/code&gt;) and the build fails before anything reaches a database. Join another table and the autocomplete for &lt;code&gt;where&lt;/code&gt; immediately knows about the new columns.&lt;/p&gt;

&lt;p&gt;Kysely also ships &lt;code&gt;Selectable&lt;/code&gt;, &lt;code&gt;Insertable&lt;/code&gt; and &lt;code&gt;Updateable&lt;/code&gt; helpers, so your service functions can take the right shape without you maintaining three nearly identical interfaces by hand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Insertable&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kysely&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Insertable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UsersTable&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insertInto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;returningAll&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;executeTakeFirstOrThrow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Introspecting the database and generating the types
&lt;/h2&gt;

&lt;p&gt;Everything above depends on that &lt;code&gt;Database&lt;/code&gt; interface being correct. Writing it by hand is fine for three tables, but for thirty, it's tedious and it goes stale the moment a teammate merges a migration. At that point your types are no longer describing your database, they're describing your optimism.&lt;/p&gt;

&lt;p&gt;The package &lt;a href="https://github.com/RobinBlomberg/kysely-codegen" rel="noopener noreferrer"&gt;kysely-codegen&lt;/a&gt; fixes that by connecting to the database, introspecting it and writing the types for you. You can start by installing it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; kysely-codegen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then point it at a connection string (it reads &lt;code&gt;DATABASE_URL&lt;/code&gt; from your &lt;code&gt;.env&lt;/code&gt; by default) and run it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kysely-codegen &lt;span class="nt"&gt;--out-file&lt;/span&gt; ./src/db/types.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voilà, your types are generated! By default, the output lands in &lt;code&gt;./node_modules/kysely-codegen/dist/db.d.ts&lt;/code&gt;, which means the types vanish on a clean install and nobody can see them in a pull request, so the &lt;code&gt;--out-file&lt;/code&gt; flag matters. Writing them into &lt;code&gt;src&lt;/code&gt; and committing them means schema changes show up in the diff, where a human can actually look at them.&lt;/p&gt;

&lt;p&gt;From there, the wiring barely changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PostgresDialect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kysely&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Pool&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DB&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./db/types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;dialect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PostgresDialect&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pool&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_URL&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are a few options worth knowing about: &lt;code&gt;--camel-case&lt;/code&gt; if you'd rather not use underscores everywhere (because of ESLint); &lt;code&gt;--singularize&lt;/code&gt; to get &lt;code&gt;User&lt;/code&gt; instead of &lt;code&gt;Users&lt;/code&gt;. And you can have a config file (&lt;code&gt;.kysely-codegenrc.ts&lt;/code&gt;, or a &lt;code&gt;kysely-codegen&lt;/code&gt; key in &lt;code&gt;package.json&lt;/code&gt;) so the whole team runs it the same way instead of everyone inventing their own flags.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrations
&lt;/h2&gt;

&lt;p&gt;Generated types are only as good as the database they were generated from, so migrations need to be part of the same flow. Kysely exposes a &lt;code&gt;Migrator&lt;/code&gt; class you can wire up by hand, but there's no reason to write that script yourself anymore since &lt;a href="https://github.com/kysely-org/kysely-ctl" rel="noopener noreferrer"&gt;kysely-ctl&lt;/a&gt; is the official CLI and it does the wiring for you. It also mirrors &lt;a href="https://knexjs.org/" rel="noopener noreferrer"&gt;Knex.js&lt;/a&gt;' CLI, so if you've used Knex before, the commands will feel suspiciously familiar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; kysely-ctl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed in the project, it becomes available as &lt;code&gt;kysely&lt;/code&gt; and a &lt;code&gt;kysely.config.ts&lt;/code&gt; file will be required to use it, either in the project root or inside a &lt;code&gt;.config&lt;/code&gt; folder. You can write it yourself, but the CLI will scaffold one for you by running &lt;code&gt;kysely init&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kysely-ctl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;dialect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dialectConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;migrationFolder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/db/migrations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that &lt;code&gt;dialect&lt;/code&gt; here is just the name of the Kysely dialect to be used, and &lt;code&gt;dialectConfig&lt;/code&gt; gets handed to the matching dialect, so you don't have to instantiate anything - or just configure it from scratch here, it's fine either way. But if you'd rather not configure the connection twice, you can skip both and pass the &lt;code&gt;kysely&lt;/code&gt; instance your app already exports instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a migration
&lt;/h3&gt;

&lt;p&gt;No more inventing your own file naming convention and then arguing about it in code review.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kysely migrate:make create_users_table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That drops a timestamped TypeScript file into your migration folder. There's a default prefix, but it can be customized, along with other settings in your config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sql&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kysely&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;up&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;serial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;primaryKey&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;varchar(255)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;varchar(255)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;created_at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;timestamptz&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defaultTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sql&lt;/span&gt;&lt;span class="s2"&gt;`now()`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;down&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Kysely&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dropTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes... that's an &lt;code&gt;any&lt;/code&gt; typing, and it's intentional, don't judge me (yet). A migration runs against whatever the schema looked like at that point in history, not against today's generated types. If you type it with your current &lt;code&gt;DB&lt;/code&gt;, the file will keep compiling for a while and then start lying to you the moment a later migration drops that table. Kysely recommends &lt;code&gt;any&lt;/code&gt; here and this is one of the rare places where it's the honest answer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running migrations
&lt;/h3&gt;

&lt;p&gt;Every command can be written with a colon or a space, so &lt;code&gt;kysely migrate:latest&lt;/code&gt; and &lt;code&gt;kysely migrate latest&lt;/code&gt; do the same thing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# run every pending migration&lt;/span&gt;
kysely migrate:latest

&lt;span class="c"&gt;# see what has run and what hasn't&lt;/span&gt;
kysely migrate:list

&lt;span class="c"&gt;# step back one migration&lt;/span&gt;
kysely migrate:down

&lt;span class="c"&gt;# undo everything (the --all is not optional)&lt;/span&gt;
kysely migrate:rollback &lt;span class="nt"&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;--all&lt;/code&gt; is the one gotcha worth remembering: a partial &lt;code&gt;rollback&lt;/code&gt; isn't supported, because Kysely doesn't keep track of migration batches the way Knex does. If you want to undo a single migration, &lt;code&gt;migrate:down&lt;/code&gt; is your friend. The good part is that the CLI reports each migration and its status for you, so you no longer have to remember that &lt;code&gt;migrateToLatest&lt;/code&gt; never throws and quietly hands you an error object your deployment script forgot to check.&lt;/p&gt;

&lt;p&gt;Under the hood it's still Kysely's own migrator, which means migrations take a database-level lock. Calling them from multiple instances at once is safe since they run serially and each migration executes exactly once.&lt;/p&gt;

&lt;p&gt;As a bonus, the same CLI gives you seeds (&lt;code&gt;kysely seed:make&lt;/code&gt; and &lt;code&gt;kysely seed:run&lt;/code&gt;) and a &lt;code&gt;kysely sql&lt;/code&gt; command that runs queries through your configured instance, which is handy when you just want to poke at something without opening a client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrate first, then generate
&lt;/h2&gt;

&lt;p&gt;The order matters, and it's the whole point of this setup. The database is the source of truth, the types are a derived artifact.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&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;"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;"db:migrate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"kysely migrate:latest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"db:types"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"kysely-codegen --out-file ./src/db/types.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"db:sync"&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 run db:migrate &amp;amp;&amp;amp; npm run db:types"&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;p&gt;Run &lt;code&gt;db:sync&lt;/code&gt; locally after writing a migration, commit both the migration and the regenerated types, and let CI type-check the result. If someone changes the schema and forgets to regenerate, the diff will look wrong to a reviewer. If someone regenerates the types and a query no longer compiles, that's not an annoyance, that's the tool doing its job and telling you a rename broke something.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;None of this is a framework and none of it asks you to give up SQL. Kysely types the queries you were already writing, kysely-codegen makes the database itself the source of those types, and kysely-ctl keeps the schema moving forward in a way you can replay and roll back. The library feels like a breath of fresh air among other options, fully integrated with TypeScript, helping us keep our sanity.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>node</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Managing document metadata in React 19</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 10 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/managing-document-metadata-in-react-19-gc6</link>
      <guid>https://dev.to/lucastonelli/managing-document-metadata-in-react-19-gc6</guid>
      <description>&lt;p&gt;This post's title may seem odd to you, if you're up to date, but a few things have changed from React 18 to 19, and one of them is how you manage document metadata. Before it, you likely had some shenanigans going on, like react-helmet or react-helmet-async in place to dynamically update your document title, inject custom metadata, links, scripts or even styles. Thankfully, with React 19 you'll very likely be able to drop all of that in favor of simplicity and good old HTML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing metadata with react-helmet
&lt;/h2&gt;

&lt;p&gt;If you're still in the Middle Ages (React 18) you might still have &lt;a href="https://github.com/nfl/react-helmet" rel="noopener noreferrer"&gt;react-helmet&lt;/a&gt; (or its fork &lt;a href="https://github.com/staylor/react-helmet-async" rel="noopener noreferrer"&gt;react-helmet-async&lt;/a&gt;) installed in your repository, to help you manage your document metadata. Please, don't get me wrong, they're both very popular solutions to an old problem everyone has and had been very reliable in solving it, so far.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Helmet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-helmet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Home page&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Helmet&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;My&lt;/span&gt; &lt;span class="nx"&gt;Website&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome to the home page of My Website.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Helmet&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="nx"&gt;Page&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;home&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Home&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 typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Helmet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-helmet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// About page&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Helmet&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;About&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;My&lt;/span&gt; &lt;span class="nx"&gt;Website&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Learn more about us on the about page.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Helmet&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;About&lt;/span&gt; &lt;span class="nx"&gt;Page&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;about&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what your code might look like if you are using these libraries, but don't stress over it, there's a much simpler solution to this problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing metadata with React 19
&lt;/h2&gt;

&lt;p&gt;Now, getting out of Plato's Cave, instead of having to install third-party libraries to do that, all you have to do is write plain HTML with the required metadata your page requires.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;About&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Lucas&lt;/span&gt; &lt;span class="nx"&gt;Tonelli&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;s history summary&amp;lt;/title&amp;gt;
      &amp;lt;link rel="canonical" href="https://lucastonelli.com/about" /&amp;gt;
      &amp;lt;meta
              name="description"
              content="A brief history about my career and who I am personally."
      /&amp;gt;
      &amp;lt;main title="About"&amp;gt;
        &amp;lt;h1&amp;gt;About&amp;lt;/h1&amp;gt;
      &amp;lt;/main&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what a piece of my CV page looks like. Yup, plain HTML. This is being done entirely by React, and if I were to include more metadata here, such as scripts and styles, I would likely see the same results.&lt;/p&gt;

&lt;p&gt;You might be wondering: "Why did he say 'likely'"? That's because there are a few exceptions where metadata won't be put in the document head. &lt;a href="https://react.dev/reference/react-dom/components/meta#special-rendering-behavior" rel="noopener noreferrer"&gt;For example&lt;/a&gt;, if the &lt;code&gt;meta&lt;/code&gt; element is provided with the &lt;code&gt;itemProp&lt;/code&gt; prop, it will stay where it is, since it doesn't represent metadata about the document, but rather metadata about a specific part of the page.&lt;/p&gt;

&lt;p&gt;With that said, go over &lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;React documentation&lt;/a&gt; and check out all the caveats for this feature. Also, there are &lt;a href="https://github.com/react/react/tree/main/CHANGELOG.md#1900-december-5-2024" rel="noopener noreferrer"&gt;several other features&lt;/a&gt; there that might pique your interest, so I recommend taking a look at those as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Shifting the paradigm of how we manage document metadata, React 19 has dropped in to simplify it, while making some libraries obsolete along the way. Now, writing plain HTML inside a React component is enough to ensure that your document title, for instance, will end up in the document head. That simplifies the day-to-day life of maintaining frontend projects and gives everyone using it fewer things to worry about.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>news</category>
      <category>devex</category>
    </item>
    <item>
      <title>Creating customizable and reusable project templates with Node</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 03 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/creating-customizable-and-reusable-project-templates-with-node-5ae2</link>
      <guid>https://dev.to/lucastonelli/creating-customizable-and-reusable-project-templates-with-node-5ae2</guid>
      <description>&lt;p&gt;At some point in your life you end up with a repo that is the starting point. It has the CI pipeline you like, your preferred linting and formatting configs and the Terraform layout that works like a charm. Then a new project shows up, you clone the base template and spend the next twenty minutes doing find-and-replace on the project name, ids, the domain name and whatever else is hardcoded in there. It works, until you miss a thing and find out your project is failing - but is it because of the template or because you missed something!? However, a small script and two npm packages solve this problem pretty well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prompt and replace
&lt;/h2&gt;

&lt;p&gt;Instead of hardcoding values, you create a template with placeholders, using whatever delimiter is unlikely to show up naturally in your code. Something like &lt;code&gt;{{% project_slug %}}&lt;/code&gt; sitting in your &lt;code&gt;package.json&lt;/code&gt;, Terraform files, &lt;code&gt;README.md&lt;/code&gt; or any other file.&lt;/p&gt;

&lt;p&gt;Then a single script asks for each value and rewrites every occurrence across the repo with two libraries doing the heavy lifting: &lt;a href="https://www.npmjs.com/package/@inquirer/prompts" rel="noopener noreferrer"&gt;@inquirer/prompts&lt;/a&gt; for the questions and &lt;a href="https://www.npmjs.com/package/replace-in-file" rel="noopener noreferrer"&gt;replace-in-file&lt;/a&gt; for the replacements.&lt;/p&gt;

&lt;h3&gt;
  
  
  The script
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node:process&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@inquirer/prompts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;replaceInFileSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;replace-in-file&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;**/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;ignore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node_modules/**/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.env&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scaffolder.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.git/**/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sr"&gt;/{{% project_slug %}}/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sr"&gt;/{{% domain_name %}}/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;glob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;answers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parameter&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Specify the &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parameter&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;(\[&lt;/span&gt;&lt;span class="sr"&gt;|{|}|%|&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;g|&lt;/span&gt;&lt;span class="se"&gt;\/)&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt; `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;replaceInFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;changes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasChanged&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; files were changed`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interesting part is that the list of regexes in &lt;code&gt;from&lt;/code&gt; is the only place you declare anything. The loop turns each pattern into a question by stripping the delimiters out of the regex source, so &lt;code&gt;/{{% domain_name %}}/g&lt;/code&gt; becomes "Specify the domain_name". Adding a new parameter to your template means adding one line to that array, and the prompt comes for free.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;to&lt;/code&gt; array is a placeholder that gets fully overwritten by the answers, and since the nth answer maps to the nth pattern, order matters. Two other details are worth pointing out: &lt;code&gt;ignore&lt;/code&gt; has to include the scaffolder itself, otherwise the script rewrites its own regexes mid-run and you get a fun debugging session; &lt;code&gt;glob.dot&lt;/code&gt; is what makes &lt;code&gt;**/*&lt;/code&gt; actually reach the dotfiles, which is where half of your config lives anyway (&lt;code&gt;.github&lt;/code&gt;, &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; and friends).&lt;/p&gt;

&lt;p&gt;Of course, the script and everything else is customizable, so if you have a different idea, set it up in any way you prefer.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about Yeoman and Cookiecutter?
&lt;/h2&gt;

&lt;p&gt;This problem is old and there are two well-established tools that solve it, so it's fair to ask why you'd write thirty lines instead of using them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Yeoman
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://yeoman.io/" rel="noopener noreferrer"&gt;Yeoman&lt;/a&gt; is the Node ecosystem's answer and it's a proper framework. You write a generator as a separate package, it renders templates through EJS, handles conflict resolution when files already exist, composes generators together and can run install steps afterwards. That's genuinely more powerful, but it also means your template stops being a repository you can clone and run, and becomes a package you have to publish, version and install globally before anyone can use it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cookiecutter
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://cookiecutter.readthedocs.io/" rel="noopener noreferrer"&gt;Cookiecutter&lt;/a&gt; is the Python one and it's closer in spirit: a &lt;code&gt;cookiecutter.json&lt;/code&gt; declares the variables and &lt;a href="https://jinja.palletsprojects.com/en/stable/" rel="noopener noreferrer"&gt;Jinja&lt;/a&gt; renders the tree. It renames directories, which is exactly the thing the script above can't do, and it works on any project regardless of language. The trade-off is that your Node template repo now needs Python in every environment that touches it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations
&lt;/h2&gt;

&lt;p&gt;The package &lt;code&gt;replace-in-file&lt;/code&gt; does what its name says, it replaces content in files. Paths are out of scope, as I mentioned, so a directory called &lt;code&gt;{{% project_slug %}}/&lt;/code&gt; stays exactly as it is after the script runs, quietly, with no error to tell you about it.&lt;/p&gt;

&lt;p&gt;However, there are a few ways to work around it, in increasing order of effort:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep folder names generic, if possible (lol);&lt;/li&gt;
&lt;li&gt;Rename folders by hand afterwards. Fine for one or two paths, terrible as a convention because it's the exact manual step you were trying to delete;&lt;/li&gt;
&lt;li&gt;Add a rename pass to the script. Walk the tree with &lt;code&gt;node:fs&lt;/code&gt;, apply the same answers to path names and &lt;code&gt;renameSync&lt;/code&gt; the matches. Just remember to go depth-first, otherwise you rename a parent directory and invalidate every path you were about to visit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may also have noticed that the replacements themselves are not transactional. If the process dies halfway through, part of your repo is substituted and part isn't, so run it on a fresh clone with a clean &lt;code&gt;git status&lt;/code&gt; and let &lt;code&gt;git diff&lt;/code&gt; be your review step. The script printing which files changed helps a lot here, because a parameter that shows up in zero files is almost always a typo in your template rather than an unused variable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;This isn't a replacement for Yeoman or Cookiecutter and it doesn't try to be. It's a single file you drop in a repo to turn it into a template, with no framework to learn, no package to publish and no second language to install. If you ever outgrow it, the placeholders you already wrote may help with migrating to another tool.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>productivity</category>
      <category>automation</category>
      <category>tools</category>
    </item>
    <item>
      <title>Speeding up your React Router server-side-rendered (SSR) app with Hono</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 03 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/speeding-up-your-react-router-server-side-rendered-ssr-app-with-hono-l8g</link>
      <guid>https://dev.to/lucastonelli/speeding-up-your-react-router-server-side-rendered-ssr-app-with-hono-l8g</guid>
      <description>&lt;p&gt;If you're running a React Router app in framework mode, you get SSR out of the box and for production it hands you @react-router/serve, a small server built on top of Express. While it does the job, Express carries a bit of history (and weight) with it, so if you're the kind of person who wants a leaner server, or just more control over what happens around your app, there's a really nice alternative that drops in with almost no glue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hono (and its Node server)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;createRequestHandler&lt;/code&gt; from &lt;code&gt;react-router&lt;/code&gt; gives you a function that takes a standard web &lt;code&gt;Request&lt;/code&gt; and resolves to a standard web &lt;code&gt;Response&lt;/code&gt;, that's the whole contract. It doesn't care about Node, Express, or any particular server, it just wants a &lt;code&gt;Request&lt;/code&gt; and it'll give you back a &lt;code&gt;Response&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/honojs/hono" rel="noopener noreferrer"&gt;Hono&lt;/a&gt; is built on those exact same web standards and, inside its handler, &lt;code&gt;context.req.raw&lt;/code&gt; is already a web &lt;code&gt;Request&lt;/code&gt;. This means that passing a request from Hono to React Router is basically one line, with no conversions, no bridging and no fuss.&lt;/p&gt;

&lt;p&gt;Since Hono itself doesn't listen on a port, it's just a handler, to actually run it on Node you'll have to bring in &lt;a href="https://github.com/honojs/node-server" rel="noopener noreferrer"&gt;@hono/node-server&lt;/a&gt;, whose &lt;code&gt;serve&lt;/code&gt; function takes your &lt;code&gt;app.fetch&lt;/code&gt; and wires it up to Node's built-in &lt;code&gt;http&lt;/code&gt; server.&lt;/p&gt;

&lt;p&gt;Install both (&lt;code&gt;npm i hono @hono/node-server&lt;/code&gt;) before this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;serve&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@hono/node-server&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Hono&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hono&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createRequestHandler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ServerBuild&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;build&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./build/server/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;ServerBuild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This one here is the output of your bundle&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRequestHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. &lt;code&gt;serve&lt;/code&gt; spins up the Node HTTP server, every request gets turned into a web &lt;code&gt;Request&lt;/code&gt;, Hono passes it to React Router, and the &lt;code&gt;Response&lt;/code&gt; goes back out.&lt;/p&gt;

&lt;h3&gt;
  
  
  Squeezing the last bit of performance
&lt;/h3&gt;

&lt;p&gt;If you must make every request count and you're not going to use Hono's ecosystem (middlewares and everything else), you can improve your performance by dropping the app entirely and relying only on a bare request listener.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;RequestListener&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node:http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getRequestListener&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@hono/node-server&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createRequestHandler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ServerBuild&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;build&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./build/server/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;ServerBuild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRequestHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getRequestListener&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;RequestListener&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why not use Fastify?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fastify.dev/" rel="noopener noreferrer"&gt;Fastify&lt;/a&gt; is fast, mature, and plenty of people already reach for it by default. It's a great framework overall. Why not then?&lt;/p&gt;

&lt;p&gt;The difference comes down to what each one speaks natively. Fastify is built on Node's own HTTP primitives, &lt;code&gt;IncomingMessage&lt;/code&gt; and &lt;code&gt;ServerResponse&lt;/code&gt; (you can reach them as &lt;code&gt;request.raw&lt;/code&gt; and &lt;code&gt;reply.raw&lt;/code&gt;). It doesn't hand you a web &lt;code&gt;Request&lt;/code&gt;, and it doesn't want a web &lt;code&gt;Response&lt;/code&gt; back. React Router deals in nothing but web &lt;code&gt;Request&lt;/code&gt; and &lt;code&gt;Response&lt;/code&gt;, so to marry the two, you would end up having to write an adapter to make it work.&lt;/p&gt;

&lt;p&gt;Since you already have Node's own server available, you don't need to put Fastify in its place, because it would generate unnecessary overhead. Where Fastify really shines is when the server itself is the product: JSON APIs with schema-based validation and its blazing fast &lt;a href="https://github.com/fastify/fast-json-stringify" rel="noopener noreferrer"&gt;JSON stringify serialization&lt;/a&gt;. With that said, for an SSR app where your whole "API" is basically "give this web request to React Router and return the response", Hono removes an entire category of mess you'd have to maintain.&lt;/p&gt;

&lt;p&gt;Before wrapping everything up, there are two things worth taking into consideration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React Router's &lt;code&gt;loadContext&lt;/code&gt; is not being provided to the &lt;code&gt;handler&lt;/code&gt; function in the examples, so you'll need to write your own logic to provide it. I suggest taking a look at how &lt;a href="https://github.com/remix-run/react-router/tree/main/packages/react-router-express" rel="noopener noreferrer"&gt;@react-router/express&lt;/a&gt;, or some other library, does it;&lt;/li&gt;
&lt;li&gt;There are a lot of things going on in your server when you call &lt;code&gt;react-router-serve&lt;/code&gt;, that's why I also recommend &lt;a href="https://github.com/remix-run/react-router/tree/main/packages/react-router-serve" rel="noopener noreferrer"&gt;taking a look at how it goes&lt;/a&gt;, so you don't miss anything you didn't know you needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Swapping to Hono doesn't ask much of you. React Router already talks in web &lt;code&gt;Request&lt;/code&gt; and &lt;code&gt;Response&lt;/code&gt;, Hono does too, and &lt;code&gt;@hono/node-server&lt;/code&gt; handles the Node part for you. You start with a handful of lines and from there you may add (or not) port handling, static serving, logging requests, etc. It's the performance boost your SSR app could be looking for.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>react</category>
      <category>performance</category>
    </item>
    <item>
      <title>Storing and managing secrets cheaply and safely</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 27 Oct 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/storing-and-managing-secrets-cheaply-and-safely-em3</link>
      <guid>https://dev.to/lucastonelli/storing-and-managing-secrets-cheaply-and-safely-em3</guid>
      <description>&lt;p&gt;Every application has its secrets (database passwords, API keys, tokens, etc.) and they need to live somewhere that isn't a plaintext file committed to Git (please, don't). For those familiar with AWS, the first thought that comes to mind is to go with Secrets Manager to manage them, and it works great, except for the price per secret per month. Later down the road, it quietly turns into a line item nobody remembers approving once you multiply it across services, environments and regions. The good news is: for most secrets, there's a cheaper place to put them that's just as safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Storing secrets with SSM Parameter Store
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html" rel="noopener noreferrer"&gt;Parameter Store&lt;/a&gt; is part of AWS Systems Manager and it holds configuration values for your applications. For anything sensitive, you use the &lt;code&gt;SecureString&lt;/code&gt; type, which encrypts the value at rest using &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/secure-string-parameter-kms-encryption.html" rel="noopener noreferrer"&gt;AWS KMS&lt;/a&gt;; for everything else you may either use &lt;code&gt;String&lt;/code&gt; or &lt;code&gt;StringList&lt;/code&gt;. The best part is that the &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html#parameter-store-tiers-introduction" rel="noopener noreferrer"&gt;standard tier is free&lt;/a&gt; and you can get a decent amount of storage and other benefits without paying a cent.&lt;/p&gt;

&lt;p&gt;Writing a secret is a one-liner and if you don't point it at a specific key, it uses the AWS managed key &lt;code&gt;aws/ssm&lt;/code&gt; that Systems Manager creates for you, which costs nothing to have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm put-parameter &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"/myapp/prod/my-secrets"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--value&lt;/span&gt; &lt;span class="s2"&gt;"super-secret-value"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--type&lt;/span&gt; SecureString
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading it back requires &lt;code&gt;--with-decryption&lt;/code&gt;, otherwise you'll just get the ciphertext staring back at you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm get-parameter &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"/myapp/prod/my-secrets"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--with-decryption&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--query&lt;/span&gt; Parameter.Value &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--output&lt;/span&gt; text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A nice bonus is that the path-like naming isn't just for looks. You can scope IAM permissions to a prefix like &lt;code&gt;/myapp/prod/*&lt;/code&gt;, so a service only ever sees the secrets it's supposed to and nothing from other paths.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparing with AWS Secrets Manager
&lt;/h2&gt;

&lt;p&gt;Both services encrypt with KMS, so from a security standpoint they're basically the same. What you're actually paying for with &lt;a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html" rel="noopener noreferrer"&gt;Secrets Manager&lt;/a&gt; is a set of features Parameter Store doesn't have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_lambda.html" rel="noopener noreferrer"&gt;Lambda rotations&lt;/a&gt; included in the price;&lt;/li&gt;
&lt;li&gt;Native integration with RDS, Redshift and DocumentDB, so rotating database credentials is mostly wired up already (&lt;a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_managed.html" rel="noopener noreferrer"&gt;managed rotation&lt;/a&gt;);&lt;/li&gt;
&lt;li&gt;Cross-region replication and easier cross-account sharing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Breaking it down, if you have credentials that auto-rotate through Secrets Manager, leave them there. Rebuilding rotation yourself to save a few cents might not be a good use of your time. However, a large chunk of secrets might never rotate at all - static API keys, third-party tokens, webhook signing secrets and so on. Those are often wasting money with Secrets Manager.&lt;/p&gt;

&lt;p&gt;For those, Parameter Store solves the problem for free. And if you ever bump into the size limit or need parameter policies, &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html" rel="noopener noreferrer"&gt;advanced parameters&lt;/a&gt; are still way cheaper than Secrets Manager, in case someone tries to guilt you about it. However, just like every other AWS' product, &lt;a href="https://docs.aws.amazon.com/general/latest/gr/asm.html" rel="noopener noreferrer"&gt;Secrets Manager&lt;/a&gt; and &lt;a href="https://docs.aws.amazon.com/general/latest/gr/ssm.html" rel="noopener noreferrer"&gt;Parameter Store&lt;/a&gt; both have quotas and limits, so check and compare before committing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch out for the KMS decryption bill
&lt;/h2&gt;

&lt;p&gt;Now, there's always a caveat (another one). Parameter Store doesn't charge you to store a &lt;code&gt;SecureString&lt;/code&gt;, but the decryption and other requests, &lt;a href="https://aws.amazon.com/kms/pricing/" rel="noopener noreferrer"&gt;aren't free&lt;/a&gt;. Despite having a free tier, every single &lt;code&gt;get-parameter --with-decryption&lt;/code&gt; triggers a KMS &lt;code&gt;Decrypt&lt;/code&gt; call, and if you take a look at the pricing, it's nothing, right?!&lt;/p&gt;

&lt;p&gt;Now, picture a Lambda that pulls fifteen separate secrets on every request, receiving traffic all day, plus a couple of CI pipelines fetching the same values on every build. Suddenly you're making KMS requests like you're trying to break a record. Also, if those parameters are on the advanced tier, you're also paying just to store them separately.&lt;/p&gt;

&lt;p&gt;So, if applicable, group related secrets into a single &lt;code&gt;SecureString&lt;/code&gt; parameter as a JSON string. One parameter, one decrypt call per fetch, one thing to manage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ssm put-parameter &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"/myapp/prod/my-secrets"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--type&lt;/span&gt; SecureString &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--value&lt;/span&gt; &lt;span class="s1"&gt;'{"db_password":"...","api_key":"...","jwt_secret":"..."}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you fetch it once and let the application pull out whatever it needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;RAW&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws ssm get-parameter &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"/myapp/prod/my-secrets"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--with-decryption&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--query&lt;/span&gt; Parameter.Value &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--output&lt;/span&gt; text&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$RAW&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.db_password'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, since I don't want you creating new problems: both Parameter Store tiers have a storage cap, so don't try to cram every secret you own into one blob - group them by what's actually fetched together, usually per service or per environment. Adding to that, since the whole value is one parameter, changing a single field means rewriting the entire JSON, so anything that needs independent rotation might be better off on its own. It's a trade-off, not a silver bullet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Reach for SSM Parameter Store as your cheap-and-safe default and group the values into a JSON (beware of the storage limit) so KMS doesn't nickel-and-dime you on every request. Keep Secrets Manager for the handful of secrets where rotation and native integrations actually earn their price. Same security, a fraction of the bill.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>cybersecurity</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Optimizing AWS S3 costs</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 20 Oct 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/optimizing-aws-s3-costs-4kgh</link>
      <guid>https://dev.to/lucastonelli/optimizing-aws-s3-costs-4kgh</guid>
      <description>&lt;p&gt;It's easy to create an S3 bucket, let objects pile up and watch everything sit comfortably in the Standard class whether it's accessed a thousand times a day or has been its fourth abandonment anniversary. However, AWS gives you the tools to figure out where your money is actually going (they'll surely charge for it lol) and when used properly, they'll show you where to start cutting costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the big picture with S3 Storage Lens
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage_lens.html" rel="noopener noreferrer"&gt;S3 Storage Lens&lt;/a&gt; is an organization-wide dashboard for your storage. It aggregates usage and activity across all your accounts, regions and buckets into a single place. So instead of clicking through buckets one by one to answer questions such as "Which buckets hold most of my data?" you get a unified view with filters to precisely help you with that.&lt;/p&gt;

&lt;p&gt;The good thing is that every account gets a &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage_lens_metrics_glossary.html" rel="noopener noreferrer"&gt;default dashboard with free metrics&lt;/a&gt;, no setup required. The free tier gives you several usage metrics with 14 days of retention, which is already enough to spot some offenders. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Buckets with a huge amount of noncurrent object versions (versioning enabled, lifecycle rules forgotten);&lt;/li&gt;
&lt;li&gt;Incomplete multipart upload bytes sitting there for months;&lt;/li&gt;
&lt;li&gt;Buckets that are 100% Standard storage even though nothing suggests they need to be.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to go deeper, there are the &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage_lens_basics_metrics_recommendations.html#storage_lens_basics_metrics_selection" rel="noopener noreferrer"&gt;advanced metrics and recommendations&lt;/a&gt;: activity metrics (requests, bytes downloaded, etc.), advanced cost optimization and data protection metrics, prefix-level aggregation, CloudWatch publishing and 15 months of retention. These are paid though, and we'll get back to that in a bit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding access patterns with S3 Storage Class Analysis
&lt;/h2&gt;

&lt;p&gt;Storage Lens gives you the big picture while &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/analytics-storage-class.html" rel="noopener noreferrer"&gt;Storage Class Analysis&lt;/a&gt; tells you your storage's access patterns. You enable it per bucket (optionally filtered by prefix or tags) and it starts watching your objects' access patterns: how much data is stored, how much is retrieved, and how that changes through time.&lt;/p&gt;

&lt;p&gt;After observing for at least 30 days, it gives you a recommendation on when objects become "infrequently accessed", which is your cue to create a &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html" rel="noopener noreferrer"&gt;lifecycle rule&lt;/a&gt; transitioning them to Standard-IA. You can also export the results daily as CSV to a bucket and slice them however you like (QuickSight, a spreadsheet, whatever makes you happy).&lt;/p&gt;

&lt;p&gt;It's worth noting that the analysis only makes recommendations for transitions from Standard to Standard-IA, and it's also a paid feature, charged per million objects monitored. If your access patterns are unpredictable and you just want to stop thinking about the problem, &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/intelligent-tiering.html" rel="noopener noreferrer"&gt;S3 Intelligent-Tiering&lt;/a&gt; might be a simpler answer than analyzing anything at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't let these tools become your new costs
&lt;/h2&gt;

&lt;p&gt;Both Storage Lens' advanced metrics and Storage Class Analysis charge you per million objects monitored, per month. Turn them on across your accounts indiscriminately, where you might have billions of small objects (such as build outputs), and congratulations, you've just blown your AWS bill.&lt;/p&gt;

&lt;p&gt;The way to avoid that is to do the heavy lifting with the free tier first:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start with the free Storage Lens metrics. They offer pretty decent data for you to build a shortlist of offenders (try using the &lt;a href="https://en.wikipedia.org/wiki/Pareto_principle" rel="noopener noreferrer"&gt;Pareto principle&lt;/a&gt; here);&lt;/li&gt;
&lt;li&gt;Enable the paid tools only on the shortlist and estimate the costs before turning them on (you may do that with &lt;a href="https://calculator.aws/#/addService" rel="noopener noreferrer"&gt;AWS Pricing Calculator&lt;/a&gt;). Turn on Storage Class Analysis for specific buckets, and use prefix or tag filters to narrow it down further instead of monitoring every single object. Use the same logic for Storage Lens advanced metrics: scope the dashboard to the accounts or buckets you're actually studying;&lt;/li&gt;
&lt;li&gt;Turn them off when you're done. Once you have gathered enough information to define what you need to do and your lifecycle rules are in place, disable the analysis. It's a diagnostic tool, not an Amazon Prime subscription. The same goes for Storage Lens.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Use free Storage Lens metrics (advanced ones, if needed) to find the suspects, Storage Class Analysis on the few buckets that justify it, then apply lifecycle rules to act on what you learned and switch the paid monitoring off. That's it, see you!&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>s3</category>
      <category>aws</category>
      <category>infrastructure</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Caching your API at the edge with fine-grained purging controls</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 13 Oct 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/caching-your-api-at-the-edge-with-fine-grained-purging-controls-5m9</link>
      <guid>https://dev.to/lucastonelli/caching-your-api-at-the-edge-with-fine-grained-purging-controls-5m9</guid>
      <description>&lt;p&gt;Caching API responses at the edge sounds great until you hit the invalidation problem. A TTL that's too short and your origin keeps getting hammered, too long and your users see stale data for who knows how long. If what you're looking for is to cache aggressively and purge surgically, the moment something changes and only what changed, there's a solution for that. Spoiler alert: the usual AWS suspects don't really compete here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting your API behind Fastly
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.fastly.com/documentation/guides/full-site-delivery/getting-started-with-full-site-delivery/" rel="noopener noreferrer"&gt;setup&lt;/a&gt; is the usual reverse proxy dance: you create a Fastly service, point it to your API as the origin (or "host"), and &lt;a href="https://www.fastly.com/documentation/guides/getting-started/domains/working-with-domains/working-with-cname-records-and-your-dns-provider/" rel="noopener noreferrer"&gt;move your DNS to Fastly&lt;/a&gt;. From that moment on, every request goes through their &lt;a href="https://www.fastly.com/documentation/guides/getting-started/concepts/using-fastlys-global-pop-network/" rel="noopener noreferrer"&gt;points of presence&lt;/a&gt; (POP) and cacheable responses get stored close to your users.&lt;/p&gt;

&lt;p&gt;Now that caching is set up, what about the "fine-grained purging controls"? This is where the &lt;a href="https://docs.fastly.com/en/guides/working-with-surrogate-keys" rel="noopener noreferrer"&gt;Surrogate-Key header&lt;/a&gt; comes in. Your origin can tag any response with one or more keys, space-separated, and Fastly will index the cached object under all of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt; &lt;span class="ne"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;application/json&lt;/span&gt;
&lt;span class="na"&gt;Surrogate-Key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;products product-42 category-shoes&lt;/span&gt;
&lt;span class="s"&gt;// Surrogate-Control works as well&lt;/span&gt;
&lt;span class="na"&gt;Cache-Control&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;max-age=86400&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of it as labeling your cache. That response for &lt;code&gt;GET /products/42&lt;/code&gt; is now reachable by "everything product-related", "this specific product" and "everything in the shoes category" at the same time. Also, Fastly strips the header before sending the response to the client, so your users never see your labeling scheme. One key can be attached to thousands of objects, and one object can carry multiple keys, allowing for surgical purging later on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Purging by keys
&lt;/h3&gt;

&lt;p&gt;When product 42 gets updated, you don't need to guess which URLs contain it, or nuke the entire cache out of despair. You just &lt;a href="https://www.fastly.com/documentation/reference/api/purging/" rel="noopener noreferrer"&gt;purge the key&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s2"&gt;"https://api.fastly.com/service/&lt;/span&gt;&lt;span class="nv"&gt;$SERVICE_ID&lt;/span&gt;&lt;span class="s2"&gt;/purge/product-42"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Fastly-Key: &lt;/span&gt;&lt;span class="nv"&gt;$FASTLY_API_TOKEN&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every cached object tagged with &lt;code&gt;product-42&lt;/code&gt; is invalidated across the whole network, usually in a few milliseconds. The listing page, the detail endpoint, that search response that happened to include it, all gone in one call while everything else stays warm.&lt;/p&gt;

&lt;p&gt;There's a catch, though (of course). URL-based purges on Fastly work &lt;a href="https://www.fastly.com/documentation/guides/full-site-delivery/purging/authenticating-api-purge-requests/" rel="noopener noreferrer"&gt;out of the box without authentication&lt;/a&gt;, so anyone who knows your endpoints could purge them and turn your cache into swiss cheese (rude, but possible). But don't worry, the fix is adding the header &lt;code&gt;http.Fastly-Purge-Requires-Auth: "1"&lt;/code&gt; change at your service configuration.&lt;/p&gt;

&lt;p&gt;With authenticated purging enabled, every purge request must carry a valid API token with purge permissions, otherwise it gets a 401 and goes home empty-handed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customizing further with VCL scripts
&lt;/h3&gt;

&lt;p&gt;If the defaults aren't enough, Fastly lets you write &lt;a href="https://www.fastly.com/documentation/guides/vcl/custom/" rel="noopener noreferrer"&gt;custom VCL&lt;/a&gt; (Varnish Configuration Language) scripts that run at the edge, on every request and you can invoke them in hooks of the &lt;a href="https://www.fastly.com/documentation/reference/vcl/request-lifecycle/" rel="noopener noreferrer"&gt;request lifecycle&lt;/a&gt;: &lt;code&gt;vcl_recv&lt;/code&gt; when the request arrives, &lt;code&gt;vcl_fetch&lt;/code&gt; when the origin responds, &lt;code&gt;vcl_deliver&lt;/code&gt; before sending it back, and so on.&lt;/p&gt;

&lt;p&gt;That opens a lot of possibilities. For instance, you can normalize query strings so &lt;code&gt;?a=1&amp;amp;b=2&lt;/code&gt; and &lt;code&gt;?b=2&amp;amp;a=1&lt;/code&gt; hit the same cache object, vary the cache by an API version header or even generate surrogate keys at the edge when your origin can't be bothered:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Script injected in the "hash" hook to cache products based on page number&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;req.url.path &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="s2"&gt;"^/products"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;set&lt;/span&gt; req.hash &lt;span class="o"&gt;+=&lt;/span&gt; querystring.filter_except&lt;span class="p"&gt;(&lt;/span&gt;querystring.sort&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;req.url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s2"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;set&lt;/span&gt; req.hash &lt;span class="o"&gt;+=&lt;/span&gt; querystring.remove&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;req.url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;set&lt;/span&gt; req.hash &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nv"&gt;req.http.host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;set&lt;/span&gt; req.hash &lt;span class="o"&gt;+=&lt;/span&gt; req.vcl.generation&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;hash&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also cache things Fastly wouldn't cache by default (like &lt;a href="https://www.fastly.com/documentation/solutions/examples/caching-post-requests/" rel="noopener noreferrer"&gt;POST bodies&lt;/a&gt; for search endpoints, if you know what you're doing) or strip cookies that would otherwise bust your cache. Basically, if the behavior you want isn't a checkbox, it's probably a few lines of VCL away.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about CloudFront and API Gateway caching?
&lt;/h2&gt;

&lt;p&gt;If your stack is on AWS, the natural instinct is to reach for &lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ConfiguringCaching.html" rel="noopener noreferrer"&gt;CloudFront&lt;/a&gt; or the &lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html" rel="noopener noreferrer"&gt;API Gateway cache&lt;/a&gt;. They'll cache your responses just fine, but the control story is a different beast.&lt;/p&gt;

&lt;p&gt;CloudFront has no equivalent to surrogate keys. Its &lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html" rel="noopener noreferrer"&gt;Invalidations&lt;/a&gt; are path-based, so to invalidate "everything related to product 42" you either track every URL that contains it (good luck with query strings) or throw a &lt;code&gt;/*&lt;/code&gt; wildcard and wipe way more than you needed. On top of that, invalidations take minutes to propagate instead of milliseconds, and past the free monthly quota, &lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PayingForInvalidation.html" rel="noopener noreferrer"&gt;each path costs money&lt;/a&gt;. Purging as part of your write path, the way you'd casually do with Fastly, just isn't how it was designed.&lt;/p&gt;

&lt;p&gt;API Gateway is even more restrictive: the cache is a fixed-size instance you pay for hourly, and invalidation is either flushing the entire stage cache or letting clients send &lt;code&gt;Cache-Control: max-age=0&lt;/code&gt; to invalidate a single entry, which you then have to control with an IAM policy so random clients can't do it. No tags, no keys, no grouping, no edge programmability. It works for "cache this GET for 5 minutes", and that's about it.&lt;/p&gt;

&lt;p&gt;None of this means these services are bad, they're just built for different use cases. If precise, event-driven invalidation is a requirement, they'll fight you the whole way. It's also worth mentioning that Fastly offers a free tier for their services, so you'll likely be able to set up a few projects without spending anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Fine-grained purging is what turns edge caching from a risky optimization into something you can lean on: tag responses with &lt;code&gt;Surrogate-Key&lt;/code&gt;, purge those keys from your write path the instant data changes, lock purging down with &lt;code&gt;Fastly-Purge-Requires-Auth&lt;/code&gt;, and reach for VCL when the defaults fall short. Your origin gets quieter, your users get fast and fresh responses, and you stop choosing between the two.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>api</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>Easily secure your non-prod environments from external users for free</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 06 Oct 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/easily-secure-your-non-prod-environments-from-external-users-for-free-2668</link>
      <guid>https://dev.to/lucastonelli/easily-secure-your-non-prod-environments-from-external-users-for-free-2668</guid>
      <description>&lt;p&gt;If you have a private domain sitting on the public internet, chances are anyone can reach it. Search engines index it, curious people poke at it, and bots scan it all day long. The usual fixes are a VPN (complex and annoying to maintain), IP allowlists (break the moment someone works from a coffee shop), or basic auth (everyone shares the same password forever). However, the good thing is that there's another way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloudflare Access
&lt;/h2&gt;

&lt;p&gt;The idea is simple, your DNS record for the environment must be proxied through Cloudflare (the orange cloud), so every request passes through their edge. Then you create a self-hosted &lt;a href="https://developers.cloudflare.com/cloudflare-one/access-controls/applications/http-apps/" rel="noopener noreferrer"&gt;Cloudflare Access application&lt;/a&gt; pointing to that domain, and attach a &lt;a href="https://developers.cloudflare.com/cloudflare-one/access-controls/policies/" rel="noopener noreferrer"&gt;policy&lt;/a&gt; to it, for example, allowing only emails ending in &lt;code&gt;@mycompany.com&lt;/code&gt; or a specific list of addresses.&lt;/p&gt;

&lt;p&gt;From that point on, anyone hitting the gated address gets redirected to a login page, with an input to enter an email. Once the email is submitted, Cloudflare sends a one-time PIN to it, if it matches the conditions in the policy, then the user gets a session cookie and goes through. If the email doesn't match, the user never touches your servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code example
&lt;/h3&gt;

&lt;p&gt;You can click this together on the Cloudflare dashboard, but you can also do it through Terraform with two resources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"cloudflare_zero_trust_access_application"&lt;/span&gt; &lt;span class="s2"&gt;"development"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;account_id&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cloudflare_account_id&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"development.${var.project_name}"&lt;/span&gt;
  &lt;span class="nx"&gt;domain&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"development.${var.apex_domain_name}"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"self_hosted"&lt;/span&gt;
  &lt;span class="nx"&gt;session_duration&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"12h"&lt;/span&gt;
  &lt;span class="nx"&gt;http_only_cookie_attribute&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;app_launcher_visible&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;policies&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
    &lt;span class="nx"&gt;id&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cloudflare_zero_trust_access_policy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;default&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="nx"&gt;precedence&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;}]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"cloudflare_zero_trust_access_policy"&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;account_id&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cloudflare_account_id&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Default"&lt;/span&gt;
  &lt;span class="nx"&gt;decision&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"allow"&lt;/span&gt;
  &lt;span class="nx"&gt;session_duration&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"24h"&lt;/span&gt;
  &lt;span class="nx"&gt;include&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
    &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;default_email&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Worth noting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;session_duration&lt;/code&gt; controls how long the cookie is valid, so people are not logging in on every request;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;http_only_cookie_attribute&lt;/code&gt; keeps the session cookie away from JavaScript;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;app_launcher_visible&lt;/code&gt; hides the app from Cloudflare's app launcher page, since this is just an internal environment;
The policy is separate from the application, so you can reuse the same &lt;code&gt;default&lt;/code&gt; policy across multiple apps.
Do you need to protect staging and QA too? Duplicate the application resource (or use &lt;code&gt;for_each&lt;/code&gt;) pointing to each subdomain, and reference the same policy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Costs
&lt;/h2&gt;

&lt;p&gt;This is the best part, it's free. &lt;a href="https://www.cloudflare.com/plans/zero-trust-services/" rel="noopener noreferrer"&gt;Cloudflare's Zero Trust free tier covers up to 50 users&lt;/a&gt;, which is plenty for protecting internal environments of most teams.&lt;/p&gt;

&lt;p&gt;There is only one catch (of course there would be a catch). The free &lt;a href="https://developers.cloudflare.com/ssl/edge-certificates/universal-ssl/" rel="noopener noreferrer"&gt;Universal SSL&lt;/a&gt; certificate &lt;a href="https://developers.cloudflare.com/ssl/edge-certificates/universal-ssl/limitations/#full-setup" rel="noopener noreferrer"&gt;covers the root domain and one level of subdomain&lt;/a&gt;. So &lt;code&gt;development.myproject.com&lt;/code&gt;, &lt;code&gt;potatochips.myproject.com&lt;/code&gt; and &lt;code&gt;whatever.myproject.com&lt;/code&gt; are all fine. But if you go one level deeper, like &lt;code&gt;api.development.myproject.com&lt;/code&gt;, that's a second-level subdomain and the free certificate won't cover it, so you'd need Cloudflare's paid &lt;a href="https://developers.cloudflare.com/ssl/edge-certificates/advanced-certificate-manager/" rel="noopener noreferrer"&gt;Advanced Certificate Manager&lt;/a&gt; for that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;For such a simple setup and a proxied DNS record, your non-prod environments stop being public. No VPN, no shared passwords, no drastic changes, just an email check at the edge. It's one of those rare cases where it seems too good to be true, but it actually is pretty good.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>infrastructure</category>
      <category>security</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Reduce SQS costs with these three strategies</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 29 Sep 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/reduce-sqs-costs-with-these-three-strategies-b8f</link>
      <guid>https://dev.to/lucastonelli/reduce-sqs-costs-with-these-three-strategies-b8f</guid>
      <description>&lt;p&gt;SQS is a very popular and cheap service from AWS which seems pretty inoffensive to your monthly bill. However, it charges per request, not per message, and that detail is where most of the waste hides. Things like racking up old and unused queues with live consumers, using FIFO indiscriminately and being careless about polling will surely make AWS very happy and your pockets lighter. The good news is: there are a few ways which will help you save some money.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable Long Polling
&lt;/h2&gt;

&lt;p&gt;By default, SQS uses &lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html" rel="noopener noreferrer"&gt;short polling&lt;/a&gt;: your consumer calls &lt;code&gt;ReceiveMessage&lt;/code&gt;, SQS answers immediately (even with an empty response), and your consumer calls again. Every one of those calls are billed, including the empty ones. A worker polling in a tight loop can easily generate millions of requests per month just to hear "nothing new".&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/best-practices-setting-up-long-polling.html" rel="noopener noreferrer"&gt;long polling&lt;/a&gt;, SQS holds the connection open for up to 20 seconds and only responds when there's a message (or when the wait time expires). One call every 20 seconds instead of dozens per second - same behavior for your application, but a fraction of the requests on your bill. Also, enabling it is a one-liner at the queue level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sqs set-queue-attributes &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--queue-url&lt;/span&gt; &lt;span class="nv"&gt;$QUEUE_URL&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--attributes&lt;/span&gt; &lt;span class="nv"&gt;ReceiveMessageWaitTimeSeconds&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or per request, by passing it on the ReceiveMessage API request. There might be no downsides for most workloads, but be sure to check if it fits your use case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prefer standard queues to FIFO
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fifo-queues.html" rel="noopener noreferrer"&gt;FIFO queues&lt;/a&gt; are convenient, exactly-once processing and strict ordering out of the box, but that convenience costs more per request than standard queues, and it also caps your throughput (you'll also have to pay more to increase it). The thing is, for a lot of systems you can get the same guarantees in the application layer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling duplicates
&lt;/h3&gt;

&lt;p&gt;Standard queues offer &lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues-at-least-once-delivery.html" rel="noopener noreferrer"&gt;at-least-once delivery&lt;/a&gt;, so the same message may arrive more than once. Instead of paying FIFO to deduplicate for you, make your consumer idempotent. Give each message a unique ID and record it when processed (a unique constraint in your database or a key in Redis). If the same ID shows up again, skip it (or do something else, I don't know).&lt;/p&gt;

&lt;h3&gt;
  
  
  Ensuring ordering
&lt;/h3&gt;

&lt;p&gt;Standard queues also &lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-queue-types.html" rel="noopener noreferrer"&gt;don't guarantee ordering&lt;/a&gt;, but in practice you might not need the global ordering from the queue. To circumvent that issue, add a timestamp (or version number) to each message at the producer, generated by the application. Then, when consuming, compare it against the last message processed: if the incoming message is older, skip it. An out-of-order message becomes a no-op instead of a bug.&lt;/p&gt;

&lt;h3&gt;
  
  
  Migrating from FIFO to standard
&lt;/h3&gt;

&lt;p&gt;This is the sad part, where there's no configuration, nothing simple or even magical to do that. To &lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues-moving.html" rel="noopener noreferrer"&gt;go back to using standard queues&lt;/a&gt; you need to create another queue and migrate your application to the newly created one. If you have a lot, like an enormous amount of FIFO queues, and you need to migrate them, I feel for you, I really do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete unused queues
&lt;/h2&gt;

&lt;p&gt;This one sounds obvious, but it's pretty easy to forget a queue created for a feature that was deprecated, an experiment, an old environment and, along with it, a consumer somewhere still polling it 24/7. Since empty receives are billed like any other request, you're literally paying for API calls that will never return anything.&lt;/p&gt;

&lt;p&gt;A quick way to find these zombies is to look at the &lt;code&gt;NumberOfEmptyReceives&lt;/code&gt; metric in CloudWatch. A queue with a high count of empty receives and zero messages sent is a strong candidate for deletion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;None of these strategies require redesigning your architecture. Long polling is a configuration change, idempotency and timestamps are small additions to your application code, and cleaning up unused queues is just housekeeping. So, keep up with these tips, and make every SQS request count.&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>infrastructure</category>
      <category>aws</category>
      <category>sqs</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Host your async app without spending a dime using AWS Lambda</title>
      <dc:creator>Lucas Tonelli</dc:creator>
      <pubDate>Tue, 22 Sep 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/lucastonelli/host-your-async-app-without-spending-a-dime-using-aws-lambda-490k</link>
      <guid>https://dev.to/lucastonelli/host-your-async-app-without-spending-a-dime-using-aws-lambda-490k</guid>
      <description>&lt;p&gt;If you have an async app, an internal tool, side project or PoC, there's no reason to pay for a machine that's awake all day for a job that takes so little time. That's where AWS Lambda comes in, charging you only when your function gets executed, with a generous free tier. So how do you take what you have, written with FastAPI, Express, Django, Fastify or whatever, and drop it into Lambda without a lot of refactoring?&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS Lambda Web Adapter
&lt;/h2&gt;

&lt;p&gt;AWS maintains an open source project called the &lt;a href="https://github.com/aws/aws-lambda-web-adapter" rel="noopener noreferrer"&gt;Lambda Web Adapter&lt;/a&gt; which is a small proxy that sits in front of your app. Lambda invokes the adapter, the adapter translates the event into a plain HTTP request, forwards it to your app and translates the response back into whatever shape Lambda expects. Your app has no idea it's running inside Lambda. It just sees an HTTP request on a port, like it always did.&lt;/p&gt;

&lt;p&gt;This means you don't have to refactor anything (not this time at least), you just add the adapter (copying the binary into your image if you're using a container or adding a Lambda Layer) and point it to your app's port. Here's a minimal Dockerfile example for a NodeJS app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;public.ecr.aws/lambda/nodejs:24&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;

&lt;span class="c"&gt;# This is required to make the adapter work as expected&lt;/span&gt;
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; []&lt;/span&gt;

&lt;span class="c"&gt;# Copy the Lambda Web Adapter binary from its distributed image&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=public.ecr.aws/awsguru/aws-lambda-adapter:1.0.1 /lambda-adapter /opt/extensions/lambda-adapter&lt;/span&gt;

&lt;span class="c"&gt;# Tells the adapter which port to listen&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; AWS_LWA_PORT=3000&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package.json ${LAMBDA_TASK_ROOT}/package.json&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package-lock.json ${LAMBDA_TASK_ROOT}/package-lock.json&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;npm ci &lt;span class="nt"&gt;--production&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["node", "app.js"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The adapter handles that translation transparently, including support for streaming responses if your app relies on them. For instance, this very website is running inside a Lambda function (yup).&lt;/p&gt;

&lt;h2&gt;
  
  
  Packaging your app
&lt;/h2&gt;

&lt;p&gt;I've given an example using Docker images, but there are a few other options for you to package your app, and they all fit different needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  ZIP
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-zip.html" rel="noopener noreferrer"&gt;The simplest option&lt;/a&gt;. You zip your code and dependencies, upload it directly (through the console or CLI), and Lambda runs it on its own managed runtime. There's no image to build or registry to manage, but you're capped at 250 MB unzipped (50 MB zipped), and native dependencies need to match Lambda's underlying OS.&lt;/p&gt;

&lt;h3&gt;
  
  
  S3
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-self-managed-storage.html" rel="noopener noreferrer"&gt;Practically the same&lt;/a&gt; as the ZIP approach, but it can accept packages greater than 50 MB zipped. You push the zip to a bucket and point Lambda at that object instead of uploading it inline. Same 250 MB limit applies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/images-create.html" rel="noopener noreferrer"&gt;The option to reach for&lt;/a&gt; once you outgrow the other limits, need OS-level dependencies that aren't in the standard runtimes, or just want your Lambda environment to look like everything else you already run in containers. Also, the images can go up to 10 GB.&lt;/p&gt;

&lt;p&gt;Once the application is packaged and the Lambda function is deployed, you need something in front of it that speaks HTTPS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting an endpoint: Lambda Function URL
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html" rel="noopener noreferrer"&gt;Function URL&lt;/a&gt;s are the fastest option. Every Lambda function can have a dedicated HTTPS endpoint enabled with a single setting, no extra resources to create. You get a generated URL and requests are forwarded straight to your function. If you just need an endpoint for a webhook, an internal service, or a quick prototype, this is usually all you need.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting an endpoint: AWS HTTP API Gateway
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html" rel="noopener noreferrer"&gt;HTTP API Gateway&lt;/a&gt; makes sense once you need more than a bare endpoint: custom domains, request throttling, built-in authorizers, etc. It's a small extra piece of infrastructure to manage, but it's also cheap and pay-per-request, so it doesn't break the "free unless you're actually getting traffic" (or a DDoS attack lol) model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worth knowing before you commit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html" rel="noopener noreferrer"&gt;Lambda has a hard execution limit&lt;/a&gt;, so this isn't a fit for long-lived connections;&lt;/li&gt;
&lt;li&gt;Cold starts are real, especially with container images, but they shouldn't be such a problem in a function with more frequent traffic. So, keep the image lean and consider using &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/provisioned-concurrency.html" rel="noopener noreferrer"&gt;provisioned concurrency&lt;/a&gt; if it matters. However, this is basically spinning up a server and paying for the time it's up;&lt;/li&gt;
&lt;li&gt;A single Lambda function &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html" rel="noopener noreferrer"&gt;reserved concurrency&lt;/a&gt; serves a single request, so plan your concurrency accordingly, to avoid being surprised by throttling;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;For various async apps out there, some idle, others with spiky traffic or without persistent connections, this setup gets you a real production app with an endpoint to receive requests that'll cost you nothing until someone actually uses it! So, what are you going to build with it?!&lt;/p&gt;




&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;small&gt;This article was created with the help of AI because, while I'm good at being a software engineer (I hope so), I suck at being a writer. On the other hand, the silly jokes and wordplay are completely mine because I'm really good at those. Also, the content comes from things I've done or learned, has been verified and is edited to be straight to the point, since AI loves to stall, but I hate it.&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>lambda</category>
      <category>infrastructure</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
