AWS Lambda Function
The Function resource lets you create and manage AWS Lambda functions with support for Node.js runtimes, environment variables, and function URLs.
Minimal Example
Section titled “Minimal Example”Create a basic Lambda function with default settings:
import { Function } from "alchemy/aws";
const func = await Function("api", { functionName: "my-api", bundle: bundle, roleArn: role.arn, handler: "index.handler",});
With Environment Variables
Section titled “With Environment Variables”Add environment variables to configure the function:
const func = await Function("api", { functionName: "my-api", bundle: bundle, roleArn: role.arn, handler: "index.handler", environment: { TABLE_NAME: table.name, QUEUE_URL: queue.url, },});
With Function URL
Section titled “With Function URL”Create a public HTTP endpoint for the function:
const func = await Function("api", { functionName: "my-api", bundle: bundle, roleArn: role.arn, handler: "index.handler", url: { authType: "NONE", cors: { allowOrigins: ["*"], allowMethods: ["GET", "POST"], allowHeaders: ["content-type"], }, },});
With Custom Configuration
Section titled “With Custom Configuration”Customize memory, timeout and other settings:
const func = await Function("worker", { functionName: "worker", bundle: bundle, roleArn: role.arn, handler: "worker.process", runtime: "nodejs20.x", architecture: "arm64", memorySize: 512, timeout: 30, tags: { Environment: "production", },});