Skip to content

Latest commit

 

History

History
58 lines (36 loc) · 2.47 KB

File metadata and controls

58 lines (36 loc) · 2.47 KB

Sample AWS Book API (Starter)

A simple starter project with sample tests, CI/CD configuration for GitHub Actions, and optional API key settings. Companion code for Building Serverless Node.js Apps on AWS (Cloud Bytes Collection), in the serverless-nodejs-dev monorepo.

Main example: sample-aws-book-api.

Setup

Requires Node.js 22+ (see .nvmrc). The Lambda runtime in serverless.yml is nodejs22.x. Serverless Framework v3 may print a harmless validation warning for that runtime locally; offline and AWS deploys still work.

npm ci

Run that command in this directory (sample-aws-book-api-starter), not the monorepo root.

The Serverless Framework and serverless-offline are project dev dependencies; a global serverless install is optional.

npm ci may still print deprecated notices from older transitive packages (for example aws-sdk v2 inside Serverless). Those are warnings, not failed installs.

Security: package.json uses npm overrides to pull patched tar, uuid, and file-type versions into Serverless v3’s tree (same pattern on all three monorepo samples). That clears the moderate/high audit findings without upgrading to Serverless v4. Do not use npm audit fix --force — it replaces Serverless with v4 and changes the book stack.

After npm ci, npm audit may still list 3 low findings on aws-sdk v2 (region-parameter guidance). There is no patched aws-sdk@2 release; Serverless v3 depends on v2. They are acceptable for local/CI if you use npm audit --audit-level=moderate (exit 0).

For AWS deploys, set credentials in your environment or shell profile:

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY"

Deployment

To deploy to AWS locally, make sure you have your AWS key and secret in your bash profile and execute the following:

sls deploy -v --stage <dev, test, staging, production, etc>

Usage

To run locally:

npm start

That runs serverless offline --noAuth using the versions pinned in package.json.

If running locally, the beginning of your url will be http://localhost:3000

To hit the hello world endpoint provided in this example, submit a GET request against the URL http://localhost:3000/dev/sample/path/hello. The response will return a 200 HTTP status with the following body:

{
    "response": "Hello!"
}