AWS Lambda mit Claude Code: Serverless Functions 2026

AWS Lambda ist das Herzstück moderner Serverless-Architekturen — kein Server-Management, automatisches Skalieren, Pay-per-Use. Claude Code kennt das AWS-Ökosystem: Lambda, API Gateway, DynamoDB, SAM und CDK für produktionsreife Serverless-Lösungen.

Lambda Function Grundstruktur

LambdaTypeScript Handler mit SAM

# Prompt: "Erstelle eine Lambda Function für eine REST API # mit API Gateway, DynamoDB und TypeScript" // handler.ts — Claude Code generiert: import { APIGatewayProxyHandler, APIGatewayProxyResult } from 'aws-lambda' import { DynamoDBClient, GetItemCommand, PutItemCommand } from '@aws-sdk/client-dynamodb' import { marshall, unmarshall } from '@aws-sdk/util-dynamodb' const client = new DynamoDBClient({ region: process.env.AWS_REGION }) const TABLE_NAME = process.env.TABLE_NAME! export const handler: APIGatewayProxyHandler = async (event) => { const { httpMethod, pathParameters, body } = event try { switch (httpMethod) { case 'GET': { const result = await client.send(new GetItemCommand({ TableName: TABLE_NAME, Key: marshall({ id: pathParameters?.id }) })) if (!result.Item) return response(404, { error: 'Not found' }) return response(200, unmarshall(result.Item)) } case 'POST': { const item = JSON.parse(body || '{}') item.id = crypto.randomUUID() item.createdAt = new Date().toISOString() await client.send(new PutItemCommand({ TableName: TABLE_NAME, Item: marshall(item) })) return response(201, item) } default: return response(405, { error: 'Method not allowed' }) } } catch (error) { console.error('Lambda error:', error) return response(500, { error: 'Internal server error' }) } } function response(statusCode: number, body: object): APIGatewayProxyResult { return { statusCode, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, body: JSON.stringify(body) } }

SAM Template: Infrastructure as Code

SAMtemplate.yaml für REST API

# template.yaml — Claude Code konfiguriert: AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Globals: Function: Runtime: nodejs20.x Timeout: 30 MemorySize: 512 Environment: Variables: TABLE_NAME: !Ref ItemsTable Resources: ItemsFunction: Type: AWS::Serverless::Function Properties: Handler: dist/handler.handler Policies: - DynamoDBCrudPolicy: TableName: !Ref ItemsTable Events: GetItem: Type: Api Properties: Path: /items/{id} Method: GET CreateItem: Type: Api Properties: Path: /items Method: POST ItemsTable: Type: AWS::DynamoDB::Table Properties: BillingMode: PAY_PER_REQUEST # On-Demand, kein Provisioning AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - AttributeName: id KeyType: HASH TimeToLiveSpecification: AttributeName: ttl Enabled: true Outputs: ApiUrl: Value: !Sub https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/

Cold Start Optimierung

PerformanceCold Start minimieren

# Prompt: "Optimiere diese Lambda Function für minimale Cold Starts" // 1. SDK-Clients außerhalb des Handlers initialisieren (einmalig!) const dynamodb = new DynamoDBClient({}) // Einmal pro Container-Start // 2. Nur benötigte SDK-Module importieren (Tree Shaking) import { GetItemCommand } from '@aws-sdk/client-dynamodb' // NICHT: import * as AWS from 'aws-sdk' ← großes Bundle! // 3. esbuild für minimales Bundle: # package.json scripts: "build": "esbuild src/handler.ts --bundle --platform=node --target=node20 --outfile=dist/handler.js --external:@aws-sdk/*" # @aws-sdk ist in Lambda Runtime bereits vorhanden → external! # 4. Lambda Snapstart (Java) oder ARM64 für Node.js: Globals: Function: Architectures: [arm64] # Graviton2 — 20% günstiger, ähnlich schnell # 5. Provisioned Concurrency für kritische Funktionen: ItemsFunction: AutoPublishAlias: live ProvisionedConcurrencyConfig: ProvisionedConcurrentExecutions: 2 ## Immer warm (teurer!)
Cold Start Realität: Node.js Lambda Cold Starts liegen bei 200-500ms. Für User-facing APIs mit <100ms Anforderung: Provisioned Concurrency oder Vercel Edge Functions als Alternative.

Event-Driven: SQS und EventBridge

EventsAsync Processing mit SQS

# Prompt: "Erstelle einen Lambda Consumer für SQS-Nachrichten # mit Batch Processing und Dead Letter Queue" import { SQSHandler, SQSRecord } from 'aws-lambda' export const handler: SQSHandler = async (event) => { const failures: string[] = [] await Promise.allSettled( event.Records.map(async (record: SQSRecord) => { try { const message = JSON.parse(record.body) await processMessage(message) } catch (error) { console.error(`Failed: ${record.messageId}`, error) failures.push(record.messageId) // → DLQ } }) ) // Partial Batch Response: fehlgeschlagene zurückgeben return { batchItemFailures: failures.map(id => ({ itemIdentifier: id })) } } # SAM: SQS Trigger mit Batching ProcessQueue: Type: SQS Properties: Queue: !GetAtt MyQueue.Arn BatchSize: 10 FunctionResponseTypes: - ReportBatchItemFailures # Partial Batch Response aktivieren
Serverless-Prompt: "Erkläre welche AWS-Services für diese Architektur optimal sind und generiere das vollständige SAM-Template mit IAM-Policies, DLQ und Monitoring." Claude Code kennt AWS Best Practices und generiert vollständige, sichere Konfigurationen.

AWS-Modul im Kurs

Im Claude Code Mastery Kurs: vollständiges AWS-Modul mit Lambda, API Gateway, DynamoDB, SQS, EventBridge, SAM und CDK — von der ersten Function bis zur produktionsreifen Serverless-Architektur.

14 Tage kostenlos testen →