惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
月光博客
月光博客
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
博客园_首页
GbyAI
GbyAI
The Cloudflare Blog
博客园 - 叶小钗
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
博客园 - 三生石上(FineUI控件)
量子位
博客园 - Franky
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
J
Java Code Geeks
腾讯CDC
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
S
Securelist
F
Full Disclosure
Cisco Talos Blog
Cisco Talos Blog
小众软件
小众软件
The GitHub Blog
The GitHub Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Creating Your First Lambda Function
Eric D Johns · 2026-05-15 · via DEV Community

So you want to build your first serverless function? Let's do it. No fluff, no detours — just you, AWS SAM, and a working Lambda function running on your machine in minutes. We're not even going to deploy to AWS yet. Let's just get it working locally first.

What You'll Need

Two things:

  1. AWS SAM CLI installed — SAM (Serverless Application Model) is the tool we'll use to create, build, and test our function. Follow the install guide for your operating system.
  2. Docker or Finch installed — SAM uses a container runtime to simulate Lambda locally. You have two options:
    • Docker Desktop — The most common option. Install it and make sure it's running.
    • Finch — A lightweight open source alternative from AWS. Install it with brew install finch.

Verify your setup

Check that SAM is installed:

sam --version

Enter fullscreen mode Exit fullscreen mode

If you chose Finch, initialize and start the VM:

finch vm init
finch vm start

Enter fullscreen mode Exit fullscreen mode

SAM automatically detects Finch when Docker isn't running — no extra configuration needed. If you have both installed, SAM uses Docker by default. To make Finch the default on macOS, run:

sudo /usr/libexec/PlistBuddy -c "Add :DefaultContainerRuntime string finch" /Library/Preferences/com.amazon.samcli.plist

Enter fullscreen mode Exit fullscreen mode

Verify your container runtime is working:

docker --version   # or: finch --version

Enter fullscreen mode Exit fullscreen mode

That's it. No AWS account needed yet. We're staying local for now.

Step 1: Initialize Your Project

Open your terminal and run:

sam init

Enter fullscreen mode Exit fullscreen mode

SAM is going to walk you through a few questions. For this blog, I'm using the TypeScript template, but you can choose any runtime and template you'd like — Python, Java, Go, whatever you're comfortable with. The prompts, project structure, and file names will vary depending on what you pick. Here's what I chose:

  1. Template source — Choose 1 - AWS Quick Start Templates
  2. Quick start template — Choose 1 - Hello World Example
  3. Use the most popular runtime and package type?N
  4. Runtime — Choose 12 - nodejs24.x
  5. Package type — Choose Zip
  6. Starter template — Choose 2 — Hello World Example TypeScript
  7. Enable X-Ray tracing?N (we'll keep it simple for now)
  8. Enable CloudWatch Application Insights?N
  9. Enable Lambda Insights?N
  10. Project name — Hit Enter to accept the default, or name it whatever you like

SAM just scaffolded an entire serverless project for you. Let's look at what we got:

sam-app/
├── template.yaml          # The blueprint for your infrastructure
├── samconfig.toml         # SAM deployment configuration
├── hello-world/           # Your function code lives here
│   ├── app.ts             # Your actual Lambda function
│   ├── package.json       # Dependencies
│   └── tests/             # Unit tests
│       └── unit/
│           └── test-handler.test.ts
└── events/
    └── event.json         # A sample test event

Enter fullscreen mode Exit fullscreen mode

The two files that matter most:

  • template.yaml — This describes your Lambda function and any AWS resources it needs. Think of it as the blueprint.
  • app.ts — This is your actual function code. The thing that runs when your Lambda gets invoked.

Understanding the template

Let's look at the key part of template.yaml — the function resource:

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs24.x
      Architectures:
        - x86_64
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get
    Metadata:
      BuildMethod: esbuild
      BuildProperties:
        Minify: true
        Target: "es2020"
        Sourcemap: true
        EntryPoints:
          - app.ts

Enter fullscreen mode Exit fullscreen mode

Here's what's going on:

  • Type: AWS::Serverless::Function — This tells SAM to create a Lambda function. SAM handles all the underlying CloudFormation resources for you.
  • CodeUri: hello-world/ — Points to the folder where your function code lives.
  • Handler: app.lambdaHandler — Tells Lambda which file and function to run. In this case, the lambdaHandler export in app.ts.
  • Runtime: nodejs24.x — The Node.js version your function runs on.

The magic is in the Events section. By adding an event with Type: Api, SAM automatically creates an API Gateway for you — no extra configuration needed. You didn't define an API Gateway resource anywhere, but SAM sees that your function wants to respond to HTTP requests at GET /hello and wires it all up behind the scenes. One line, and you've got a fully managed API endpoint in front of your Lambda.

The Metadata section tells SAM how to build your TypeScript code. Instead of running tsc and bundling manually, SAM uses esbuild — a JavaScript/TypeScript bundler. It compiles your TypeScript, minifies the output, generates sourcemaps for debugging, and packages it all up. You don't need to install esbuild yourself — SAM handles it during sam build.

Step 2: Build It

cd sam-app
sam build

Enter fullscreen mode Exit fullscreen mode

SAM grabs your code, installs any dependencies, and packages everything up. You'll see a .aws-sam folder appear — that's your build output. You don't need to touch it.

Don't have the runtime installed on your machine (e.g., no Node.js)? No problem — just add --use-container and SAM will build inside a Docker/Finch container instead:

sam build --use-container

Enter fullscreen mode Exit fullscreen mode

SAM will automatically pull down a container image that matches your function's runtime, build your code inside it, and output the packaged result to .aws-sam just like a normal build. You get the exact same Lambda environment without installing anything on your machine.

Step 3: Test It Locally

Here's the fun part. Run your Lambda function right on your machine:

sam local invoke

Enter fullscreen mode Exit fullscreen mode

You should see a response like:

{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}

Enter fullscreen mode Exit fullscreen mode

That's your Lambda function running locally. No AWS account, no deployment, no charges. Just your code doing its thing.

Make It Yours

Let's make a quick change so you can see the full loop — edit, build, test. Open hello-world/app.ts and find this line:

message: 'hello world',

Enter fullscreen mode Exit fullscreen mode

Change it to:

message: 'hello Lambda',

Enter fullscreen mode Exit fullscreen mode

Now rebuild and invoke again:

sam build
sam local invoke

Enter fullscreen mode Exit fullscreen mode

{"statusCode": 200, "body": "{\"message\": \"hello Lambda\"}"}

Enter fullscreen mode Exit fullscreen mode

That's the workflow. Change your code, build, test — all local, all instant.

Want to test it as an API instead? Run:

sam local start-api

Enter fullscreen mode Exit fullscreen mode

This spins up a local API Gateway. Open your browser and hit http://127.0.0.1:3000/hello and you'll see:

{"message": "hello Lambda"}

Enter fullscreen mode Exit fullscreen mode

You now have a fully functional serverless API running on your laptop.

What Just Happened?

In about 5 minutes, you:

  • Scaffolded a serverless project with a single command
  • Learned how the SAM template automatically wires up a Lambda function and API Gateway
  • Built your TypeScript code with esbuild — no manual setup needed
  • Ran a Lambda function locally
  • Made a code change and saw it reflected instantly
  • Spun up a local API endpoint and hit it from the browser

All without touching AWS. All free. All on your machine.

Ready to Deploy? Let's Go Live.

You've got it working locally. Now let's put it in the cloud so the rest of the world can use it. For this part, you'll need a couple more things set up.

Additional Requirements

  1. An AWS account — Head to aws.amazon.com/free and sign up. New customers get up to $200 in credits and a Free Plan that lets you explore AWS for up to 6 months at no cost. On top of that, Lambda has its own always-free tier — 1 million requests and 400,000 GB-seconds of compute per month.

  2. AWS CLI installed and configured — This is how your machine talks to your AWS account. First, install it from the AWS CLI install guide. Then follow the Setting up the AWS CLI guide to configure your credentials. For most new users, you'll want the IAM user with short-term credentials option — it's the recommended approach for getting started securely.

Once you're set up, verify it's working:

aws sts get-caller-identity

Enter fullscreen mode Exit fullscreen mode

If you see your account ID, you're connected.

Step 4: Deploy It

From your project directory, run:

sam deploy --guided

Enter fullscreen mode Exit fullscreen mode

The --guided flag walks you through the deployment settings the first time. Here's what to expect:

  • Stack Name — Give it a name (like my-sam-app)
  • AWS Region — Pick your closest region (e.g., us-east-1)
  • Confirm changes before deployY
  • Allow SAM CLI IAM role creationY (SAM needs to create a role for your function)
  • Disable rollbackN
  • Save arguments to config fileY (so you don't have to answer these again)

SAM will show you a changeset — a preview of what it's about to create. Type Y to confirm, and watch it go.

When it's done, you'll see an Outputs section with a URL. That's your live API endpoint. Copy it, paste it in your browser, and...

{"message": "hello Lambda"}

Enter fullscreen mode Exit fullscreen mode

🎉 Your Lambda function is live on AWS.

Clean Up

Don't want to leave resources hanging around? Tear it all down with:

sam delete

Enter fullscreen mode Exit fullscreen mode

SAM removes everything it created. Clean slate.

What Just Happened?

In about 10 minutes, you:

  • Scaffolded a serverless project with a single command
  • Learned how the SAM template automatically wires up a Lambda function and API Gateway
  • Built your TypeScript code with esbuild — no manual setup needed
  • Tested your function locally and made a code change
  • Spun up a local API and hit it from the browser
  • Deployed it to AWS with a real, live URL
  • Cleaned it all up with one command

SAM handled all the heavy lifting — the CloudFormation stack, the IAM roles, the API Gateway, the packaging. You just answered a few questions.

What's Next?

You've got the basics down. From here you can:

  • Add more functions to your template.yaml
  • Connect your Lambda to DynamoDB, S3, or other AWS services
  • Set up environment variables and custom permissions
  • Explore event-driven architectures with SNS, SQS, and EventBridge

Want to keep learning? Check out Serverless Land — the go-to hub for all things Lambda and serverless with patterns, tutorials, and best practices. Or dive into the Sessions with SAM YouTube playlist that goes deeper into everything AWS SAM can do.

But that's for next time. For now, celebrate — you just went serverless. 🚀