
Run an unmodified Express.js REST API as a Lambda Web Function that reads and writes items in an Amazon DynamoDB table, using AWS SAM.
index.js runs locally with node index.js and on AWS.POST /items creates an item with a conditional write that returns 409 on a duplicate id, GET /items/{id} reads one item and returns 404 when it is missing, PUT /items/{id} updates name, description or metadata and fails with 404 if the item does not exist, and GET /items scans the table with cursor pagination through the limit and lastKey query parameters. Missing required fields return 400. Every response includes the Region that served it, which becomes useful when the same code is deployed behind a MultiRegion endpoint with a DynamoDB global table.DocumentClient is created once per sandbox and reused across the many concurrent requests that a single sandbox handles, and it authenticates with the function's execution role. That role is defined explicitly in the template so it can carry AWSLambdaBasicExecutionRole for CloudWatch Logs plus GetItem, PutItem, UpdateItem and Scan scoped to the table ARN. The table name is generated by CloudFormation and injected through the TABLE_NAME environment variable.AWS::Serverless::WebFunction resource expands into AWS::Lambda::WebFunction, an immutable AWS::Lambda::WebFunctionRevision that references the zip in a versioning-enabled S3 bucket, and an AWS::Lambda::WebFunctionEndpoint routed 100% to that revision. The endpoint uses AuthType ApplicationManaged, so it is publicly reachable and the application owns authentication; switch to IamAuth to accept only SigV4-signed requests.node_modules and no build step runs at deploy time, install production dependencies before zipping. To ship a change, upload the zip under a new S3 key and deploy again; CloudFormation creates a new immutable revision only when the revision's properties change, and the LatestRevision endpoint mode moves traffic to it as soon as it is active.git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/lambda-web-dynamodb-api/nodejs/samSee the GitHub repo for deployment instructions.sam delete --stack-name lambda-web-dynamodb-api-sam.