Automation Guide

AWS Lambda for Beginners: How to Build Your First Serverless Automation

From an empty AWS console to a tested, triggered automation in Node.js or Python, plus the settings beginners usually miss.

AWS LambdaServerlessBeginnerAutomation

By Troy Tessalone · · 11 minutes

Beginner Tutorial

A practical field guide from Automation Ace.

The short answer

AWS Lambda runs your code in response to events without servers to manage. To build your first serverless automation: create a function in the AWS console, choose a Node.js or Python runtime, paste a handler that calls one API and sends the result to another app, store keys as environment variables, click Test, then add a trigger: a Function URL for webhooks and calls from Zapier, or an EventBridge schedule for recurring runs. Logs appear in CloudWatch.

Prefer a lighter-weight option? Compare the same tutorial on Cloudflare Workers.

What is AWS Lambda?

Lambda is Amazon Web Services' function-as-a-service platform. You upload a function, tell AWS what should trigger it, and AWS runs it on demand, scaling from zero to many parallel runs and billing by requests and compute time. There is no server to patch or keep online.

In automation, Lambda is the place for logic that outgrows no-code tools: heavy data processing, libraries a Code step cannot load, long-running jobs, or anything that needs direct access to AWS services like S3 or DynamoDB. See Amazon AWS Zapier integrations.

Key concepts in plain English

  • Function: your code plus its settings (runtime, memory, timeout).
  • Handler: the entry point Lambda calls, such as handler in Node.js or lambda_handler in Python.
  • Event: the input data describing what triggered the run, such as an HTTP request body or a schedule payload.
  • Trigger: what invokes the function: a Function URL, API Gateway, EventBridge, S3, SQS, and more. See the trigger glossary entry.
  • Execution role: an IAM role defining what AWS resources the function may use. Start with basic logging permissions only.
  • Environment variables: configuration and secrets available to the code.
  • CloudWatch Logs: where console.log and print output goes.

Step 1: create the function

  1. Sign in to the AWS Management Console and open Lambda. Pick the region closest to your apps or users.
  2. Click Create function → Author from scratch.
  3. Name it (for example usd-eur-to-slack) and choose a current Node.js or Python runtime.
  4. Leave the default execution role, which allows writing logs, and click Create function.

Step 2: write the automation

In the code editor, replace the file contents. Node.js:

// index.mjs — fetch today's USD→EUR rate and post it to Slack
export const handler = async (event) => {
  // 1) Call a public API
  const res = await fetch('https://api.frankfurter.app/latest?from=USD&to=EUR');
  if (!res.ok) throw new Error(`Rates API failed: ${res.status}`);
  const data = await res.json();
  const rate = data.rates.EUR;

  // 2) Send the result to another app (Slack incoming webhook)
  const slack = await fetch(process.env.SLACK_WEBHOOK_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text: `USD→EUR today: ${rate}` }),
  });
  if (!slack.ok) throw new Error(`Slack failed: ${slack.status}`);

  // 3) Return a response (used by Function URLs and callers like Zapier)
  return { statusCode: 200, body: JSON.stringify({ ok: true, rate, date: data.date }) };
};

Python:

# lambda_function.py — the same automation in Python (standard library only)
import json, os, urllib.request

def lambda_handler(event, context):
    with urllib.request.urlopen("https://api.frankfurter.app/latest?from=USD&to=EUR") as r:
        data = json.load(r)
    rate = data["rates"]["EUR"]

    req = urllib.request.Request(
        os.environ["SLACK_WEBHOOK_URL"],
        data=json.dumps({"text": f"USD→EUR today: {rate}"}).encode(),
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    urllib.request.urlopen(req)
    return {"statusCode": 200, "body": json.dumps({"ok": True, "rate": rate})}

This is the core pattern of every API automation: call, check, transform, send. Click Deploy to save the code.

Step 3: add configuration and secrets

  1. Open Configuration → Environment variables and add SLACK_WEBHOOK_URL.
  2. Open Configuration → General configuration and raise the timeout from the short default (a few seconds) to something like 30 seconds, since API calls can be slow.
  3. For sensitive keys in production, use AWS Secrets Manager or Systems Manager Parameter Store and grant the execution role read access. See API authentication for automation.

Step 4: test it

Click Test, create a test event (an empty {} is fine for this function), and run it. You should see the response, a Slack message, and a link to the CloudWatch logs. If it fails, the error and stack trace appear right there. See debugging HTTP requests.

Step 5: add a trigger

Option A: a Function URL (webhooks and Zapier). Under Configuration → Function URL, create a URL. With auth type AWS_IAM, callers must sign requests; with NONE, anyone with the URL can call it, so check a secret token in your code:

// Protect a public Function URL with a shared token header
const token = event.headers?.['x-run-token'];
if (token !== process.env.RUN_TOKEN) {
  return { statusCode: 401, body: 'Unauthorized' };
}
const input = event.body ? JSON.parse(event.body) : {};   // JSON sent by the caller

Call the URL from a Zap with a Webhooks by Zapier POST, or give it to an app as a webhook endpoint. For richer routing, throttling, or API keys, put Amazon API Gateway in front instead.

Option B: a schedule. Use Amazon EventBridge Scheduler to invoke the function on a cron or rate expression:

cron(0 13 ? * MON-FRI *)     # 13:00 UTC, Monday to Friday (EventBridge Scheduler syntax)
rate(15 minutes)             # every 15 minutes

Schedules can use a time zone you choose. Compare with Cloudflare Cron Triggers and custom Zap schedules.

Costs and limits

  • Free tier: AWS has offered an ongoing Lambda free tier (historically 1 million requests and 400,000 GB-seconds of compute per month). Check current AWS pricing, especially for newer accounts.
  • Timeout: up to 15 minutes per invocation; set only what you need.
  • Memory: configurable, and more memory also means more CPU.
  • Other services (API Gateway, Secrets Manager, CloudWatch storage, data transfer) have their own pricing.
  • Set a budget alert in AWS Billing so surprises are caught early.

Lambda vs Cloudflare Workers

AWS LambdaCloudflare Workers
RunsCode in response to events: HTTP requests, schedules, files, queuesCode on Cloudflare's network for HTTP requests, schedules, and email
LanguagesNode.js, Python, Java, .NET, Ruby, Go (via custom runtime), and moreJavaScript, TypeScript, Python, WebAssembly
Max run timeUp to 15 minutes per invocationShort per-request CPU limits; longer work via Workflows
TriggersFunction URLs, API Gateway, EventBridge schedules, S3, SQS, SNS, DynamoDB, and morefetch, Cron Triggers, Email Workers, Queues
Best forHeavier processing, AWS-native data, longer jobsFast edge endpoints, webhooks, lightweight automations
Setup feelMore configuration: IAM roles, regions, logsFewer moving parts to start

Both are good homes for code that outgrows Code by Zapier; see reasons to move custom code to serverless and Cloudflare Workers 101.

Common beginner errors

  • Task timed out after 3 seconds: raise the timeout in General configuration.
  • Cannot find module or handler not found: the handler setting must match the file and function name, such as index.handler or lambda_function.lambda_handler.
  • AccessDenied: the execution role lacks permission for an AWS resource; add only the specific permission needed.
  • Missing packages: third-party libraries must be bundled in a deployment package or a Lambda layer.
  • 401, 403, or 429 from an API: see 401 errors and 429 errors.

Next steps

Frequently asked questions

What is AWS Lambda?

AWS Lambda is Amazon Web Services' serverless compute service. It runs your code in response to events such as HTTP requests, schedules, or file uploads, scales automatically, and bills by requests and compute time, with no servers to manage.

How do I create my first AWS Lambda function?

In the AWS console, open Lambda, choose Create function and Author from scratch, pick a Node.js or Python runtime, paste your handler code, click Deploy, and run it with a test event.

How do I call an AWS Lambda function from Zapier or a webhook?

Create a Function URL for the function, protect it with IAM auth or a secret token checked in your code, and POST to it from Webhooks by Zapier or the sending app. API Gateway is an alternative for richer routing and API keys.

How do I run a Lambda function on a schedule?

Use Amazon EventBridge Scheduler with a cron or rate expression, such as rate(15 minutes) or cron(0 13 ? * MON-FRI *), targeting your function.

Is AWS Lambda free?

AWS has offered an ongoing Lambda free tier, historically 1 million requests and 400,000 GB-seconds per month. Check current AWS pricing, and note that related services like API Gateway are billed separately.

Should I use AWS Lambda or Cloudflare Workers?

Lambda suits heavier processing, longer jobs up to 15 minutes, and AWS-native integrations. Cloudflare Workers suit fast, lightweight endpoints, webhooks, and simple automations with less setup.

AWS LambdaServerlessBeginnerAutomation

Disclaimer: Zapier features, plan availability, and settings can change. Confirm current details in Zapier's help documentation and AWS Lambda documentation and pricing pages. Limits and plan features change over time. Code samples are simplified starting points; add your own validation, error handling, and security review before production use before relying on a specific setting. This article may include links to apps, products, or services; some links may be affiliate links, which means Automation Ace may earn a commission at no extra cost to you.

Build Better Systems

Ready to automate with confidence?

Share your tools, process, and goals. Automation Ace can design the workflow, integration, file transfer, or integration that fits your business.

Start a Project →