<?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: iAmSherif 💎</title>
    <description>The latest articles on DEV Community by iAmSherif 💎 (@iamsherif).</description>
    <link>https://dev.to/iamsherif</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%2F1069965%2F2956d1af-a76e-4604-8d57-3f180d14be94.jpeg</url>
      <title>DEV Community: iAmSherif 💎</title>
      <link>https://dev.to/iamsherif</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamsherif"/>
    <language>en</language>
    <item>
      <title>How to Test AWS Lambda Locally Using AWS Emulator</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Mon, 23 Nov 2026 19:49:37 +0000</pubDate>
      <link>https://dev.to/aws-builders/how-to-test-aws-lambda-locally-using-aws-emulator-47f4</link>
      <guid>https://dev.to/aws-builders/how-to-test-aws-lambda-locally-using-aws-emulator-47f4</guid>
      <description>&lt;p&gt;Over the years building on AWS, one of my biggest challenges has been local testing. It takes a lot of hard work to get right. Until now, if you have built anything on Lambda, you know the loop: change one line, deploy, wait, test, open CloudWatch, repeat. On November 11, 2026, AWS released &lt;strong&gt;AWS Emulator&lt;/strong&gt;, a free, open-source emulator of the AWS APIs that runs on your own machine. It takes the deploy out of that loop. Your AWS CLI and SDK calls go to a local endpoint instead of AWS, and the answers come back in milliseconds.&lt;/p&gt;

&lt;p&gt;In this article, I will walk you through testing an API Gateway → Lambda → DynamoDB app locally with AWS Emulator and Docker, step by step. More importantly, I will show you every error I hit on both runtimes and how I worked around it. The emulator is not AWS, and the gaps are where your time goes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Everything here was tested on an Intel Mac with Docker, on AWS Emulator 1.0.348 to 1.0.505. Behaviour changed between those versions, so check yours before you trust any finding here.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is AWS Emulator?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/products/developer-tools/emulator/" rel="noopener noreferrer"&gt;AWS Emulator&lt;/a&gt; is a single local program that serves AWS API endpoints. It has no console and no UI. You start it, point your AWS CLI or SDK at it with a few environment variables, and run your code as usual. No AWS account, no credentials, no bill.&lt;/p&gt;

&lt;p&gt;A few things make it different from the tools you may already know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It is generated from AWS's own API models&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is built and maintained by AI agents.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It runs natively on Linux only.&lt;/strong&gt; On macOS and Windows you run it in Docker, from an image you build yourself. AWS does not publish one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Everything lives in memory.&lt;/strong&gt; Stop the emulator and your tables, functions and APIs are gone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What it is not
&lt;/h3&gt;

&lt;p&gt;This part matters more than the feature list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Don't rely on its IAM.&lt;/strong&gt; On 1.0.348 and 1.0.367, a function ran with a role that didn't exist. On 1.0.505, a role with no DynamoDB policy was denied. Enforcement is partial and changes between versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It is one account (&lt;code&gt;000000000000&lt;/code&gt;) and one Region.&lt;/strong&gt; No cross-account or cross-Region behaviour.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lambda runs only Zip-packaged Python and Node.js functions.&lt;/strong&gt; No container images and no other runtimes yet, such as Java or Go. Functions on other runtimes deploy without error, then fail when invoked. If your Lambda is a Docker image, the emulator will store it but won't run it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It is not for security testing or production.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So in this article, Docker runs the &lt;em&gt;emulator&lt;/em&gt;, not your Lambda. The usual AWS Lambda base image approach does not apply here.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;A small &lt;strong&gt;notes&lt;/strong&gt;** API** with three routes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;POST /notes&lt;/code&gt; creates a note and returns &lt;code&gt;201&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /notes/{id}&lt;/code&gt; returns one note, or &lt;code&gt;404&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /notes&lt;/code&gt; lists all notes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's an AWS CDK app I newly built for this article: an API Gateway HTTP API with one Lambda function per route (three Node.js 22 functions), reading and writing one DynamoDB table, &lt;code&gt;Notes&lt;/code&gt;, keyed on &lt;code&gt;id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxm3y9qoubtjmnm4w4yf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxm3y9qoubtjmnm4w4yf4.png" alt="API Gateway → Lambda → DynamoDB, all inside the emulator" width="799" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything except the client runs inside the emulator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Docker, running&lt;/strong&gt;, with about 2 GB of memory free for the emulator and about 2 GB of disk for its image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS CLI v2.&lt;/strong&gt; The AWS CDK CLI too, since Step 4 deploys with it.&lt;/li&gt;
&lt;li&gt;Node.js 22, to match the nodejs22.x functions in the CDK app, and Python 3.12 if you run the Python probe in Step 3. Match the Lambda runtime you will deploy to, not your system default. My machine had Python 3.14; &lt;code&gt;uv python install 3.12&lt;/code&gt; fixed that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No AWS account.&lt;/strong&gt; You won't need one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 - Build and Run the Emulator in Docker
&lt;/h2&gt;

&lt;p&gt;AWS does not publish an image, so you build one from the Dockerfile in the User Guide. Create &lt;code&gt;emulator/Dockerfile&lt;/code&gt;:&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; public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
&lt;span class="k"&gt;ADD&lt;/span&gt; https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-x86_64.rpm /tmp/aws-emulator.rpm
&lt;span class="k"&gt;RUN&lt;/span&gt; rpm -i /tmp/aws-emulator.rpm &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; rm /tmp/aws-emulator.rpm \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; mkdir -p /home/emulator &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; chown 1000 /home/emulator
&lt;span class="k"&gt;USER&lt;/span&gt; 1000
&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/home/emulator
&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 9297
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"aws-emulator"&lt;/span&gt;, &lt;span class="s2"&gt;"-b"&lt;/span&gt;, &lt;span class="s2"&gt;"0.0.0.0"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Apple silicon, replace &lt;code&gt;aws-emulator-x86_64.rpm&lt;/code&gt; with &lt;code&gt;aws-emulator-aarch64.rpm&lt;/code&gt;. I only ran the x86_64 image, so I can't vouch for the Arm one.&lt;/p&gt;

&lt;p&gt;Build it, then start the emulator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t aws-emulator emulator/

mkdir -p ~/.aws/emulator
docker run -d --rm --name aws-emulator --memory=2g --memory-swap=2g \
  -p 127.0.0.1:9297:9297 \
  -e &lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$HOME"&lt;/span&gt; -v &lt;span class="s2"&gt;"$HOME/.aws/emulator:$HOME/.aws/emulator"&lt;/span&gt; \
  aws-emulator -p 9297 --telemetry off
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What matters in that command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mkdir&lt;/code&gt; first. On Linux, if Docker creates the folder, root owns it and your SDK can't read it. Also add &lt;code&gt;--user "$(id -u):$(id -g)"&lt;/code&gt; on Linux.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p 127.0.0.1:9297:9297&lt;/code&gt;, never &lt;code&gt;-p 9297:9297&lt;/code&gt;. The short form opens the emulator to your whole network.&lt;/li&gt;
&lt;li&gt;The volume mount is how the emulator hands you its credentials, config and certificate. It writes them to &lt;code&gt;~/.aws/emulator/9297/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--telemetry off&lt;/code&gt;, because the emulator sends usage data to AWS by default. AWS says it only looks at that data in aggregate and keeps it from being tied to users or accounts, but it's your choice. You can also set &lt;code&gt;EMULATOR_TELEMETRY=off&lt;/code&gt; instead of passing the flag.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--memory=2g&lt;/code&gt;. Go over it and the container dies with exit code 137, taking your resources with it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wait until it is healthy (about 3 s in my runs):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sf --cacert ~/.aws/emulator/9297/ca.pem https://127.0.0.1:9297/__admin/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should get back &lt;code&gt;ok&lt;/code&gt;. In zsh you'll see &lt;code&gt;ok%&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two warnings you can ignore.&lt;/strong&gt; &lt;code&gt;docker logs aws-emulator&lt;/code&gt; shows a warning that the emulator listens on &lt;code&gt;0.0.0.0&lt;/code&gt;. That's the &lt;code&gt;-b 0.0.0.0&lt;/code&gt; in the Dockerfile, which a container needs, and the &lt;code&gt;127.0.0.1:&lt;/code&gt; in the port mapping still keeps it on your machine. The image build also prints &lt;code&gt;NOKEY&lt;/code&gt; for the RPM signature, because the base image doesn't have AWS's signing key. The package installs fine, but its signature isn't checked, so import AWS's key first if that matters to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Point the AWS CLI and SDKs at the Emulator
&lt;/h2&gt;

&lt;p&gt;Open a second terminal. Create &lt;code&gt;scripts/env-emulator.sh&lt;/code&gt; and &lt;code&gt;source&lt;/code&gt; it before every CLI, SDK or test call:&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="kd"&gt;unset&lt;/span&gt; AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_PROFILE
&lt;span class="nv"&gt;E&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.aws/emulator/9297
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_ENDPOINT_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://127.0.0.1:9297
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_SHARED_CREDENTIALS_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$E&lt;/span&gt;/emulator_credentials
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_CONFIG_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$E&lt;/span&gt;/config
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_CA_BUNDLE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$E&lt;/span&gt;/ca.pem
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;NODE_EXTRA_CA_CERTS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$E&lt;/span&gt;/ca.pem   &lt;span class="c"&gt;# Node.js SDK only&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_EC2_METADATA_DISABLED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_DISABLE_HOST_PREFIX_INJECTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;AWS_REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east-1 &lt;span class="nv"&gt;AWS_DEFAULT_REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three rules worth knowing up front:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;127.0.0.1&lt;/code&gt;, never &lt;code&gt;localhost&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;localhost&lt;/code&gt; can resolve to &lt;code&gt;::1&lt;/code&gt;, and some SDKs then put the S3 bucket name in the host name, which the emulator rejects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Node.js SDK needs &lt;code&gt;NODE_EXTRA_CA_CERTS&lt;/code&gt;.&lt;/strong&gt; Node reads it once, at start-up. A &lt;code&gt;--watch&lt;/code&gt; test runner or a REPL that was already running keeps trusting the old certificate after an emulator restart. Restart that process too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every restart resets everything:&lt;/strong&gt; tables, functions, APIs, credentials &lt;em&gt;and&lt;/em&gt; the CA certificate. Always go: start emulator → source env → deploy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sts get-caller-identity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see account &lt;code&gt;000000000000&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add a safety guard
&lt;/h3&gt;

&lt;p&gt;The whole point is to never touch real AWS by accident, say from a shell where you forgot to source the env file. So every deploy and test script starts with a guard:&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="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$AWS_ENDPOINT_URL"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://127.0.0.1:9297"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Not the emulator. Abort."&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;ACCOUNT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;aws sts get-caller-identity --query Account --output text&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$ACCOUNT"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"000000000000"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Wrong account: $ACCOUNT"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The endpoint check runs &lt;strong&gt;before&lt;/strong&gt; any network call. I tested it by pointing at &lt;code&gt;dynamodb.us-east-1.amazonaws.com&lt;/code&gt;: it aborted with no request sent. I also repeated the same check inside my integration test setup, so running &lt;code&gt;pytest&lt;/code&gt; or &lt;code&gt;node --test&lt;/code&gt; by hand in the wrong shell can't reach AWS either. You will see in Step 3 why I didn't want to trust my eyes alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 (Optional) - Check What Your Lambda Sees Inside the Emulator
&lt;/h2&gt;

&lt;p&gt;Before you deploy your real function, deploy a throwaway Lambda whose only job is to report what it sees: the runtime version, the environment variables, which services it can reach and the event it receives. Most of the gaps in the errors section below show up here, and the emulator changes often, so this is how you check them on your own version.&lt;/p&gt;

&lt;p&gt;Here is the Python version. The important part is that every check is wrapped on its own, so one surprise doesn't hide the rest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{type(e).__name__}: {e}"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&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;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"aws_env"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AWS_"&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;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tables"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dynamodb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_tables&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="s2"&gt;"TableNames"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"endpoint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dynamodb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endpoint_url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"event"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;event&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="s2"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;str&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;The Node.js probe does the same with &lt;code&gt;process.version&lt;/code&gt;, &lt;code&gt;process.env&lt;/code&gt; and &lt;code&gt;await import(name)&lt;/code&gt; for a list of core modules. One tip: build the module name as a variable (&lt;code&gt;const m = '@aws-sdk/client-dynamodb'; await import(m)&lt;/code&gt;), otherwise esbuild tries to bundle it.&lt;/p&gt;

&lt;p&gt;Deploy it, invoke it and read the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;zip probe.zip probe.py
aws lambda create-function --function-name probe --runtime python3.12 \
  --handler probe.handler --zip-file fileb://probe.zip \
  --role arn:aws:iam::000000000000:role/lambda-role
aws lambda &lt;span class="nb"&gt;wait&lt;/span&gt; function-active-v2 --function-name probe
aws lambda invoke --function-name probe /dev/stdout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The role doesn't exist. On 1.0.348 and 1.0.367 that didn't matter. On 1.0.505, a role with no DynamoDB policy was denied access, so if you get AccessDeniedException, create a real role with the permissions the function needs.&lt;/p&gt;

&lt;p&gt;For an API Gateway → Lambda → DynamoDB app, the answer that matters most is this one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Can the function's SDK reach DynamoDB?&lt;/strong&gt; Yes, with no endpoint and no credentials in the function code. Inside the function there is no &lt;code&gt;AWS_ACCESS_KEY_ID&lt;/code&gt;, no secret, no session token and no &lt;code&gt;AWS_ENDPOINT_URL&lt;/code&gt;. The SDK inside the emulator is a shim that routes calls internally.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It also gave me a scare. In Python, &lt;code&gt;client.meta.endpoint_url&lt;/code&gt; reported &lt;code&gt;https://dynamodb.us-east-1.amazonaws.com&lt;/code&gt;, the &lt;em&gt;real&lt;/em&gt; AWS hostname. For a project whose first rule is "never call real AWS", that looks alarming. Here is how I confirmed it was safe:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;list_tables()&lt;/code&gt; returned a table that only existed in the emulator.&lt;/li&gt;
&lt;li&gt;A DNS lookup inside the function failed with: &lt;code&gt;a Lambda function in this emulator has no host network to reach&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The emulator's own log recorded the calls.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the function has no network at all. The reported endpoint is simply misleading, and that is exactly why the safety guard from Step 2 checks the account id instead of trusting what the code reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 - Deploy Your App to the Emulator
&lt;/h2&gt;

&lt;p&gt;If your app is already in AWS CDK, you don't need new deploy scripts. &lt;code&gt;cdk deploy&lt;/code&gt; works against the emulator as it is. I tested it with the notes app from What I Built: an HTTP API, three &lt;code&gt;nodejs22.x&lt;/code&gt; functions and a DynamoDB table. Bootstrap, asset upload, deploy, hotswap, &lt;code&gt;cdk watch&lt;/code&gt; and destroy all worked. One route needed a local-only fix (Error #7).&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploy With AWS CDK
&lt;/h3&gt;

&lt;p&gt;With the env file sourced and the safety guard passing:&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="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;CDK_DISABLE_CLI_TELEMETRY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
cdk bootstrap aws://000000000000/us-east-1
cdk deploy --require-approval never
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it works without changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The CDK CLI reads &lt;code&gt;AWS_ENDPOINT_URL&lt;/code&gt;, and the variable takes priority over the endpoint in the emulator's &lt;code&gt;config&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;It trusts the emulator's certificate through either &lt;code&gt;AWS_CA_BUNDLE&lt;/code&gt; or &lt;code&gt;NODE_EXTRA_CA_CERTS&lt;/code&gt;. With neither set, bootstrap fails with &lt;code&gt;self-signed certificate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NodejsFunction&lt;/code&gt; left the AWS SDK out of the bundle, because my stack sets &lt;code&gt;externalModules: ['@aws-sdk/*']&lt;/code&gt;. Keep it that way: a bundled SDK won't load in the emulator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't trust &lt;code&gt;CREATE_COMPLETE&lt;/code&gt; alone. Check the resources with the CLI, and call every route: one of mine deployed cleanly and still failed (Error #7). To check a function's state, use &lt;code&gt;aws lambda get-function-configuration&lt;/code&gt;; &lt;code&gt;list-functions&lt;/code&gt; returned &lt;code&gt;None&lt;/code&gt; for &lt;code&gt;State&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The HTTP API invoke URL&lt;/strong&gt; has no stage in the path when you use the &lt;code&gt;$default&lt;/code&gt; stage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://127.0.0.1:9297/_aws/execute-api/{apiId}/notes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;.../{apiId}/$default/notes&lt;/code&gt; works too. &lt;code&gt;aws apigatewayv2 get-apis&lt;/code&gt; prints the endpoint for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep production unchanged.&lt;/strong&gt; Put any local-only change behind a context flag, deploy with &lt;code&gt;cdk deploy -c local=true&lt;/code&gt;, and check that &lt;code&gt;cdk synth&lt;/code&gt; without the flag gives exactly the same template as before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clean up&lt;/strong&gt; with &lt;code&gt;cdk destroy&lt;/code&gt;. A table with &lt;code&gt;RemovalPolicy.RETAIN&lt;/code&gt; stays behind, as it would on AWS. Restarting the emulator clears everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 - Test It
&lt;/h2&gt;

&lt;p&gt;With everything deployed, you can test the whole path, API Gateway → Lambda → DynamoDB, without leaving your machine. There are three checks worth knowing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Call the API
&lt;/h3&gt;

&lt;p&gt;Use the invoke URL from Step 4. If you don't have it, list the APIs in the emulator. The &lt;code&gt;ApiEndpoint&lt;/code&gt; of each one is its base URL, for example &lt;a href="https://127.0.0.1:9297/_aws/execute-api/" rel="noopener noreferrer"&gt;https://127.0.0.1:9297/_aws/execute-api/&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;aws apigatewayv2 get-apis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a note and read it back with the &lt;code&gt;id&lt;/code&gt; from the response:&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;API_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://127.0.0.1:9297/_aws/execute-api/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;apiId&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nv"&gt;CA&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.aws/emulator/9297/ca.pem
curl -s --cacert &lt;span class="nv"&gt;$CA&lt;/span&gt; -X POST &lt;span class="s2"&gt;"$API_URL/notes"&lt;/span&gt; \
  -H &lt;span class="s1"&gt;'content-type: application/json'&lt;/span&gt; -d &lt;span class="s1"&gt;'{"title":"First note"}'&lt;/span&gt;
curl -s --cacert &lt;span class="nv"&gt;$CA&lt;/span&gt; &lt;span class="s2"&gt;"$API_URL/notes/&amp;lt;id&amp;gt;"&lt;/span&gt;
curl -s --cacert &lt;span class="nv"&gt;$CA&lt;/span&gt; &lt;span class="s2"&gt;"$API_URL/notes"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also test the unhappy paths: a bad body should return &lt;code&gt;400&lt;/code&gt;, an unknown id &lt;code&gt;404&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Invoke the Lambda directly
&lt;/h3&gt;

&lt;p&gt;First, create an &lt;code&gt;event.json&lt;/code&gt; that looks like what API Gateway sends. If you ran the probe in Step 3, use the event it captured. Otherwise, write a minimal one. This is an HTTP API (payload 2.0) event for &lt;code&gt;GET /notes/{id}&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; event.json &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"version"&lt;/span&gt;: &lt;span class="s2"&gt;"2.0"&lt;/span&gt;,
  &lt;span class="s2"&gt;"routeKey"&lt;/span&gt;: &lt;span class="s2"&gt;"GET /notes/{id}"&lt;/span&gt;,
  &lt;span class="s2"&gt;"rawPath"&lt;/span&gt;: &lt;span class="s2"&gt;"/notes/123"&lt;/span&gt;,
  &lt;span class="s2"&gt;"rawQueryString"&lt;/span&gt;: &lt;span class="s2"&gt;""&lt;/span&gt;,
  &lt;span class="s2"&gt;"headers"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"content-type"&lt;/span&gt;: &lt;span class="s2"&gt;"application/json"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="s2"&gt;"pathParameters"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"id"&lt;/span&gt;: &lt;span class="s2"&gt;"123"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="s2"&gt;"requestContext"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"http"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"method"&lt;/span&gt;: &lt;span class="s2"&gt;"GET"&lt;/span&gt;, &lt;span class="s2"&gt;"path"&lt;/span&gt;: &lt;span class="s2"&gt;"/notes/123"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;,
    &lt;span class="s2"&gt;"routeKey"&lt;/span&gt;: &lt;span class="s2"&gt;"GET /notes/{id}"&lt;/span&gt;,
    &lt;span class="s2"&gt;"stage"&lt;/span&gt;: &lt;span class="s2"&gt;"$default"&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="s2"&gt;"isBase64Encoded"&lt;/span&gt;: &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A REST API event has a different shape: &lt;code&gt;httpMethod&lt;/code&gt;, &lt;code&gt;resource&lt;/code&gt;, &lt;code&gt;path&lt;/code&gt; and &lt;code&gt;pathParameters&lt;/code&gt; at the top level. If your handler reads other fields, add them too.&lt;/p&gt;

&lt;p&gt;Then invoke the function without going through API Gateway. CDK generates function names, so look yours up first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws lambda list-functions --query &lt;span class="s1"&gt;'Functions[].FunctionName'&lt;/span&gt;
aws lambda invoke --function-name &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;your-function&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --cli-binary-format raw-in-base64-out \
  --payload file://event.json /dev/stdout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how you reach the cases API Gateway blocks before your function runs, like an undefined route. It is also your fallback if a future emulator version breaks the HTTP path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check what landed in DynamoDB
&lt;/h3&gt;

&lt;p&gt;After a &lt;code&gt;POST /notes&lt;/code&gt;, the new item should be in the table. CDK generates the table name, so list the tables first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws dynamodb list-tables
aws dynamodb scan --table-name &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;your-table&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Errors I Hit and How I Fixed Them
&lt;/h2&gt;

&lt;p&gt;Most of these trace back to one fact: the Lambda runtimes inside AWS Emulator are &lt;strong&gt;not&lt;/strong&gt; the real interpreters, and the AWS SDK inside them is a shim.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python runtime
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Finding: &lt;code&gt;python3.12&lt;/code&gt; is not CPython 3.12&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inside the function, &lt;code&gt;sys.version&lt;/code&gt; returned:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;3.14.0.alpha ... [RustPython 0.6.0 with rustc 1.99.1]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's RustPython, a Python interpreter written in Rust, not CPython. This cuts both ways. Code that uses 3.13 or 3.14 features can pass in the emulator and fail on real Lambda. Code that relies on CPython behaviour or C extensions can fail in the emulator and work on AWS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workaround:&lt;/strong&gt; run your unit tests on a real CPython 3.12. The emulator proves the wiring, not the interpreter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #1: boto3 has no version&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;AttributeError: module 'boto3' has no attribute '__version__'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The boto3 inside the function is a stand-in, not the real library. &lt;strong&gt;Workaround:&lt;/strong&gt; use &lt;code&gt;getattr(boto3, "__version__", "?")&lt;/code&gt;, and watch for libraries that read boto3's version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #2: Credentials with no access key&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TypeError: 'NoneType' object is not subscriptable&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Unlike real Lambda, the function gets no access key, secret or session token. &lt;strong&gt;Workaround:&lt;/strong&gt; don't read credentials in your function; you never need to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #3: &lt;code&gt;import subprocess&lt;/code&gt; crashes the function&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ModuleNotFoundError: No module named '_signal'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Importing &lt;code&gt;subprocess&lt;/code&gt; at module level, or any library that does, crashes the function at cold start. &lt;strong&gt;Workaround:&lt;/strong&gt; keep OS-level modules out of module-level imports.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #4: Unknown service inside the function&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;UnknownServiceError: Unknown service: 'sts'. Valid service names are: sqs, sns, events, eventbridge, dynamodb, logs, cloudwatchlogs, cloudwatch, apigateway, apigatewaymanagementapi, secretsmanager, ss...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;boto3 inside the function only covers some services. Oddly, &lt;code&gt;boto3.client("nope")&lt;/code&gt; returned a client without raising, so don't trust the absence of an error either.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workaround:&lt;/strong&gt; check that every service your function calls is on that list. Call STS from the host instead; that is where my safety guard runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Node.js runtime
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Error #5: A bundled AWS SDK fails at import&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Runtime.ImportModuleError: Error: Cannot find module 'node:zlib'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A bundled SDK needs Node.js core modules the emulator doesn't have. On 1.0.505 it fails on &lt;code&gt;node:process&lt;/code&gt; instead. &lt;strong&gt;Workaround:&lt;/strong&gt; leave the SDK out of the bundle, because the runtime provides it: &lt;code&gt;externalModules: ['@aws-sdk/*']&lt;/code&gt; with CDK, or &lt;code&gt;'--external:@aws-sdk/*'&lt;/code&gt; with esbuild.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #6: The esbuild &lt;code&gt;createRequire&lt;/code&gt; banner fails too&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Runtime.ImportModuleError: Error: Cannot find module 'node:module'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;esbuild's usual banner for CommonJS dependencies imports &lt;code&gt;node:module&lt;/code&gt;, which the emulator doesn't have. &lt;strong&gt;Workaround:&lt;/strong&gt; with the SDK left out of the bundle, you don't need the banner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finding: The SDK client is a shim too&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;new DynamoDBClient({})&lt;/code&gt; works with no endpoint and no credentials, but &lt;code&gt;client.config.endpoint&lt;/code&gt; is undefined and the client has only a &lt;code&gt;config&lt;/code&gt; property. A real v3 client also has &lt;code&gt;middlewareStack&lt;/code&gt;. So locally you are not testing the real SDK's middleware, retries or HTTP settings. Anything you configure beyond the defaults may behave differently, or be ignored. I didn't verify which.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploying with CDK
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Error #7: A route with a path parameter returns 500&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;500 {"message":"Internal Server Error"}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After a clean deploy, &lt;code&gt;GET /notes&lt;/code&gt; and &lt;code&gt;POST /notes&lt;/code&gt; worked, but &lt;code&gt;GET /notes/{id}&lt;/code&gt; returned 500 for every id. The function was never called. The emulator's log says why:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;refusing an invoke: this route's function allows the gateway no invocation for it, so none was made&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;CDK gives API Gateway permission to call the function on the path &lt;code&gt;/notes/{id}&lt;/code&gt;, written literally. The emulator doesn't match that to a real request like &lt;code&gt;/notes/123&lt;/code&gt;. I couldn't check how real AWS treats it, so I'm not calling it a bug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workaround:&lt;/strong&gt; give API Gateway a second permission that uses &lt;code&gt;*&lt;/code&gt; for the path, and only for local deploys.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your stack, after you create the function and the HTTP API, add this:
&lt;/li&gt;
&lt;/ol&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;iam&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'aws-cdk-lib/aws-iam'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Only runs when you deploy with: cdk deploy -c local=true&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tryGetContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'local'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'true'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// getNoteFn = the function behind GET /notes/{id}&lt;/span&gt;
  &lt;span class="c1"&gt;// httpApi   = your HttpApi&lt;/span&gt;
  &lt;span class="n"&gt;getNoteFn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addPermission&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'LocalEmulatorInvoke'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;iam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ServicePrincipal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'apigateway.amazonaws.com'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sourceArn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`arn:aws:execute-api:${this.region}:${this.account}:${httpApi.apiId}/*/*/notes/*`&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Deploy to the emulator with the flag: &lt;code&gt;cdk deploy -c local=true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;GET /notes/{id}&lt;/code&gt; again. You should get 200 for a note that exists and 404 for one that doesn't.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without &lt;code&gt;-c local=true&lt;/code&gt;, the extra permission isn't added, so your production template doesn't change. If you have other routes with a path parameter, give each of them the same permission.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the Emulator Can't Tell You
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AWS Emulator proves your wiring, not your runtime.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It told me, with real confidence, that API Gateway routes to my function, that my function reads and writes DynamoDB and that my error responses have the right shape. It could not tell me any of these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Whether your IAM is right.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Whether your code runs on the real interpreter.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Whether your SDK configuration works.&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything involving the network or host files.&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Warm-start behaviour.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only proof of those is a real deployment. Use the emulator for the fast inner loop, and keep one deploy to a real AWS account in your pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;AWS Emulator does what it promises. Calls come back in milliseconds, there's no account and no bill, and a fresh start, CDK deploy and test takes a minute or two. For API Gateway, Lambda and DynamoDB, its behaviour was faithful: complete proxy events, the real error shapes, real pagination limits.&lt;/p&gt;

&lt;p&gt;But it is a new tool, and it changes every day. The runtimes are stand-ins, the SDK is a shim, and IAM is only partly enforced. So check what your Lambda sees before you build, run your unit tests on the real runtime, guard against touching real AWS, and write down the version you tested on.&lt;/p&gt;

&lt;p&gt;The emulator didn't replace AWS for me. It replaced the waiting.&lt;/p&gt;

&lt;p&gt;Have you tried it yet? If you hit an error I didn't cover, drop it in the comments and I'll add it here.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/blogs/aws/test-your-applications-against-aws-locally-with-aws-emulator/" rel="noopener noreferrer"&gt;Test your applications against AWS locally with AWS Emulator&lt;/a&gt;, AWS News Blog&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/emulator/latest/userguide/what-is-service.html" rel="noopener noreferrer"&gt;What is AWS Emulator?&lt;/a&gt;, AWS Emulator User Guide&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/emulator/latest/userguide/getting-started-docker.html" rel="noopener noreferrer"&gt;Getting started with Docker&lt;/a&gt;, AWS Emulator User Guide&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/aws/aws-emulator" rel="noopener noreferrer"&gt;aws/aws-emulator&lt;/a&gt;, GitHub&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;For more articles, follow my social handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://x.com/sherif_on_x" rel="noopener noreferrer"&gt;Twitter/X&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;Dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Medium&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>lambda</category>
      <category>testing</category>
      <category>awsemulator</category>
    </item>
    <item>
      <title>What is MCP? How AI Agents Plug Into the World (MCP Series, Part 1)</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Sat, 07 Nov 2026 23:35:10 +0000</pubDate>
      <link>https://dev.to/iamsherif/what-is-mcp-how-ai-agents-plug-into-the-world-mcp-series-part-1-3pi4</link>
      <guid>https://dev.to/iamsherif/what-is-mcp-how-ai-agents-plug-into-the-world-mcp-series-part-1-3pi4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Not so long ago, every phone brand shipped with its own charger. Nokia had its pins, Samsung had a different port, and Apple had yet another. Leave yours at home and you were stuck, even in a room full of chargers.&lt;/p&gt;

&lt;p&gt;AI applications ran into the same problem. Every app that wanted to read a file, query a database, or call an API needed its own custom connector, built for that one pairing of app and service. The &lt;strong&gt;Model Context Protocol (MCP)&lt;/strong&gt; fixes that: one standard "charging port" for connecting AI applications to tools and data.&lt;/p&gt;

&lt;p&gt;This is the first article in a series on MCP. Over the next few parts, we will cover:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is MCP? (this article)&lt;/li&gt;
&lt;li&gt;The difference between MCP and an API&lt;/li&gt;
&lt;li&gt;What changed in the new MCP version: sampling, logging (and the OpenTelemetry workaround), roots being deprecated, and others&lt;/li&gt;
&lt;li&gt;The new MCP version deep dive: handling state in a stateless infrastructure (HTTP+SSE vs Streamable HTTP)&lt;/li&gt;
&lt;li&gt;MCP on AWS: event functions or web functions, and why&lt;/li&gt;
&lt;li&gt;Handling MCP auth in web functions&lt;/li&gt;
&lt;li&gt;AWS infrastructure MCP&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this article, we focus on the foundation: how an agent connects to resources through MCP, the roles involved, what a server can offer, and how one MCP server works with several clients at once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt; You should have a basic idea of what an LLM is and have called an HTTP API before. No MCP experience needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Everything here is based on the current MCP specification, revision &lt;strong&gt;2026-07-28&lt;/strong&gt;. If you read MCP tutorials from 2025, a few things (like the &lt;code&gt;initialize&lt;/code&gt; handshake and sessions) have changed. I will point them out as we go.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How Agents Reached Tools Before MCP
&lt;/h2&gt;

&lt;p&gt;An LLM on its own only knows what it learned during training. It cannot check today's exchange rate, read your Jira board, or query your Postgres database. To do anything useful in the real world, an agent needs a way to reach out to resources.&lt;/p&gt;

&lt;p&gt;Before MCP, the usual approach was function calling (also called tool use). You describe a function to the model in your request, the model replies with "call this function with these arguments", your code executes it, and you send the result back. That works, but all the wiring (tool definitions, execution, auth, retries) lives inside that one application.&lt;/p&gt;

&lt;p&gt;Now multiply that. Say your company has 4 AI applications (a chat assistant, an IDE plugin, an internal agent, and a support bot) and 5 services they need (GitHub, Slack, a database, Google Drive, and your billing API). Without a shared standard, you are looking at up to 4 × 5 = 20 separate integrations, each built and maintained on its own.&lt;/p&gt;

&lt;p&gt;This is the classic &lt;strong&gt;N × M integration problem&lt;/strong&gt;. MCP turns it into &lt;strong&gt;N + M&lt;/strong&gt;: each AI application implements the protocol once, each service implements it once, and they can all talk to each other. In our example, that is 4 + 5 = 9 implementations instead of 20.&lt;/p&gt;

&lt;p&gt;Before we dive deep, let's define MCP properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What Is MCP?
&lt;/h2&gt;

&lt;p&gt;The Model Context Protocol (MCP) is an open standard that defines how AI applications discover and use external tools, data, and prompt templates through one common interface.&lt;/p&gt;

&lt;p&gt;Notice the word &lt;em&gt;protocol&lt;/em&gt;. MCP is not a library, a framework, or a product. It is a set of rules, the same way HTTP is a set of rules. It defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Who talks to whom&lt;/strong&gt;: a host, its clients, and servers (more on these shortly).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What a server can offer&lt;/strong&gt;: tools, resources, and prompts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How messages are encoded&lt;/strong&gt;: every message is JSON-RPC 2.0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How messages travel&lt;/strong&gt;: stdio for local servers, Streamable HTTP for remote ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How remote servers are secured&lt;/strong&gt;: an OAuth-based authorization framework.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The official MCP docs compare it to a USB-C port for AI applications, which is the grown-up version of my charger story. Build one MCP server for your service, and any MCP-compatible application (Claude, ChatGPT, Cursor, VS Code, or your own agent) can use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Three Roles: Host, Client, and Server
&lt;/h2&gt;

&lt;p&gt;MCP has three roles. Once you get these, everything else falls into place.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Host&lt;/strong&gt;: The AI application the user actually interacts with: Claude Desktop, Cursor, VS Code, or a custom agent you built yourself. The host owns the conversation, the model, and the user's trust.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client&lt;/strong&gt;: A connector that lives inside the host. The host creates &lt;strong&gt;one client for each server&lt;/strong&gt; it connects to, and each client keeps a one-to-one relationship with its server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt;: A program that exposes capabilities. It might wrap a database, a file system, a SaaS product like GitHub, or your own HTTP API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Going back to the charger analogy: the host is your phone, each client is a port on the phone, and each server is whatever you plug into that port.&lt;/p&gt;

&lt;p&gt;Here is the key point people often miss: &lt;strong&gt;the model never talks to the server directly.&lt;/strong&gt; When it wants to use a tool, it tells the host, and the host's client makes the call. The host stays in control of what gets called and what the user sees. That separation is deliberate; it is where user consent and security checks happen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F88tyabvwl9u6twwdfi4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F88tyabvwl9u6twwdfi4s.png" alt="How MCP Clients and server connect" width="799" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Host A runs two clients, one per server it uses. The billing server is shared: Host A's Client 2 and Host B's Client 1 both talk to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an MCP Server Can Offer
&lt;/h2&gt;

&lt;p&gt;An MCP server exposes its features through three primitives. The difference that matters most is &lt;em&gt;who decides&lt;/em&gt; when each one gets used.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Primitive&lt;/th&gt;
&lt;th&gt;Controlled by&lt;/th&gt;
&lt;th&gt;What it is&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Tools&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The model&lt;/td&gt;
&lt;td&gt;Functions the model can call, each with a name, description, and JSON Schema input&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;calculate&lt;/code&gt;, &lt;code&gt;create_invoice&lt;/code&gt;, &lt;code&gt;search_issues&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The application&lt;/td&gt;
&lt;td&gt;Read-only context identified by a URI&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;file:///project/README.md&lt;/code&gt;, a customer record&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Prompts&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The user&lt;/td&gt;
&lt;td&gt;Reusable prompt templates, often shown as slash commands&lt;/td&gt;
&lt;td&gt;"Summarize this incident", "Draft a release note"&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Tools&lt;/strong&gt; are by far the most used. When people say "we built an MCP server for our API", they almost always mean a set of tools that call API endpoints.&lt;/p&gt;

&lt;p&gt;There is also one feature that flows the other way, from client to server: &lt;strong&gt;elicitation&lt;/strong&gt;. It lets a server ask the user for missing input in the middle of a request, for example "which account should I debit?" before a transfer goes through.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Earlier spec revisions also had &lt;strong&gt;roots&lt;/strong&gt;, &lt;strong&gt;sampling&lt;/strong&gt;, and &lt;strong&gt;logging&lt;/strong&gt; as client-side features. The 2026-07-28 revision deprecated all three. They keep working for at least twelve months under the new deprecation policy, but new implementations should not adopt them. We will dig into this, and the workarounds, in Part 3 of this series.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How a Request Flows, End to End
&lt;/h2&gt;

&lt;p&gt;Let's say we built a Calculator MCP server. It exposes a single tool, &lt;code&gt;calculate&lt;/code&gt;. Here is how the server describes that tool when a client asks with &lt;code&gt;tools/list&lt;/code&gt;:&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;"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;"calculate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Calculator"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Performs basic arithmetic on two numbers. Use it whenever an exact result is needed instead of estimating."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"inputSchema"&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;"object"&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;"operation"&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;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"enum"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"add"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"subtract"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"multiply"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"divide"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"The operation to perform"&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;"a"&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;"number"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"First operand"&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;"b"&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;"number"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Second operand"&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;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"operation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"b"&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;"annotations"&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;"readOnlyHint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&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;That definition is all the model will ever know about our server. It never sees our code, so the name, description, and schema have to explain the tool on their own. A vague description means wrong calls.&lt;/p&gt;

&lt;p&gt;Now, when you ask an agent "What is 1,250 multiplied by 12?" and it uses the calculator server to answer. Here is what happens under the hood:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Connect&lt;/strong&gt;: You add the server to your host, either as a local command (stdio) or a URL (Streamable HTTP).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discover&lt;/strong&gt;: The client asks the server what it offers with &lt;code&gt;tools/list&lt;/code&gt; (and, where relevant, &lt;code&gt;resources/list&lt;/code&gt; and &lt;code&gt;prompts/list&lt;/code&gt;). This is where it receives the &lt;code&gt;calculate&lt;/code&gt; definition above.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Present&lt;/strong&gt;: The host passes the tool names, descriptions, and input schemas to the model alongside your message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decide&lt;/strong&gt;: The model decides a tool would help and produces arguments that match the tool's input schema. For our question, that is a multiply with a = 1250 and b = 12.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confirm&lt;/strong&gt;: The host can ask you to approve the call. The spec expects hosts to keep a human in the loop and let users deny tool calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Call&lt;/strong&gt;: The client sends &lt;code&gt;tools/call&lt;/code&gt; to the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return&lt;/strong&gt;: The server does the work (1,250 × 12 = 15,000) and returns the result. The host adds it to the conversation, and the model writes its answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is step 6 on the wire. Over Streamable HTTP, the client sends this request:&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="nf"&gt;POST&lt;/span&gt; &lt;span class="nn"&gt;/mcp&lt;/span&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="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;Accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;application/json, text/event-stream&lt;/span&gt;
&lt;span class="na"&gt;MCP-Protocol-Version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2026-07-28&lt;/span&gt;
&lt;span class="na"&gt;Mcp-Method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tools/call&lt;/span&gt;
&lt;span class="na"&gt;Mcp-Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;calculate&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"jsonrpc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"method"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tools/call"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"params"&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;"calculate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"arguments"&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;"operation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"multiply"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"b"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&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;"_meta"&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;"io.modelcontextprotocol/protocolVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-07-28"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"io.modelcontextprotocol/clientCapabilities"&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;Two things are worth noticing in that request:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Every request is self-contained.&lt;/strong&gt; Look at the &lt;code&gt;_meta&lt;/code&gt; field carrying the protocol version and client capabilities, plus the &lt;code&gt;Mcp-Method&lt;/code&gt; and &lt;code&gt;Mcp-Name&lt;/code&gt; headers. In older revisions, the client and server first did an &lt;code&gt;initialize&lt;/code&gt; handshake and shared an &lt;code&gt;Mcp-Session-Id&lt;/code&gt;. In 2026-07-28, both are gone. A client that wants to know what a server supports up front can call the new &lt;code&gt;server/discover&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Errors are results, not crashes.&lt;/strong&gt; If the model asks the calculator to divide by zero, the server should return a normal result with &lt;code&gt;isError: true&lt;/code&gt; and a readable message. The model can read it and try again with better arguments.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One Server, Many Clients
&lt;/h2&gt;

&lt;p&gt;Inside a host, each client talks to exactly one server. But the reverse is not true: &lt;strong&gt;a single MCP server can serve many clients at the same time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Take a remote MCP server for your company's billing API. On a normal workday:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Babalola has it connected in Claude Desktop.&lt;/li&gt;
&lt;li&gt;Aina has it connected in Cursor.&lt;/li&gt;
&lt;li&gt;An internal support agent running in the cloud calls it on every ticket.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is three hosts, three separate clients, and one server. Each client discovers the same tools, but each one sends its own requests with its own credentials.&lt;/p&gt;

&lt;p&gt;How the server handles this depends on the transport:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;stdio servers&lt;/strong&gt; are one-to-one by nature. The host launches the server as a subprocess, so every host gets its own private copy of the server process. Three users means three processes. Client and server must be running on the same machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streamable HTTP servers&lt;/strong&gt; are shared. One deployment exposes a single endpoint, like &lt;code&gt;https://billing.example.com/mcp&lt;/code&gt;, and every client sends its requests there.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For remote servers, the 2026-07-28 revision made this a lot easier. Since every request now carries everything the server needs, any request can land on any server instance. You no longer need sticky routing or a shared session store just to keep the protocol working. Put three instances behind a load balancer and let any of them answer.&lt;/p&gt;

&lt;p&gt;What if a tool genuinely needs memory between calls, like a shopping cart or a multi-step booking? State becomes explicit. The tool returns a handle (say, a &lt;code&gt;cartId&lt;/code&gt;), and the client passes that handle back as an argument in later calls. The connection itself is no longer a session.&lt;/p&gt;

&lt;p&gt;The new stateless design makes MCP fits serverless platforms like AWS Lambda, and it is the main subject of Parts 4 and 5.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transports: stdio vs Streamable HTTP
&lt;/h2&gt;

&lt;p&gt;The same JSON-RPC messages can travel over two standard transports. The protocol is identical on both; only the delivery changes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;stdio&lt;/th&gt;
&lt;th&gt;Streamable HTTP&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Where the server runs&lt;/td&gt;
&lt;td&gt;A local subprocess launched by the host&lt;/td&gt;
&lt;td&gt;An independent web service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How messages travel&lt;/td&gt;
&lt;td&gt;Newline-delimited JSON over stdin/stdout&lt;/td&gt;
&lt;td&gt;Each message is its own HTTP &lt;code&gt;POST&lt;/code&gt; to one endpoint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How responses come back&lt;/td&gt;
&lt;td&gt;Written to stdout&lt;/td&gt;
&lt;td&gt;A single JSON response, or an SSE stream scoped to that one request&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Credentials&lt;/td&gt;
&lt;td&gt;Environment variables&lt;/td&gt;
&lt;td&gt;OAuth-based authorization framework&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Local files, CLIs, local databases, development&lt;/td&gt;
&lt;td&gt;Shared, hosted, multi-user servers&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You may also come across tutorials that open a &lt;code&gt;GET /sse&lt;/code&gt; stream on a separate endpoint. That is the older HTTP+SSE transport from the 2024-11-05 revision, and it is now formally deprecated. We will break down HTTP+SSE vs Streamable HTTP properly in Part 4.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;MCP did not make AI agents smarter. It made them connectable.&lt;/p&gt;

&lt;p&gt;With MCP, a service builds one server, and any compliant host can use it. The host stays in control, the model gets a clean menu of tools, and the server does the actual work.&lt;/p&gt;

&lt;p&gt;Next up is Part 2: &lt;strong&gt;MCP vs API&lt;/strong&gt;. If most MCP servers call an API under the hood, do the two complement each other, or is one replacing the other? We’ll break down where they differ and when you need each.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/specification/latest" rel="noopener noreferrer"&gt;Model Context Protocol: official documentation and specification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/changelog" rel="noopener noreferrer"&gt;MCP 2026-07-28 changelog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/basic/transports" rel="noopener noreferrer"&gt;MCP transports (2026-07-28)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/server/tools" rel="noopener noreferrer"&gt;MCP tools specification (2026-07-28)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/news/model-context-protocol" rel="noopener noreferrer"&gt;Anthropic: Introducing the Model Context Protocol&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more articles, follow my social handles:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>aws</category>
      <category>software</category>
    </item>
    <item>
      <title>Migrating a Lambda to a Durable Lambda Function</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Sun, 01 Feb 2026 13:53:04 +0000</pubDate>
      <link>https://dev.to/iamsherif/migrating-a-lambda-to-a-durable-lambda-function-1ki2</link>
      <guid>https://dev.to/iamsherif/migrating-a-lambda-to-a-durable-lambda-function-1ki2</guid>
      <description>&lt;p&gt;I migrated an AWS Lambda function that simulates a patient health insurance verification workflow into a Durable Lambda execution. The function verifies a patient’s insurance and proceeds to schedule a health-check appointment only when the verification succeeds.&lt;/p&gt;

&lt;p&gt;At this point, you probably already understand what AWS Lambda is. This article focuses specifically on what changes when you migrate a Lambda function to a Durable Lambda, why those changes are necessary, and the errors you are likely to encounter if anything is misconfigured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite:&lt;/strong&gt;&lt;br&gt;
You should already understand how AWS Lambda works.&lt;/p&gt;

&lt;p&gt;Before discussing durability, it’s important to understand the workflow itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxyuc4m8q5yft2wxisky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxyuc4m8q5yft2wxisky.png" alt="Workflow illustration" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this flow, we can see that the function goes through a series of sequential steps to complete its work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Validate Patient Information&lt;/strong&gt; - Checks if patient ID and name are provided&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check Insurance Database&lt;/strong&gt; - Simulates lookup in insurance database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify Insurance Coverage&lt;/strong&gt; - Gets coverage details and limits&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorize Health Check Procedures&lt;/strong&gt; - Determines which procedures are covered&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Schedule Health Checks&lt;/strong&gt; - Creates appointment schedule for authorized procedures.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each step depends on the successful completion of the previous one. This dependency chain is what makes durability valuable.&lt;/p&gt;

&lt;p&gt;Before we dive deep, let's talk a bit about Durable Lambda Function.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a Durable Lambda Function?
&lt;/h2&gt;

&lt;p&gt;A Durable Lambda function is still a Lambda function running inside the Lambda runtime. What changes is how execution is managed.&lt;/p&gt;

&lt;p&gt;A durable function can run for up to one year, maintaining progress across failures, restarts, and retries, without incurring wait-time charges. This is achieved through a mechanism called a durable execution.&lt;/p&gt;

&lt;p&gt;A durable execution uses checkpoints to track progress. If a failure occurs, the function is replayed from the beginning, but completed steps are skipped and their results reused.&lt;/p&gt;

&lt;p&gt;Durable Lambda exposes special operations, most notably &lt;code&gt;step&lt;/code&gt; and &lt;code&gt;wait&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;step&lt;/code&gt; executes business logic with built-in progress tracking and replay support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;wait&lt;/code&gt; pauses execution without consuming compute, which is useful for long-running or human-in-the-loop workflows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Lambda vs Durable Lambda?
&lt;/h3&gt;

&lt;p&gt;This is not a replacement. Durable Lambda still runs on Lambda.&lt;br&gt;
What changes is the execution model. Durable Lambda improves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Visibility into execution flow&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recovery from failures&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Retry behavior&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Developer experience when working with long or multi-step workflows&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You are not switching platforms. You are adopting a stricter execution discipline.&lt;/p&gt;

&lt;p&gt;Now that we've had a brief understanding of Durable Lambda function, let's dive into migrating our lambda function to durable lambda.&lt;/p&gt;
&lt;h3&gt;
  
  
  What the Lambda Function Looked Like
&lt;/h3&gt;

&lt;p&gt;Before durability was introduced, the function followed a familiar sequential pattern. Everything happened inside a single invocation, and the only “state” was whatever lived in memory during execution.&lt;/p&gt;

&lt;p&gt;Conceptually, the Lambda looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&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;event&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;patientId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;patientId&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;patientName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Validate patient information&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid patient information&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="c1"&gt;// Check insurance&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasInsurance&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;checkInsuranceStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;hasInsurance&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                    &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;REJECTED&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Patient does not have valid health insurance.&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="c1"&gt;// Verify coverage&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coverage&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;getInsuranceCoverage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Authorize procedures&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authorizedProcedures&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;authorizeHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;coverage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Schedule health checks&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scheduledAppointments&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;scheduleHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nx"&gt;authorizedProcedures&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;APPROVED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;insuranceCoverage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;coverage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;authorizedProcedures&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;scheduledAppointments&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="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ERROR&lt;/span&gt;&lt;span class="dl"&gt;'&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is readable and easy to reason about, but it hides a critical weakness.&lt;/p&gt;

&lt;p&gt;Every step is tightly coupled to the same execution. If the function times out, crashes, or is retried, everything restarts from the beginning. External systems are called again, and partial progress is lost.&lt;/p&gt;

&lt;p&gt;This is the exact problem Durable Lambda solves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introducing Durable Execution
&lt;/h3&gt;

&lt;p&gt;Below is the Durable Lambda version of the same function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&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;withDurableExecution&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;event&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="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="nf"&gt;configureLogger&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;customLogger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;modeAware&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;patientId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;patientId&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;patientName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;try&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;logger&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Step 1: Validating patient information&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;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;patientName&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid patient information&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasInsurance&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;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;validate-patientid&lt;/span&gt;&lt;span class="dl"&gt;'&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;stepContext&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="nx"&gt;stepContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Validating user claims&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;checkInsuranceStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;hasInsurance&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                        &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;REJECTED&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Patient does not have valid health insurance.&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coverage&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;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;verify-insurance&lt;/span&gt;&lt;span class="dl"&gt;'&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;stepContext&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="nx"&gt;stepContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Verify insurance coverage&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;getInsuranceCoverage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&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;authorizedProcedures&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;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;authorize-health-checks&lt;/span&gt;&lt;span class="dl"&gt;'&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;stepContext&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="nx"&gt;stepContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorize health check procedures&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;authorizeHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;coverage&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;scheduledAppointments&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;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;schedule-health-checks&lt;/span&gt;&lt;span class="dl"&gt;'&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;stepContext&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="nx"&gt;stepContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Schedule health checks&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;scheduleHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authorizedProcedures&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                    &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;APPROVED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;insuranceCoverage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;coverage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nx"&gt;authorizedProcedures&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nx"&gt;scheduledAppointments&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="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                    &lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nx"&gt;patientName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ERROR&lt;/span&gt;&lt;span class="dl"&gt;'&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&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="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, the business logic looks almost identical. That similarity is intentional. Durable Lambda is designed so you do not have to rewrite your domain logic from scratch.&lt;/p&gt;

&lt;p&gt;The real change is where durability is introduced.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Actually Changed?
&lt;/h4&gt;

&lt;p&gt;The most important difference is the &lt;code&gt;withDurableExecution&lt;/code&gt; wrapper. This single addition changes the execution model of the function. Instead of treating the handler as a one-shot computation, it turns it into a resumable workflow. The function can now pause, fail, retry, and resume without losing progress.&lt;/p&gt;

&lt;p&gt;The second major change is the introduction of &lt;code&gt;context.step&lt;/code&gt; from DurableContext. In the Lambda, each async call simply executes and returns. In the durable version, every critical operation is wrapped in a named &lt;code&gt;step&lt;/code&gt;. That name is not cosmetic. It becomes the durable checkpoint that allows the runtime to remember, “this work has already been completed.”&lt;/p&gt;

&lt;p&gt;For example, insurance validation used to be just this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;checkInsuranceStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the durable version, it becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;validate-patientid&lt;/span&gt;&lt;span class="dl"&gt;'&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="o"&gt;=&amp;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="nf"&gt;checkInsuranceStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientId&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;This single change prevents duplicate calls when retries happen. If the function crashes after this step succeeds, Durable Lambda does not re-run it. It replays the stored result and moves forward.&lt;/p&gt;

&lt;p&gt;Logging also changes subtly but importantly. Instead of relying on global logging assumptions, logging is now tied to execution context and step context. This is why logging behavior felt different after migration. The function is no longer guaranteed to run once from top to bottom; parts of it may be replayed.&lt;/p&gt;

&lt;p&gt;THAT'S ALL FOR THE FUNCTION CODE REFACTORING&lt;/p&gt;

&lt;h2&gt;
  
  
  Infrastructure Configuration Matters
&lt;/h2&gt;

&lt;p&gt;Durable Lambda is not only about code. It requires explicit infrastructure configuration.&lt;br&gt;
Your lambda function configuration might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;patientHealthCheckFunction&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;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PatientHealthCheckFunction&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;runtime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODEJS_20_X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index.handler&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromAsset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lambda-package&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;NODE_ENV&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;LOG_LEVEL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INFO&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;In the above configuration, the function uses Lambda's NodeJS 20  runtime, identifies the handler, navigates to the function, set timeout limit, and attaches some env variables that would be used by the function code.&lt;br&gt;
When migrating to Durable Lambda, you must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use a supported runtime (Node.js 22 or 24)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assign a role that allows checkpointing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure durableConfig&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use versions and aliases&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Misconfigurations lead directly to runtime errors.&lt;/p&gt;

&lt;p&gt;I will walk you through actual errors that occurs when your durable function isn't configured properly and also we going to discuss each of their fixes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #1: Durable Execution Would Not Start&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first failure happened immediately after deployment:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Unexpected payload provided to start the durable execution. Check your resource configurations to confirm the durability is set.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This error had nothing to do with business logic. Durable Lambda requires its configuration to be explicitly enabled in infrastructure. Without that configuration, the runtime treats the function like a normal Lambda and rejects the durable execution payload.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;durableConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;executionTimeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hours&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="nx"&gt;retentionPeriod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;days&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&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;Once configured with an execution timeout and retention period, the function was able to start durable execution correctly.&lt;/p&gt;

&lt;p&gt;This was the first signal that Durable Lambda is not just a code change; it is an execution contract enforced at the infrastructure level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #2: Synchronous Invocation Still Has Limits&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After enabling durability, the next error appeared:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You cannot synchronously invoke a durable function with an &lt;code&gt;executionTimeout&lt;/code&gt; greater than 15 minutes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When invoked synchronously, a durable function must still complete within 15 minutes. Reducing the execution timeout resolved the issue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;durableConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;executionTimeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;minutes&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="nx"&gt;retentionPeriod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;days&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&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;This reinforced an important point: Durable Lambda adds persistence, not infinite runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error #3: Permission Error&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next failure was caused by permission error:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Failed to checkpoint durable execution.  User is not authorized to perform &lt;code&gt;lambda:CheckpointDurableExecution&lt;/code&gt; on resource &lt;code&gt;arn:aws:…&lt;/code&gt; because no identity-based policy allows the &lt;code&gt;lambda:CheckpointDurableExecution&lt;/code&gt; action&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Durable Lambda requires explicit IAM permissions to store and retrieve execution state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;lambdaRole&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addToPolicy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;iam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PolicyStatement&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;actions&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="s1"&gt;lambda:CheckpointDurableExecution&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;lambda:GetDurableExecutionState&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;lambda:InvokeFunction&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;resources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="s2"&gt;`arn:aws:lambda:&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;region&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:function:PatientHealthCheckStack*`&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without these permissions, durability silently fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed after migration
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After Durable Lambda&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;State handling&lt;/td&gt;
&lt;td&gt;Stateless&lt;/td&gt;
&lt;td&gt;Persistent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Retries&lt;/td&gt;
&lt;td&gt;Restart entire flow&lt;/td&gt;
&lt;td&gt;Resume from failure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Invocation rules&lt;/td&gt;
&lt;td&gt;Flexible&lt;/td&gt;
&lt;td&gt;Strict but safer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Versioning&lt;/td&gt;
&lt;td&gt;Optional&lt;/td&gt;
&lt;td&gt;Required&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Observability&lt;/td&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;Needs discipline&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Migrating to Durable Lambda did not make the system simpler; it made it more explicit.&lt;/p&gt;

&lt;p&gt;Failures stopped being destructive. Retries stopped being accidental. Progress became something the system could reason about instead of guess. The workflow shifted from “hope this finishes” to “this will eventually complete correctly.”&lt;/p&gt;

&lt;p&gt;Durable Lambda is not something you reach for by default. But when your Lambda function starts behaving like a workflow—multi-step, failure-prone, and externally dependent, durability stops being optional.&lt;/p&gt;

&lt;p&gt;At that point, it becomes a design decision about correctness.&lt;/p&gt;

&lt;p&gt;And in systems like healthcare workflows, correctness is the only acceptable outcome.&lt;/p&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more articles, follow my social handles:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>lambda</category>
      <category>serverless</category>
      <category>aws</category>
      <category>programming</category>
    </item>
    <item>
      <title>A Step-by-Step Guide to Deploying CrewAI on Amazon Bedrock AgentCore</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Sun, 03 Aug 2025 21:12:02 +0000</pubDate>
      <link>https://dev.to/iamsherif/a-step-by-step-guide-to-deploying-crewai-on-amazon-bedrock-agentcore-293n</link>
      <guid>https://dev.to/iamsherif/a-step-by-step-guide-to-deploying-crewai-on-amazon-bedrock-agentcore-293n</guid>
      <description>&lt;p&gt;In 2024, I built &lt;a href="https://main.dumvtvqtcpc4p.amplifyapp.com/" rel="noopener noreferrer"&gt;Curiouser&lt;/a&gt; an agent-to-agent (A2A) application using &lt;a href="https://crewai.com/" rel="noopener noreferrer"&gt;CrewAI&lt;/a&gt; with the Ollama LLM. It was my first real experience orchestrating multiple agents in a single app. As someone curious about agentic frameworks, CrewAI felt intuitive and developer-friendly.&lt;/p&gt;

&lt;p&gt;But I ran into limitations. I was running the application locally on my 8GB RAM AMD Ryzen laptop with a 256GB SSD, and it will take an average of 2–3 hours to complete a run (no bluff). Plus, I couldn’t take it beyond my local machine.&lt;/p&gt;

&lt;p&gt;Then AWS announced &lt;strong&gt;Amazon Bedrock AgentCore&lt;/strong&gt; at the New York Summit — and it felt like it was built for people like me. It's a &lt;strong&gt;serverless runtime&lt;/strong&gt; for deploying and operating AI agents securely at scale, using any framework, including CrewAI, LangGraph, LlamaIndex, and Strands Agents, as well as any foundation model in or outside of Amazon Bedrock, without managing infrastructure. So I decided to migrate my local CrewAI app to production using this new service.&lt;/p&gt;

&lt;p&gt;This blog post is a step-by-step guide for doing exactly that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This guide assumes you already have a working CrewAI application. I’ll only walk you through the changes needed to get it running on Bedrock AgentCore.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What I Built
&lt;/h3&gt;

&lt;p&gt;I built &lt;strong&gt;Curiouser&lt;/strong&gt; — a multi-agent AI application designed for curious minds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It provides detailed yet concise summaries of tech topics.&lt;/li&gt;
&lt;li&gt;It generates test questions to help you evaluate your understanding.&lt;/li&gt;
&lt;li&gt;It uses three cooperating agents, each with a different role.&lt;/li&gt;
&lt;li&gt;I switched from Ollama to the Amazon Bedrock Nova Pro model.&lt;/li&gt;
&lt;li&gt;It also stores user-generated content in Amazon S3.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;To follow along, you'll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A working CrewAI app&lt;/li&gt;
&lt;li&gt;An AWS account with access to:

&lt;ul&gt;
&lt;li&gt;Amazon Bedrock&lt;/li&gt;
&lt;li&gt;Bedrock AgentCore&lt;/li&gt;
&lt;li&gt;S3&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Python 3.10+&lt;/li&gt;

&lt;li&gt;Docker installed and running&lt;/li&gt;

&lt;li&gt;AWS CLI installed and configured&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;bedrock-agentcore&lt;/code&gt; and &lt;code&gt;bedrock-agentcore-starter-toolkit&lt;/code&gt; Python packages&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1 - Update Your Agents to Use a Bedrock-Supported LLM
&lt;/h3&gt;

&lt;p&gt;Bedrock AgentCore supports only Amazon Bedrock-compatible foundational models. You’ll need to update your CrewAI agents to use one of these.&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html" rel="noopener noreferrer"&gt;supported models here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 - Create a Remote Entrypoint for Bedrock AgentCore
&lt;/h3&gt;

&lt;p&gt;We'll convert your local app into a remote one by modifying the entrypoint. Here's what to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Import AgentCore:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;bedrock_agentcore.runtime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BedrockAgentCoreApp&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Initialize the runtime app:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BedrockAgentCoreApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Define the entrypoint handler:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="nd"&gt;@app.entrypoint&lt;/span&gt;
   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;app_entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
       &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Handle agent invocations&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
       &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
           &lt;span class="n"&gt;user_message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Web3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;crew&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;kickoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inputs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;topic&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user_message&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
       &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run the app:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AgentCore automatically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sets up an HTTP server on port 8080&lt;/li&gt;
&lt;li&gt;Exposes &lt;code&gt;/invocations&lt;/code&gt; and &lt;code&gt;/ping&lt;/code&gt; endpoints&lt;/li&gt;
&lt;li&gt;Manages content types, responses, and errors&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 3 - Configure IAM Role for AgentCore
&lt;/h3&gt;

&lt;p&gt;You’ll need a dedicated IAM role that allows your agent to run in the cloud. Below is a Bash script I wrote to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a trust policy&lt;/li&gt;
&lt;li&gt;Create permissions policy&lt;/li&gt;
&lt;li&gt;Attach the permissions policy&lt;/li&gt;
&lt;li&gt;Grant access to ECR, Bedrock Agentcore, and Bedrock&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The script also configures your agent with AgentCore:&lt;br&gt;
&lt;code&gt;agentcore configure --entrypoint src/curiouser/main.py -er &amp;lt;ROLE_ARN&amp;gt;&lt;/code&gt;&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;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# Setup script for CrewAI with Amazon Bedrock AgentCore&lt;/span&gt;
&lt;span class="c"&gt;# This script creates the necessary IAM role and configures agentcore&lt;/span&gt;

&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt;  &lt;span class="c"&gt;# Exit on any error&lt;/span&gt;

&lt;span class="c"&gt;# Configuration variables&lt;/span&gt;
&lt;span class="nv"&gt;ROLE_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Curioser-CrewAI-BedrockAgentCore-Role"&lt;/span&gt;
&lt;span class="nv"&gt;POLICY_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Curioser-CrewAI-BedrockAgentCore-Policy"&lt;/span&gt;
&lt;span class="nv"&gt;TRUST_POLICY_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"trust-policy.json"&lt;/span&gt;
&lt;span class="nv"&gt;PERMISSIONS_POLICY_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"permissions-policy.json"&lt;/span&gt;
&lt;span class="nv"&gt;ENTRYPOINT_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"src/curiouser/main.py"&lt;/span&gt;


&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'\033[0m'&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"Setting up CrewAI with Amazon Bedrock AgentCore&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Check if AWS CLI is installed and configured&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; aws &amp;amp;&amp;gt; /dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"❌ AWS CLI is not installed. Please install it first.&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# Get AWS account ID and region&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"📋 Getting AWS account information...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;ACCOUNT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws sts get-caller-identity &lt;span class="nt"&gt;--query&lt;/span&gt; Account &lt;span class="nt"&gt;--output&lt;/span&gt; text&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws configure get region&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"⚠️  No default region set. Using us-east-1&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nv"&gt;REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;
&lt;span class="k"&gt;fi

&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"✓ Account ID: &lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"✓ Region: &lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Create trust policy for the IAM role&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"📝 Creating trust policy..."&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$TRUST_POLICY_FILE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AssumeRolePolicy",
      "Effect": "Allow",
      "Principal": {
        "Service": "bedrock-agentcore.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
            "StringEquals": {
                "aws:SourceAccount": "&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;"
            },
            "ArnLike": {
                "aws:SourceArn": "arn:aws:bedrock-agentcore:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:*"
            }
       }
    }
  ]
}
&lt;/span&gt;&lt;span class="no"&gt;
EOF

&lt;/span&gt;&lt;span class="c"&gt;# Create permissions policy with dynamic values&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"📝 Creating permissions policy..."&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$PERMISSIONS_POLICY_FILE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ECRImageAccess",
            "Effect": "Allow",
            "Action": [
                "ecr:BatchGetImage",
                "ecr:GetDownloadUrlForLayer"
            ],
            "Resource": [
                "arn:aws:ecr:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:repository/*"
            ]        
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:DescribeLogStreams",
                "logs:CreateLogGroup"
            ],
            "Resource": [
                "arn:aws:logs:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:log-group:/aws/bedrock-agentcore/runtimes/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:DescribeLogGroups"
            ],
            "Resource": [
                "arn:aws:logs:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:log-group:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:log-group:/aws/bedrock-agentcore/runtimes/*:log-stream:*"
            ]
        },
        {
            "Sid": "ECRTokenAccess",
            "Effect": "Allow",
            "Action": [
                "ecr:GetAuthorizationToken"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow", 
            "Action": [ 
                "xray:PutTraceSegments", 
                "xray:PutTelemetryRecords", 
                "xray:GetSamplingRules", 
                "xray:GetSamplingTargets"
            ],
            "Resource": [ "*" ] 
        },
        {
            "Effect": "Allow",
            "Resource": "*",
            "Action": "cloudwatch:PutMetricData",
            "Condition": {
                "StringEquals": {
                    "cloudwatch:namespace": "bedrock-agentcore"
                }
            }
        },
        {
            "Sid": "GetAgentAccessToken",
            "Effect": "Allow",
            "Action": [
                "bedrock-agentcore:GetWorkloadAccessToken",
                "bedrock-agentcore:GetWorkloadAccessTokenForJWT",
                "bedrock-agentcore:GetWorkloadAccessTokenForUserId"
            ],
            "Resource": [
                "arn:aws:bedrock-agentcore:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:workload-identity-directory/default",
                "arn:aws:bedrock-agentcore:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:workload-identity-directory/default/workload-identity/agentName-*"
            ]
        },
        {
            "Sid": "BedrockModelInvocation", 
            "Effect": "Allow", 
            "Action": [ 
                "bedrock:InvokeModel", 
                "bedrock:InvokeModelWithResponseStream"
            ], 
            "Resource": [
                "arn:aws:bedrock:*::foundation-model/*",
                "arn:aws:bedrock:&lt;/span&gt;&lt;span class="nv"&gt;$REGION&lt;/span&gt;&lt;span class="sh"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$ACCOUNT_ID&lt;/span&gt;&lt;span class="sh"&gt;:*"
            ]
        }
    ]
}
&lt;/span&gt;&lt;span class="no"&gt;EOF

&lt;/span&gt;&lt;span class="c"&gt;# Check if role already exists&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"🔍 Checking if IAM role exists...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;aws iam get-role &lt;span class="nt"&gt;--role-name&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt; &amp;amp;&amp;gt; /dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"⚠️  Role &lt;/span&gt;&lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt;&lt;span class="s2"&gt; already exists. Updating policies...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="c"&gt;# Update the role's trust policy&lt;/span&gt;
    aws iam update-assume-role-policy &lt;span class="nt"&gt;--role-name&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt; &lt;span class="nt"&gt;--policy-document&lt;/span&gt; file://&lt;span class="nv"&gt;$TRUST_POLICY_FILE&lt;/span&gt;

    &lt;span class="c"&gt;# Delete existing inline policy if it exists&lt;/span&gt;
    aws iam delete-role-policy &lt;span class="nt"&gt;--role-name&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt; &lt;span class="nt"&gt;--policy-name&lt;/span&gt; &lt;span class="nv"&gt;$POLICY_NAME&lt;/span&gt; &amp;amp;&amp;gt; /dev/null &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"🔨 Creating IAM role..."&lt;/span&gt;
    aws iam create-role &lt;span class="se"&gt;\&lt;/span&gt;
        &lt;span class="nt"&gt;--role-name&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
        &lt;span class="nt"&gt;--assume-role-policy-document&lt;/span&gt; file://&lt;span class="nv"&gt;$TRUST_POLICY_FILE&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
        &lt;span class="nt"&gt;--description&lt;/span&gt; &lt;span class="s2"&gt;"IAM role for CrewAI with Bedrock AgentCore"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# Attach the permissions policy&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;YELLOW&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;📎 Attaching permissions policy...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
aws iam put-role-policy &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--role-name&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--policy-name&lt;/span&gt; &lt;span class="nv"&gt;$POLICY_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--policy-document&lt;/span&gt; file://&lt;span class="nv"&gt;$PERMISSIONS_POLICY_FILE&lt;/span&gt;

&lt;span class="c"&gt;# Get the role ARN&lt;/span&gt;
&lt;span class="nv"&gt;ROLE_ARN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aws iam get-role &lt;span class="nt"&gt;--role-name&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_NAME&lt;/span&gt; &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s1"&gt;'Role.Arn'&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="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"✓ IAM Role ARN: &lt;/span&gt;&lt;span class="nv"&gt;$ROLE_ARN&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Check if src/curiouser/main.py exists&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ENTRYPOINT_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"✓ Entrypoint file &lt;/span&gt;&lt;span class="nv"&gt;$ENTRYPOINT_FILE&lt;/span&gt;&lt;span class="s2"&gt; already exists and is configured for Bedrock AgentCore"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"❌ Entrypoint file &lt;/span&gt;&lt;span class="nv"&gt;$ENTRYPOINT_FILE&lt;/span&gt;&lt;span class="s2"&gt; not found. Please ensure your CrewAI project structure is correct."&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# Wait a moment for IAM role to propagate&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"⏳ Waiting for IAM role to propagate..."&lt;/span&gt;
&lt;span class="nb"&gt;sleep &lt;/span&gt;10

&lt;span class="c"&gt;# Configure agentcore&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"🔧 Configuring agentcore..."&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; agentcore &amp;amp;&amp;gt; /dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;agentcore configure &lt;span class="nt"&gt;--entrypoint&lt;/span&gt; &lt;span class="nv"&gt;$ENTRYPOINT_FILE&lt;/span&gt; &lt;span class="nt"&gt;-er&lt;/span&gt; &lt;span class="nv"&gt;$ROLE_ARN&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"✓ AgentCore configured successfully!"&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"❌ agentcore command not found. Please install the Bedrock AgentCore CLI first."&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"💡 You can install it with: pip install bedrock-agentcore-cli"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"📋 Manual configuration command:"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"agentcore configure --entrypoint &lt;/span&gt;&lt;span class="nv"&gt;$ENTRYPOINT_FILE&lt;/span&gt;&lt;span class="s2"&gt; -er &lt;/span&gt;&lt;span class="nv"&gt;$ROLE_ARN&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Attach the policy that your project needs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step 4 - Generate Docker Configuration with AgentCore command
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p8cz0ee3hhdz6wn8mkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p8cz0ee3hhdz6wn8mkg.png" alt="AgentCore Configure" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;agentcore configure &lt;span class="nt"&gt;--entrypoint&lt;/span&gt; src/curiouser/main.py &lt;span class="nt"&gt;-er&lt;/span&gt; &amp;lt;ROLE_ARN&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate a Dockerfile and &lt;code&gt;.bedrock_agentcore.yaml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a .bedrock_agentcore.yaml configuration file&lt;/li&gt;
&lt;li&gt;Prepare our application for containerization&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Important Fix
&lt;/h4&gt;

&lt;p&gt;The generated Dockerfile doesn’t install &lt;code&gt;bedrock_agentcore&lt;/code&gt;, so be sure to add else you will run into a dependency error:&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;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;bedrock_agentcore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Dockerfile should look like this:&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="s"&gt; public.ecr.aws/docker/library/python:3.10-slim&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&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;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; .
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;bedrock_agentcore
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;aws-opentelemetry-distro&amp;gt;&lt;span class="o"&gt;=&lt;/span&gt;0.10.0

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; AWS_REGION=&amp;lt;your-region&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; AWS_DEFAULT_REGION=&amp;lt;your-region&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; DOCKER_CONTAINER=1&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;useradd &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; 1000 bedrock_agentcore
&lt;span class="k"&gt;USER&lt;/span&gt;&lt;span class="s"&gt; bedrock_agentcore&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 8080&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["opentelemetry-instrument", "python", "-m", "src.app.main"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5 - Launch the Agent to the Cloud
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fblu7djvek0c2yi3yfp7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fblu7djvek0c2yi3yfp7r.png" alt="Launch the Agent to the Cloud" width="800" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once everything is ready, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;agentcore launch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build the Docker image&lt;/li&gt;
&lt;li&gt;Push it to Amazon ECR&lt;/li&gt;
&lt;li&gt;Create a Bedrock AgentCore runtime&lt;/li&gt;
&lt;li&gt;And deploy your agent to the cloud&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 6 - Test Your Deployed Agent
&lt;/h3&gt;

&lt;p&gt;Use the CLI to invoke your agent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;agentcore invoke &lt;span class="s1"&gt;'{"prompt": "Hello"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or test directly from the AWS Console.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;That’s it, you’ve just seen how to take a multi-agent CrewAI application from local development to a cloud-native, production-ready deployment using Amazon Bedrock AgentCore.&lt;/p&gt;

&lt;p&gt;Personally, moving from a painfully slow, local setup on limited hardware to a serverless runtime that scales, monitors, and secures my workload automatically was a game-changer. No more babysitting long processes or worrying about whether my laptop will crash before the task finishes. With Amazon Bedrock AgentCore, deployment is fast, observability is built-in, and your agentic logic becomes accessible from anywhere, anytime.&lt;/p&gt;

&lt;p&gt;For developers building serious agentic applications, especially multi-agent systems with orchestration and external data workflows. Amazon Bedrock AgentCore unlocks scalability and reliability without the traditional ops overhead. And because it’s part of the AWS ecosystem, integrating other services like S3, CloudWatch, and IAM is straightforward and secure.&lt;/p&gt;

&lt;p&gt;Whether you’re:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building a knowledge assistant like &lt;a href="https://main.dumvtvqtcpc4p.amplifyapp.com/" rel="noopener noreferrer"&gt;Curiouser&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;Orchestrating tools and LLMs across complex workflows,&lt;/li&gt;
&lt;li&gt;Experimenting with autonomous agents in a safe and scalable environment,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon Bedrock AgentCore gives you a strong foundation to focus on the intelligence of your application, not the plumbing.&lt;/p&gt;

&lt;p&gt;If you’ve already got a local CrewAI project up and running, there’s no better time to bring it to life in the cloud.&lt;/p&gt;

&lt;p&gt;Let me know if you try this out or run into any blockers — always happy to connect with fellow builders.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/bedrock-agentcore/" rel="noopener noreferrer"&gt;Amazon Bedrock AgentCore Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/awslabs/amazon-bedrock-agentcore-samples.git" rel="noopener noreferrer"&gt;Amazon Bedrock AgentCore GitHub Samples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html" rel="noopener noreferrer"&gt;Supported Foundation Models on Bedrock&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.crewai.com/en/introduction" rel="noopener noreferrer"&gt;CrewAI Framework Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html" rel="noopener noreferrer"&gt;Amazon Bedrock Developer Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more articles, follow my social handles:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>bedrockagentcore</category>
      <category>crewai</category>
      <category>aws</category>
    </item>
    <item>
      <title>How to capture data changes in DynamoDB using Streams and Lambda (Node.js + AWS CDK)</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Tue, 15 Jul 2025 00:18:34 +0000</pubDate>
      <link>https://dev.to/iamsherif/how-to-capture-data-changes-in-dynamodb-using-streams-and-lambda-nodejs-aws-cdk-4n9n</link>
      <guid>https://dev.to/iamsherif/how-to-capture-data-changes-in-dynamodb-using-streams-and-lambda-nodejs-aws-cdk-4n9n</guid>
      <description>&lt;p&gt;One of the biggest advantages of serverless services is their event-driven nature. When something (an event) happens, another service reacts. DynamoDB is a serverless NoSQL database that fits perfectly into this pattern. It allows you to build scalable, event-driven applications that respond to changes in your data in near real time.&lt;/p&gt;

&lt;p&gt;In this article, I’ll show you how to capture data changes in DynamoDB using DynamoDB Streams, and then use the stream as an event source to a Lambda function, which then logs the stream information to CloudWatch Logs, all implemented using Node.js and AWS CDK as Iac.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Capture Data Changes?
&lt;/h3&gt;

&lt;p&gt;Before we dive into the implementation, let’s consider a few use cases where capturing data changes can be valuable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Audit logging: Keep track of item-level changes for compliance or debugging.&lt;/li&gt;
&lt;li&gt;Triggering side effects: Send notifications, update search indexes, or replicate data in real time.&lt;/li&gt;
&lt;li&gt;Analytics: Track user behavior or system events as they happen.&lt;/li&gt;
&lt;li&gt;Data synchronization: Sync changes between microservices or external systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How DynamoDB Streams Work
&lt;/h3&gt;

&lt;p&gt;When you enable Streams on a DynamoDB table, DynamoDB records every item-level change (creates, updates, and deletes) in a time-ordered sequence.&lt;/p&gt;

&lt;p&gt;Each stream record contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The primary key of the modified item&lt;/li&gt;
&lt;li&gt;Metadata about the operation (INSERT, MODIFY, REMOVE)&lt;/li&gt;
&lt;li&gt;Optional “before” and “after” images of the data (if configured)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These stream records are stored for up to 24 hours and can be read by AWS services like Lambda, which you can set up to react to each change automatically.&lt;/p&gt;

&lt;h3&gt;
  
  
  What We’ll Build
&lt;/h3&gt;

&lt;p&gt;We’ll create:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A DynamoDB table with Streams enabled&lt;/li&gt;
&lt;li&gt;A Lambda function that listens to the stream&lt;/li&gt;
&lt;li&gt;Logging of the change details to CloudWatch Logs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  So Let’s Get Started
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Define a DynamoDB Table with Stream Enabled
&lt;/h4&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;AttributeType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;StreamViewType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Table&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;aws-cdk-lib/aws-dynamodb&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;table&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;Table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MyTable&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;partitionKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AttributeType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STRING&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;StreamViewType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEW_AND_OLD_IMAGES&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Enables streams with both before/after images&lt;/span&gt;
  &lt;span class="c1"&gt;// Other configuration&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Stream View Types
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;StreamViewType&lt;/code&gt; determines what data is recorded in the stream for each item change:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;KEYS_ONLY&lt;/code&gt; – Only the primary key attributes are written to the stream.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NEW_IMAGE&lt;/code&gt; – The entire item, as it appears after the modification, is written to the stream.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;OLD_IMAGE&lt;/code&gt; – The item as it appeared before the modification is written to the stream.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NEW_AND_OLD_IMAGES&lt;/code&gt; – Both the new and old versions of the item are included.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Create a Lambda Function to Handle Stream Events
&lt;/h4&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="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Code&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;aws-cdk-lib/aws-lambda&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;LambdaIntegration&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;aws-cdk-lib/aws-apigateway&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;path&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;path&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;streamHandler&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;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;StreamHandlerFunction&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;runtime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODEJS_20_X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index.handler&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromAsset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../lambda&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;&lt;strong&gt;Sample &lt;code&gt;index.js&lt;/code&gt; Lambda code:&lt;/strong&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;unmarshall&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;@aws-sdk/util-dynamodb&lt;/span&gt;&lt;span class="dl"&gt;'&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;handler&lt;/span&gt; &lt;span class="o"&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;event&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="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;record&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Records&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;newImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dynamodb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NewImage&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;unmarshall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dynamodb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NewImage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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;oldImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dynamodb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OldImage&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;unmarshall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dynamodb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OldImage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Event Type:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eventName&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New Image:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newImage&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Old Image:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldImage&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&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;h4&gt;
  
  
  Why do we use &lt;code&gt;unmarshall&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;When DynamoDB Streams triggers our Lambda function, it passes the item images in DynamoDB JSON format, which looks like this:&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;"id"&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;"S"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"asdf"&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;"uuid"&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;"S"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"foo"&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;"status"&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;"S"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"new"&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;To work with standard JavaScript objects, we use the &lt;code&gt;unmarshall&lt;/code&gt; utility from &lt;code&gt;@aws-sdk/util-dynamodb&lt;/code&gt;. This transforms the DynamoDB JSON into a regular JavaScript object:&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;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"asdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"uuid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"foo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"new"&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;This makes it easier to log or manipulate the data in our code.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Connect the Stream to Lambda
&lt;/h4&gt;

&lt;p&gt;To allow our Lambda function to process events from the DynamoDB stream, we need to do two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Grant the Lambda the proper execution role permission to read from the stream&lt;/li&gt;
&lt;li&gt;Register the DynamoDB table as an event source
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Grant the Lambda the proper execution role permission to read from the stream&lt;/span&gt;
&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;grantStreamRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;streamHandler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Attach DynamoDB stream as an event source&lt;/span&gt;
&lt;span class="nx"&gt;streamHandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventSource&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;DynamoEventSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;startingPosition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;StartingPosition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;LATEST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;batchSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;retryAttempts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&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;h4&gt;
  
  
  Configuration Options
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;startingPosition&lt;/code&gt; – Defines where the Lambda function should start reading the stream (e.g., &lt;code&gt;LATEST&lt;/code&gt; for new records only).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;batchSize&lt;/code&gt; – The maximum number of records to send to the function in a single invocation. The Lambda will receive all these records in the event payload.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;retryAttempts&lt;/code&gt; – The maximum number of times Lambda will retry a failed batch before discarding or sending it to a dead-letter destination (if configured).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By using DynamoDB Streams, you can build powerful real-time event-driven systems with minimal operational overhead. In this example, we simply logged data changes to CloudWatch, but you can extend this to trigger notifications, sync systems, or persist audit logs to S3.&lt;/p&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more articles, follow my social handles:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>dynamodb</category>
      <category>lambda</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Deploying a Static E-commerce Site to AWS Using Pulumi</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Sat, 05 Apr 2025 20:47:40 +0000</pubDate>
      <link>https://dev.to/iamsherif/deploying-a-static-e-commerce-site-to-aws-using-pulumi-1nlf</link>
      <guid>https://dev.to/iamsherif/deploying-a-static-e-commerce-site-to-aws-using-pulumi-1nlf</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pulumi"&gt;Pulumi Deploy and Document Challenge&lt;/a&gt;: Fast Static Website Deployment&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I built and deployed &lt;strong&gt;Ticaz Bags &amp;amp; Luggage&lt;/strong&gt;, a sleek and modern static e-commerce website where users can browse and shop for stylish bags and durable luggage. The website features clean UI, responsive design, and smooth navigation, all tailored to create an enjoyable online shopping experience.&lt;/p&gt;

&lt;p&gt;To bring this project to life, I used Pulumi to set up the entire cloud infrastructure on AWS from scratch. This includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;strong&gt;S3 bucket&lt;/strong&gt; for hosting the static build&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;CloudFront distribution&lt;/strong&gt; for fast and secure global content delivery&lt;/li&gt;
&lt;li&gt;Proper &lt;strong&gt;IAM roles and bucket policies&lt;/strong&gt; for access control and caching&lt;/li&gt;
&lt;li&gt;A well-structured &lt;strong&gt;Pulumi&lt;/strong&gt; stack for consistent, repeatable deployments
&lt;em&gt;All of which are fully-managed by &lt;strong&gt;Pulumi&lt;/strong&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The site was developed using &lt;strong&gt;React&lt;/strong&gt;, &lt;strong&gt;Vite&lt;/strong&gt;, and &lt;strong&gt;Tailwind CSS&lt;/strong&gt;, offering fast performance and responsive design.&lt;/p&gt;

&lt;p&gt;This project was both a dev and DevOps learning experience, combining frontend polish with cloud-native deployment!&lt;/p&gt;

&lt;p&gt;In this post, I’ll walk you through my journey and how you, too, can deploy a static website to &lt;strong&gt;AWS&lt;/strong&gt; using &lt;strong&gt;Pulumi as Infrastructure as Code (IaC)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Demo Link
&lt;/h2&gt;

&lt;p&gt;Access the live site via the CDN link below:&lt;br&gt;
-&amp;gt;  &lt;a href="https://dyk9aqch11ytc.cloudfront.net/" rel="noopener noreferrer"&gt;https://dyk9aqch11ytc.cloudfront.net/&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Project Repo
&lt;/h2&gt;

&lt;p&gt;🔗 &lt;a href="https://github.com/iAmSherifCodes/TicazOnAWSPulumi.git" rel="noopener noreferrer"&gt;GitHub – Ticaz Bags &amp;amp; Luggage&lt;/a&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The repo includes the full frontend source code and the Pulumi configuration used to deploy it. The README includes setup instructions and deployment steps.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  My Journey
&lt;/h2&gt;

&lt;p&gt;Before this challenge, I already had the &lt;strong&gt;Ticaz Bags &amp;amp; Luggage&lt;/strong&gt; website built, but it hadn’t yet been deployed to AWS. I discovered the &lt;a href="https://www.pulumi.com/templates/static-website/aws/" rel="noopener noreferrer"&gt;Pulumi Static Website Template for AWS&lt;/a&gt; and followed the guide to get everything deployed smoothly.&lt;/p&gt;

&lt;p&gt;Along the way, I learned that there are &lt;strong&gt;two main ways&lt;/strong&gt; to connect your static build to your Pulumi project:&lt;/p&gt;
&lt;h3&gt;
  
  
  ✅ Option 1: Use &lt;code&gt;pulumi config set path&lt;/code&gt; via CLI
&lt;/h3&gt;

&lt;p&gt;This method lets you set the path to your static build folder (like &lt;code&gt;dist/&lt;/code&gt;) using the CLI. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pulumi config &lt;span class="nb"&gt;set &lt;/span&gt;path /home/user/Documents/codes/frontend/dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;💡 In my case, I first ran &lt;code&gt;npm run build&lt;/code&gt; inside the frontend project, which generated the &lt;code&gt;/dist&lt;/code&gt; folder.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This command updates your &lt;code&gt;Pulumi.&amp;lt;stack-name&amp;gt;.yaml&lt;/code&gt; file, and Pulumi uses that path when deploying to S3.&lt;br&gt;&lt;br&gt;
It’s quick and easy, but note that &lt;strong&gt;your frontend code stays outside&lt;/strong&gt; the Pulumi project. So while your build is deployed, your local project structure remains disconnected.&lt;/p&gt;


&lt;h3&gt;
  
  
  ✅ Option 2: Move the frontend into your Pulumi project
&lt;/h3&gt;

&lt;p&gt;With this approach, I moved the built frontend folder into the Pulumi project directory (e.g., &lt;code&gt;www/frontend/dist&lt;/code&gt;) and &lt;strong&gt;manually edited&lt;/strong&gt; the Pulumi YAML config like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;&amp;lt;stack-name&amp;gt;:path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;www/frontend/dist&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allowed me to &lt;strong&gt;keep my infrastructure and app code together&lt;/strong&gt;, making it easier to maintain and understand everything in one place.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠My Decision
&lt;/h3&gt;

&lt;p&gt;I tested &lt;strong&gt;both approaches&lt;/strong&gt;, and while they both worked, I ultimately chose the &lt;strong&gt;second method&lt;/strong&gt;. Here's why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I had better control over the deployment&lt;/li&gt;
&lt;li&gt;My infrastructure and frontend code lived together in one repo&lt;/li&gt;
&lt;li&gt;I could track everything more cleanly with version control&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It gave me a clearer understanding of how Pulumi interacts with the application build and made debugging and updating easier going forward.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoulvpwugli5mb2t7flf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoulvpwugli5mb2t7flf.png" alt="Different ways to deploy your static website to aws using pulumi" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Pulumi
&lt;/h2&gt;

&lt;p&gt;Pulumi made the deployment process seamless, structured, and developer-friendly. I didn’t have to worry about manually setting up S3 buckets, configuring IAM permissions, or writing extensive boilerplate IaC code from scratch.&lt;/p&gt;

&lt;p&gt;Here’s how I used Pulumi in this project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Infrastructure as Code:&lt;/strong&gt; I provisioned AWS resources like S3 and CloudFront using Pulumi’s TypeScript SDK. Everything was version-controlled and easy to manage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple Configuration:&lt;/strong&gt; My main task was linking the application’s build folder (the &lt;code&gt;/dist&lt;/code&gt; directory) to the Pulumi project. Once connected, Pulumi handled the rest—uploading the files, configuring the CDN, and setting proper access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automation:&lt;/strong&gt; With just one command (&lt;code&gt;pulumi up&lt;/code&gt;), I could deploy changes, test updates, or even roll back &lt;code&gt;pulumi cancel&lt;/code&gt; when needed—no AWS Console clicking required.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Pulumi enabled me to streamline deployment without getting entangled in low-level infrastructure tasks. It’s a powerful tool for full-stack and solo developers who want to manage cloud infrastructure with familiar programming languages and clean, version-controlled code.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>pulumichallenge</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
    <item>
      <title>How to set up CORS in AWS Lambda and API Gateway (RestApi)</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Thu, 06 Feb 2025 15:25:47 +0000</pubDate>
      <link>https://dev.to/iamsherif/how-to-set-up-cors-in-aws-lambda-and-api-gateway-restapi-34a2</link>
      <guid>https://dev.to/iamsherif/how-to-set-up-cors-in-aws-lambda-and-api-gateway-restapi-34a2</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7oy3jo93ltizq88s9fx8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7oy3jo93ltizq88s9fx8.png" alt="How to set up CORS in AWS Lambda and API Gateway (RestApi)" width="800" height="240"&gt;&lt;/a&gt;Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers that restricts how resources on a web server can be requested from  a different domain. When building serverless applications using AWS Lambda and API Gateway, you need to configure CORS properly to allow client applications from different origins to access your API.&lt;/p&gt;

&lt;p&gt;CORS is enforced at the browser level. When you deploy a REST API service to a domain, the browser must agree to the service's terms before communicating with it.&lt;/p&gt;

&lt;p&gt;Imagine you have a Lambda backend service exposed through API Gateway's REST API. You integrate this API into your client application using communication services like &lt;code&gt;Axios&lt;/code&gt; or JavaScript's &lt;code&gt;fetch&lt;/code&gt;. You expect it to work smoothly because you've tested it with API testing tools such as Postman or even the AWS Management Console. But then &lt;em&gt;poof!&lt;/em&gt; a strange 403 error appears. Why is this happening?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do You Get a CORS Error from the Browser?
&lt;/h2&gt;

&lt;p&gt;The reason is simple: unlike tools like Postman that make direct requests, browsers enforce the same-origin policy as a security measure. If your frontend is hosted on &lt;a href="https://frontend.com" rel="noopener noreferrer"&gt;https://frontend.com&lt;/a&gt; and it tries to fetch data from &lt;a href="https://api.com" rel="noopener noreferrer"&gt;https://api.com&lt;/a&gt;, the browser blocks the request unless the API explicitly allows it.&lt;/p&gt;

&lt;p&gt;CORS settings in API Gateway define whether such cross-origin requests should be permitted. The key configurations involve setting allowed origins, HTTP methods, and headers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Request Flow: Preflight and Actual Requests
&lt;/h2&gt;

&lt;p&gt;When a client’s browser makes a request to an API hosted on a different origin, the process typically involves two steps: The Preflight Request and the Actual Request.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Preflight Request&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nqb2t9ysbpjxo18b14t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nqb2t9ysbpjxo18b14t.png" alt="Preflight Request" width="550" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before sending the actual request, the browser sends an &lt;code&gt;OPTIONS&lt;/code&gt; request to the API.&lt;/p&gt;

&lt;p&gt;This request asks the server: “Am I allowed to send this request? If so, what methods and headers can I use?”&lt;/p&gt;

&lt;p&gt;API Gateway (if configured correctly) responds with the allowed origins, methods, and headers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Actual Request&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the browser receives a successful response from the preflight check, it proceeds to send the actual request (GET, POST, etc.) to the API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyny637k64blsne3okmjw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyny637k64blsne3okmjw.png" alt="Actual Request" width="550" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the API response includes the required CORS headers, the browser allows the data to be accessed by the client application.&lt;/p&gt;

&lt;p&gt;Without proper CORS settings, the browser will block the request at the preflight stage, preventing the client from communicating with the API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up CORS in AWS API Gateway and Lambda in (CDK)
&lt;/h2&gt;

&lt;p&gt;There are two places you are required to set your headers in other for the two requests (Preflight and Actual) to be successful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, Set up &lt;code&gt;defaultCorsPreflightOptions&lt;/code&gt; in your API-Gateway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;restApi&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;RestApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`YourApi`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;defaultCorsPreflightOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;allowOrigins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://frontend.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;allowMethods&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="s1"&gt;GET&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;POST&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;OPTIONS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;allowHeaders&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="s1"&gt;Content-Type&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;Authorization&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;Accept&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;X-Requested-With&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;allowCredentials&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;defaultCorsPreflightOptions&lt;/code&gt;: adds a CORS preflight configuration to this resource and all child resources. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;allowOrigins&lt;/code&gt;: Defines the permitted origins for requests to this resource. To allow all origins, use Cors.ALL_ORIGINS or [*]. The response will include the Access-Control-Allow-Origin header, and if Cors.ALL_ORIGINS is used, the Vary: Origin header will also be included.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;allowMethods&lt;/code&gt;: The Access-Control-Allow-Methods response header defines the permitted HTTP methods for a resource in response to a preflight request. Here, only GET, POST, and OPTIONS are allowed, enforcing the principle of least privilege by restricting access to necessary methods.
If ANY is specified, it will be expanded to Cors.ALL_METHODS.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;allowHeaders&lt;/code&gt;: The Access-Control-Allow-Headers response header specifies the allowed HTTP headers in response to a preflight request, based on the Access-Control-Request-Headers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;allowCredentials&lt;/code&gt;: The Access-Control-Allow-Credentials response header determines whether the response is accessible to frontend JavaScript when the request's credentials mode is set to "include". If true, browsers expose the response only when credentials (cookies, authorization headers, or TLS client certificates) are included.&lt;/p&gt;

&lt;p&gt;In API Gateway, this ensures a successful preflight request but does not guarantee the actual request's success.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg1ij14enqlzemeraplig.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg1ij14enqlzemeraplig.jpg" alt="Successful preflight request" width="734" height="53"&gt;&lt;/a&gt;&lt;br&gt;
Why? Because the API response does not include the necessary CORS headers. How can we fix that?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, Add CORS headers to your lambda response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&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;event&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;headers&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;Access-Control-Allow-Origin&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;*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Allow all origins&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Methods&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;GET,OPTIONS&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;Access-Control-Allow-Headers&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;Content-Type,Authorization&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;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;We Are Fixing CORS!&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;We added CORS headers to the Lambda response. After a successful preflight request, the browser verifies these headers in the actual response. If present, the data becomes accessible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Setting up CORS for AWS Lambda and API Gateway is crucial when exposing APIs to frontend applications hosted on different domains. By configuring API Gateway’s preflight options and ensuring Lambda responses include CORS headers, you can successfully enable cross-origin access.&lt;/p&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more articles, follow my social handles:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>cdk</category>
      <category>lambda</category>
      <category>restapi</category>
    </item>
    <item>
      <title>How to validate requests when using AWS Lambda Function Url</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Sun, 08 Dec 2024 07:57:31 +0000</pubDate>
      <link>https://dev.to/iamsherif/how-to-validate-requests-when-using-aws-lambda-function-url-5d72</link>
      <guid>https://dev.to/iamsherif/how-to-validate-requests-when-using-aws-lambda-function-url-5d72</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A Lambda function URL is a built-in HTTPS endpoint for an AWS Lambda function. It allows you to directly invoke a Lambda function over HTTP without needing an intermediary service like API Gateway. This simplifies deployments when your function needs to be publicly accessible or integrated into web applications. Validating requests with Lambda Function URLs offers unique challenges and nuances, unlike API Gateway where you can use Model and RequestValidator &lt;a href="https://dev.to/iamsherif/how-to-validate-requests-in-amazon-api-gateway-4n78"&gt;See&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this article, I will guide you on how you can simply validate your event object and as well return appropriate error if there is mismatch in received event payload.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do you need Lambda Function Url
&lt;/h2&gt;

&lt;p&gt;A Lambda function URL is a dedicated endpoint with a unique URL that provides a straightforward way to call a Lambda function over HTTP. When you create a Lambda function URL, AWS automatically generates a URL for the function, and you can configure IAM-based authentication or leave it public (for open access).&lt;/p&gt;

&lt;h3&gt;
  
  
  Importance of Lambda Function Url are:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplicity&lt;/strong&gt;: Removes the need to set up and manage an API Gateway when you only need a simple HTTP endpoint.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost-Effective&lt;/strong&gt;: Reduces costs compared to using API Gateway for basic use cases since Lambda function URLs have no additional charges beyond standard Lambda pricing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quick Deployment&lt;/strong&gt;: Ideal for rapid prototyping or use cases where setting up API Gateway is unnecessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Native HTTPS Support&lt;/strong&gt;: Provides secure communication without extra configuration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication Control&lt;/strong&gt;: Supports IAM-based authentication for secure access or can be set to public for open endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  When would you need Lambda Function Url
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Microservices and Webhooks&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easily create microservices that respond to HTTP requests.&lt;/li&gt;
&lt;li&gt;Use Lambda function URLs to handle webhook callbacks from third-party services (e.g., payment systems, notifications).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prototyping and Demos&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quickly expose a backend function for demo purposes without setting up API Gateway.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Automation and Internal Tools&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create internal tools that employees can access directly via a simple URL.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Static Website Backends&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pair a static website hosted on Amazon S3 or CloudFront with a Lambda function URL for dynamic functionality (e.g., form submissions).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;IoT Integrations&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allow IoT devices to trigger serverless functions directly via HTTP endpoints.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to validate requests in Lambda Function Url
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Define your request model&lt;/li&gt;
&lt;li&gt;Use the reusable request model to validate your event body data(payload)&lt;/li&gt;
&lt;li&gt;Plug the model to your handler method&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Define your request model
&lt;/h4&gt;

&lt;p&gt;Define the model for your event body. Say you want &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, and an optional &lt;code&gt;mobileNumber&lt;/code&gt;. We are going to create a model that matches the expected event body.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite&lt;/strong&gt;:  Install Joi --&amp;gt; &lt;code&gt;npm install Joi&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;joi&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;eventModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;minDomainSegments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;tlds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;allow&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="s1"&gt;com&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;net&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="na"&gt;mobileNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;optional&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;h4&gt;
  
  
  Use the request model to validate your event
&lt;/h4&gt;

&lt;p&gt;After creating the model, next we will need to validate the event body data with the model; this step also ensures error is properly handled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;validateEventData&lt;/span&gt; &lt;span class="o"&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;data&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="k"&gt;try&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;value&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;eventModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;validateAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;error&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;h4&gt;
  
  
  Plug-in the model to your handler method
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&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;event&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;validateEventData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;body&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="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid request body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;err&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sample Error
&lt;/h3&gt;

&lt;p&gt;Say we send a mismatch event object like:&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;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value3@gmail.com"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"mobileNumber"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"234567890"&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;Note that we took out a required field &lt;code&gt;name&lt;/code&gt;.&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="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"body"&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;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Invalid request body"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; is required"&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;Here's a refactored and expanded version of your conclusion section to provide more depth and reinforce key takeaways:&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Properly validating incoming requests is a critical step in safeguarding your AWS Lambda functions from potential vulnerabilities such as SQL injection, script injection, and other forms of malicious input. By implementing robust validation practices, you can ensure that your application remains secure, reliable, and resilient.&lt;/p&gt;

&lt;p&gt;In this article, we demonstrated how to use &lt;a href="https://www.npmjs.com/package/joi" rel="noopener noreferrer"&gt;Joi&lt;/a&gt; library to perform request validation in AWS Lambda functions. With Joi, you can define clear validation schemas, enforce data integrity, and provide informative error messages to users when inputs do not meet your requirements. This approach not only fortifies your application against security threats but also enhances maintainability by keeping your validation logic structured and reusable.&lt;/p&gt;

&lt;p&gt;By following the steps outlined, you can seamlessly integrate input validation into your Lambda functions and handle validation errors gracefully. As a result, your serverless applications can operate more securely, giving you confidence that only well-formed, valid data is processed.&lt;/p&gt;

&lt;p&gt;Remember, validation is just one layer of a comprehensive security strategy. Pairing it with practices such as proper error logging, input sanitization, and authentication mechanisms (like AWS Cognito) will further bolster the security of your application.&lt;/p&gt;

&lt;p&gt;Secure coding practices like these are essential for building robust serverless architectures. Start implementing input validation today to protect your AWS Lambda endpoints and provide a safer experience for your users.&lt;/p&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more articles, follow my social handles:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>lambda</category>
      <category>aws</category>
      <category>javascript</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Schema Validation in Amazon DynamoDB</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Fri, 08 Nov 2024 22:03:14 +0000</pubDate>
      <link>https://dev.to/iamsherif/schema-validation-in-amazon-dynamodb-2c73</link>
      <guid>https://dev.to/iamsherif/schema-validation-in-amazon-dynamodb-2c73</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Validating data in DynamoDB is crucial for maintaining data integrity, ensuring application reliability, and reducing errors. Unlike relational databases, DynamoDB does not enforce strict schema constraints, giving you the flexibility to store a variety of data formats. However, this flexibility means you must take responsibility for validating data before it is written to the database. In this article, we’ll go through an approach to validate data in DynamoDB using AWS Lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Data Validation Matters in DynamoDB
&lt;/h2&gt;

&lt;p&gt;Without strict schema enforcement, data in DynamoDB can end up in inconsistent or incorrect formats. If validation is neglected, problems may arise, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Application Errors: Missing or incorrectly formatted data can lead to errors and application crashes.&lt;/li&gt;
&lt;li&gt;Data Inconsistencies: Querying inconsistent data formats can complicate analytics and reporting.&lt;/li&gt;
&lt;li&gt;Scalability Issues: Unvalidated data may lead to inefficient data structure and increased storage costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To avoid these issues, validating data before saving it to DynamoDB is essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to validate schema using AWS Lambda
&lt;/h2&gt;

&lt;p&gt;In serverless architectures, AWS Lambda is a common approach for server-side validation. By implementing validation within Lambda functions, you can control data before it reaches DynamoDB.&lt;/p&gt;

&lt;p&gt;Here’s how you can incorporate validation in a Lambda function with Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;joi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// The schema definition using Joi&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tableSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;pattern&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;RegExp&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="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w-&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.]+@([&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w-]+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.)+[&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w-]{2,4}$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;optional&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;validateObject&lt;/span&gt; &lt;span class="o"&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;data&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="k"&gt;try&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;value&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;tableSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;validateAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid request body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;err&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;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lambdaHandler&lt;/span&gt; &lt;span class="o"&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;event&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&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;writeToDynamodbTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid request body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;err&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;writeToDynamodbTable&lt;/span&gt; &lt;span class="o"&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;data&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="k"&gt;try&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;value&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;validateObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;TableName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;YourTableName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&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="na"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;phone&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;ConditionExpression&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;attribute_not_exists(id)&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;res&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;dynamodbClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&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;PutCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&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;In the code snippet above we:&lt;br&gt;
1- Define the schema using &lt;a href="https://joi.dev/api/" rel="noopener noreferrer"&gt;Joi&lt;/a&gt; Schema&lt;br&gt;
2- Validate our object in the validateObject function&lt;br&gt;
3- Configure our params object&lt;br&gt;
3- Send request to DynamoDB using AWS Lambda&lt;/p&gt;
&lt;h3&gt;
  
  
  SAMPLE ERROR:
&lt;/h3&gt;

&lt;p&gt;If we send a mismatch object like this:&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="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;"body"&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;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value1"&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;"value2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value3@gmail.com"&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;&lt;em&gt;Note: &lt;code&gt;phone&lt;/code&gt; is not included in the object but it is a required key in the schema we defined.&lt;/em&gt;&lt;br&gt;
We will get an error like&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="err"&gt;statusCode:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;body:&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="err"&gt;message:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Invalid request body"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="err"&gt;error:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="err"&gt;phone&lt;/span&gt;&lt;span class="s2"&gt;" is required"&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Validating data in DynamoDB is a fundamental step to ensure data quality and avoid issues down the line. Whether you choose to validate data on the client, the server, or both, using a structured approach with reusable validation schemas will streamline the process. By following best practices, you can improve the reliability and performance of your DynamoDB-backed applications.&lt;/p&gt;

&lt;p&gt;——————————————&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow my social handles for more articles:&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Click and follow on&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dynamodb</category>
      <category>aws</category>
      <category>security</category>
      <category>node</category>
    </item>
    <item>
      <title>How to Pull Resources from AWS SSM Parameter Store in AWS SAM</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Fri, 11 Oct 2024 23:09:35 +0000</pubDate>
      <link>https://dev.to/iamsherif/how-to-pull-resources-from-aws-ssm-parameter-store-in-aws-sam-3nb4</link>
      <guid>https://dev.to/iamsherif/how-to-pull-resources-from-aws-ssm-parameter-store-in-aws-sam-3nb4</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In this article, I'll guide you through the process of retrieving a DynamoDB table name stored in AWS Systems Manager Parameter Store (SSM Parameter Store) using an AWS SAM template (template.yml). Additionally, I’ll show how to use this parameter in our code and how to add the required IAM permissions to the function.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is AWS Systems Manager Parameter Store?
&lt;/h3&gt;

&lt;p&gt;AWS Systems Manager Parameter Store is a service that provides secure, hierarchical storage for managing configuration data and secrets. It allows you to store values like passwords, database strings, Amazon Machine Image (AMI) IDs, and other sensitive information as parameters. These values can be stored as plain text or encrypted, and referenced in scripts, AWS Lambda functions, and other AWS services by their unique parameter names.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Parameter in AWS Systems Manager Parameter Store
&lt;/h3&gt;

&lt;p&gt;We will create a parameter to hold our DynamoDB table name in the SSM Parameter Store.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the AWS Management Console, search for Systems Manager.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1q7tsq12iy0ig8a877ji.png" alt="Systems Manager search result" width="800" height="271"&gt;
&lt;/li&gt;
&lt;li&gt;Under the Application Management section, select Parameter Store.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8wx21s6wvdyg7ofr17v2.png" alt="Parameter Store" width="330" height="207"&gt;
&lt;/li&gt;
&lt;li&gt;Click the Create Parameter button on the left side.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1s4n48c3l36wc8796m9.png" alt="Create a Parameter" width="194" height="53"&gt;
4- Name the parameter &lt;code&gt;/my/database/name&lt;/code&gt;.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx159gtea7s0h9h3y0wfd.png" alt="parameter name" width="714" height="180"&gt;
5- Set the type to &lt;strong&gt;String&lt;/strong&gt;, and enter the DynamoDB table name as the value.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0sl39mnkpqad4b7cwr2.png" alt="create paramter" width="628" height="407"&gt;
6- Click Create Parameter to save.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Note: In this example, the parameter name is &lt;code&gt;/my/database/name&lt;/code&gt;, and its value is the name of your DynamoDB table.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Retrieving the Parameter in Your AWS SAM Template
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;template.yml&lt;/code&gt; file, we'll reference the DynamoDB table name stored in SSM. The Lambda function, &lt;code&gt;MyFunction&lt;/code&gt;, needs both read permissions for the DynamoDB table and permission to access the SSM Parameter Store.&lt;/p&gt;

&lt;p&gt;The SSM parameter is retrieved using the syntax &lt;code&gt;{{resolve:ssm:/my/database/name}}&lt;/code&gt;, which fetches the value dynamically during resource creation. Additionally, we must assign the necessary IAM roles to allow the Lambda function to read the parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;AWSTemplateFormatVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;2010-09-09'&lt;/span&gt;
&lt;span class="na"&gt;Transform&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Serverless-2016-10-31&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Url Sample SAM Template for url&lt;/span&gt;

&lt;span class="na"&gt;Globals&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Function&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
    &lt;span class="na"&gt;LoggingConfig&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;LogFormat&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;JSON&lt;/span&gt;
&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;MyFunction&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Serverless::Function&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redirect.handler&lt;/span&gt;
      &lt;span class="na"&gt;Runtime&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nodejs18.x&lt;/span&gt;
      &lt;span class="na"&gt;FunctionUrlConfig&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;AuthType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;NONE&lt;/span&gt;
      &lt;span class="na"&gt;Policies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;DynamoDBCrudPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;TableName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{resolve:ssm:/my/database/name}}"&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt;  &lt;span class="na"&gt;SSMParameterReadPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;ParameterName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;my/database/name"&lt;/span&gt;
      &lt;span class="na"&gt;Architectures&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;x86_64&lt;/span&gt;
      &lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;Variables&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;TABLE_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/my/database/name"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the Lambda function retrieves the DynamoDB table name using the &lt;code&gt;resolve&lt;/code&gt; function from SSM and assigns the necessary policies to access both DynamoDB and the SSM Parameter Store.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: We removed the starting&lt;/em&gt; &lt;code&gt;/&lt;/code&gt; &lt;em&gt;before the parameter name.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt;  &lt;span class="na"&gt;SSMParameterReadPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;ParameterName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;my/database/name"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;If we don't, we will get an Unauthorized error.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Retrieving the Parameter Value in your Code
&lt;/h3&gt;

&lt;p&gt;In your code, you can retrieve the DynamoDB table name from the SSM Parameter Store like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SSMClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;GetParameterCommand&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@aws-sdk/client-ssm&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;table_name_path&lt;/span&gt; &lt;span class="o"&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;TABLE_NAME&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;retrieveTable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;table_name_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;WithDecryption&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;command&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;GetParameterCommand&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&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;ssmClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;command&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&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="nx"&gt;Value&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;This JavaScript code initializes an SSM client, and retrieves the DynamoDB table name using the &lt;code&gt;GetParameterCommand&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: Ensure you install the &lt;code&gt;@aws-sdk/client-ssm&lt;/code&gt; package using &lt;code&gt;npm install @aws-sdk/client-ssm&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Notice that we didn't retrieve the parameter value directly within our Lambda function. We avoid adding extra latency during Lambda's cold start. This approach improves performance by reducing the number of external API calls made during execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we explored how to securely store and retrieve a DynamoDB table name from AWS Systems Manager Parameter Store and use it within an AWS Lambda function. By utilizing the &lt;code&gt;{{resolve:ssm}}&lt;/code&gt; syntax in the AWS SAM template, we demonstrated how to dynamically reference parameters during resource deployment. Additionally, we showed how to configure the necessary IAM permissions and retrieve the parameter value within our code using AWS SDK.&lt;/p&gt;

&lt;p&gt;Leveraging AWS Systems Manager Parameter Store not only helps in managing configuration data and secrets efficiently, but also enhances the security and flexibility of your serverless applications. With these steps, you can easily scale this approach to manage other sensitive configuration values across your AWS infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow my social handles for more articles:&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Click and follow on&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>lambda</category>
      <category>dynamodb</category>
    </item>
    <item>
      <title>How to make authenticated HTTP POST and GET requests to third-party APIs in SpringBoot</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Thu, 26 Sep 2024 00:22:40 +0000</pubDate>
      <link>https://dev.to/iamsherif/how-to-make-authenticated-http-post-and-get-requests-in-springboot-ai7</link>
      <guid>https://dev.to/iamsherif/how-to-make-authenticated-http-post-and-get-requests-in-springboot-ai7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Spring Boot is a powerful Java framework that simplifies software development process by providing a comprehensive suite of tools and conventions. Its ease of use, along with powerful features, makes it a popular choice for both small and large applications. In building applications, at times there is a need to consume third-party APIs within your application.&lt;/p&gt;

&lt;p&gt;There are several ways to make requests to APIs in Spring Boot which include using &lt;code&gt;RestTemplate&lt;/code&gt;, &lt;code&gt;WebSocket&lt;/code&gt;, &lt;code&gt;Apache HttpClient&lt;/code&gt;, &lt;code&gt;OkHttp&lt;/code&gt;, and &lt;code&gt;FeignClient&lt;/code&gt;. The choice of method often depends on the specific requirements of your application. In this article, we will focus on how to make authenticated POST and GET requests to third-party APIs using &lt;code&gt;RestTemplate&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is RestTemplate?
&lt;/h3&gt;

&lt;p&gt;RestTemplate is a synchronous client provided by Spring that provides a straightforward and intuitive API for sending HTTP requests and handling responses. It is a package in Spring that is included in the Spring Web dependency. Its methods are easy to understand, making it accessible for developers of all skill levels.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to make an Authenticated POST request
&lt;/h3&gt;

&lt;p&gt;To demonstrate how to make an authenticated POST request, let's consider a scenario where we are building a wallet application that needs to create an account via a third-party API at &lt;code&gt;https://api.example.com/create&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Requirements:
&lt;/h4&gt;

&lt;p&gt;The API requires the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Headers: &lt;code&gt;Authorization bearer &amp;lt;token&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Body Parameters: &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, &lt;code&gt;bvn&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Steps
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Create a RestTemplate object.&lt;/li&gt;
&lt;li&gt;Set Up the HTTP Headers: Create a header that carries the authorization token using &lt;code&gt;HttpHeaders&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create the HttpEntity: Construct an &lt;code&gt;HttpEntity&lt;/code&gt; object using the expected request body and the HTTP header.&lt;/li&gt;
&lt;li&gt;Make the POST Request: Use the &lt;code&gt;postForObject&lt;/code&gt; method of RestTemplate to send the request.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example Code
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.example.com/create"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;RestTemplate&lt;/span&gt; &lt;span class="n"&gt;restTemplate&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;RestTemplate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;HttpHeaders&lt;/span&gt; &lt;span class="n"&gt;httpHeaders&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;HttpHeaders&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;httpHeaders&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setBasicAuth&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;HttpEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;httpEntity&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;HttpEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;requestBody&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpHeaders&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Response from the API server&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;responseObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;restTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;postForObject&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpEntity&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this setup, you can successfully make a POST request to the API, provided that the token is valid.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to make an Authenticated GET request
&lt;/h3&gt;

&lt;p&gt;To make the authenticated GET request, we are going to make use of the &lt;code&gt;exchange&lt;/code&gt; method in &lt;code&gt;RestTemplate&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example Code
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.example.com/balance"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;HttpHeaders&lt;/span&gt; &lt;span class="n"&gt;httpHeaders&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;HttpHeaders&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;httpHeaders&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setBasicAuth&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;HttpEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;httpEntity&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;HttpEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;httpHeaders&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Response from the API server&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;responseObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;restTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;exchange&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpMethod&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;GET&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpEntity&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;getBody&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these steps, you will be able to make the GET request to the API provided your token is valid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we covered how to make authenticated POST and GET requests to third-party APIs using SpringBoot's &lt;code&gt;RestTemplate&lt;/code&gt;. By leveraging RestTemplate, you can easily configure your requests to include necessary authentication headers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Always ensure that sensitive data such as API keys and passwords are stored securely, using environment variables or encrypted configuration files.&lt;/li&gt;
&lt;li&gt;Consider exploring other options like WebClient for reactive programming or FeignClient for declarative API clients in more complex applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Follow my social handles for more articles:&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Click and follow on&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>http</category>
    </item>
    <item>
      <title>Securing Data at Rest: The Importance of Encryption and How to Implement It</title>
      <dc:creator>iAmSherif 💎</dc:creator>
      <pubDate>Sun, 14 Jul 2024 17:30:56 +0000</pubDate>
      <link>https://dev.to/iamsherif/securing-data-at-rest-the-importance-of-encryption-and-how-to-implement-it-81a</link>
      <guid>https://dev.to/iamsherif/securing-data-at-rest-the-importance-of-encryption-and-how-to-implement-it-81a</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Keeping your data safe is essential for any organization to prevent unauthorized access and breaches. In AWS's shared security responsibility model, customers are responsible for anything they put in the cloud or connect to the cloud, while AWS is responsible for the security of the cloud. For more details, you can &lt;a href="https://aws.amazon.com/compliance/shared-responsibility-model/" rel="noopener noreferrer"&gt;&lt;em&gt;read more information about AWS shared responsibility model.&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Data at rest refers to data stored in AWS data stores, such as Amazon S3 buckets and DynamoDB. In this article, I will highlight the importance of encrypting data at rest and provide a guide on how to encrypt an &lt;a href="https://aws.amazon.com/dynamodb/" rel="noopener noreferrer"&gt;&lt;em&gt;Amazon DynamoDB&lt;/em&gt;&lt;/a&gt; table using a Customer Managed key (CMK).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need to encrypt data at rest?
&lt;/h2&gt;

&lt;p&gt;AWS data stores offer encryption at rest using configurable options that we control. These encryption options leverage the AWS Key Management Service (AWS KMS) and keys that either we or AWS manage. By default, data on Amazon DynamoDB tables is fully encrypted. AWS offers several encryption tools, including &lt;a href="https://docs.aws.amazon.com/crypto/latest/userguide/awscryp-service-toplevel.html" rel="noopener noreferrer"&gt;&lt;em&gt;AWS Cryptographic Services and Tools&lt;/em&gt;&lt;/a&gt;, and &lt;a href="https://aws.amazon.com/kms/" rel="noopener noreferrer"&gt;AWS KMS&lt;/a&gt;. In this article, we will focus on adding encryption to DynamoDB using a &lt;a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-mgmt" rel="noopener noreferrer"&gt;AWS KMS CMK&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The importance of encrypting data at rest includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensuring sensitive data stored on disks is not readable by any user or application without a valid key.&lt;/li&gt;
&lt;li&gt;Maintaining the confidentiality and protection of sensitive information from unauthorized access.&lt;/li&gt;
&lt;li&gt;Enhancing customer trust by demonstrating a commitment to data security and privacy.&lt;/li&gt;
&lt;li&gt;Minimizing the impact of data breaches on business operations and reputation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to Encrypt a DynamoDB Table Using AWS KMS CMK
&lt;/h2&gt;

&lt;p&gt;The steps below guides on how to encrypt a DynamoDB table using AWS KMS CMK from AWS Management Console:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create an AWS KMS Customer Managed Key
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your &lt;strong&gt;AWS Management Console&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Navigate to AWS Key Management Service (KMS)&lt;/strong&gt; and click on &lt;strong&gt;Create key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feu5ix93fzf3ndnw5wqfq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feu5ix93fzf3ndnw5wqfq.png" alt="Create key image on management console" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fewe13a98nrgihb4w3zts.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fewe13a98nrgihb4w3zts.png" alt="Configure key image on management console" width="800" height="619"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Add Labels&lt;/strong&gt;: Name the key "mykey".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskozjw97ltzogv74ye1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskozjw97ltzogv74ye1s.png" alt="Configure Add Labels" width="800" height="771"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define Key Administrative Permissions and Usage Permissions&lt;/strong&gt;. &lt;a href="https://repost.aws/questions/QU4A3jhSKwRy-3vUUrS2Fqzw/assign-role-for-administrative-and-usage-permission-kms" rel="noopener noreferrer"&gt;&lt;em&gt;Read more&lt;/em&gt;&lt;/a&gt; about assigning roles for administrative and usage permissions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Review your configurations&lt;/strong&gt; and click &lt;strong&gt;Finish&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Encrypt DynamoDB Table Data Using the Key
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Go to the DynamoDB console&lt;/strong&gt; and select &lt;strong&gt;Tables&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on &lt;strong&gt;Create table&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oa6ouvwz5sv7tjicugx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oa6ouvwz5sv7tjicugx.png" alt="Click on Create table" width="514" height="91"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the next page, name your table "&lt;code&gt;myTable&lt;/code&gt;" and add a partition key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In &lt;strong&gt;Table Settings&lt;/strong&gt;, click on &lt;strong&gt;Customize settings&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2qmm602dw5zojg4iutz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2qmm602dw5zojg4iutz.png" alt="Customize settings" width="800" height="784"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Scroll down to &lt;strong&gt;Encryption at rest&lt;/strong&gt; and add your custom key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2dhq180kvd37k0k1zuc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2dhq180kvd37k0k1zuc.png" alt="Add our own custom key" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose the key you created named "mykey".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create table&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfoukzvclyptnqjbcc15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfoukzvclyptnqjbcc15.png" alt="Create table" width="495" height="209"&gt;&lt;/a&gt;&lt;br&gt;
Your table will now be encrypted using the selected CMK.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Encrypting data at rest in AWS is a critical step in ensuring the security and integrity of your organization's sensitive information. By leveraging AWS KMS Customer Managed Keys (CMK), you can maintain control over your encryption keys and meet compliance requirements. This guide has walked you through the process of creating a custom key and using it to encrypt a DynamoDB table. Implementing these encryption practices not only protects your data from unauthorized access but also enhances customer trust and minimizes the impact of potential data breaches. Prioritizing data security is essential for safeguarding your business operations and reputation.&lt;/p&gt;

&lt;p&gt;Follow my social handles for more on AWS Serverless services:&lt;br&gt;
Click to follow on&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/sherifawofiranye" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.x.com/sherif_on_x" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iamsherif"&gt;&lt;em&gt;Dev&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@awofiranyesherif4" rel="noopener noreferrer"&gt;&lt;em&gt;Medium&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>serverless</category>
      <category>data</category>
      <category>dynamodb</category>
    </item>
  </channel>
</rss>
