Hi there.
You'll need pnpm installed. If you don't have it already you can enable corepack and it will automagically appear in proper version in this project.
corepack enableAfter that install dependencies and you're good to go:
pnpm ipnpm testperform the jest unit testspnpm cdk deploydeploy this stack to your default AWS account/regionpnpm cdk deploy --watchdeploy this stack to your default AWS account/region and watch for changespnpm cdk diffcompare deployed stack with current statepnpm cdk destroyremove stack
API accepts and returns application/json content-type.
All requests have to be authenticated by sending access_token in Authentication header.
type Note = {
id: string | undefined;
title: string;
body: string;
};type Error = {
message: string;
details: any | undefined;
};-
POST /notes- create a noteAccepts
Notein body. Fieldidshould be left empty, as it's generated on the server.Returns
201on success.
Returns422on malformed request and sendsErrorin response. -
GET /notes- list all notesReturns
200on success and sends aNote[]in response. -
GET /notes/:id- retrieve a noteReturns
200on success and sends aNotein response.
Returns404on request to non-existent resource. -
POST /notes/:id- update a noteAccepts
Notein body. Fieldidis overridden with with:idfrom request parameter.Returns
204on success.
Returns404on request to non-existent resource.
Returns422on malformed request and sendsErrorin response. -
DELETE /notes/:id- delete a noteReturns
204on success.
Deleting non-existent resource is also treated as success and returns204.
After deployment stack outputs signin-url. You can go there and register an user.
You'll be redirected to a demo callback function that returns oauth2 response - grab access_token from there.
Alternatively: Change callback parameter in signin url to https://localhost and fetch token manualy with your favourite API Client or if you preffer CLI with command like one bellow:
curl --request POST \
--url ${COGNITO_DOMAIN}/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=authorization_code \
--data redirect_uri=https://localhost \
--data client_id=${CLIENT_ID} \
--data code=${CODE}Although it's possible to run an API Gateway stack defined by AWS-CDK locally thanks to AWS-SAM, it's far from perfect. API Gateway Local will silently ignore the existence of any authorizers. That breaks the contract with Lambda integration.
That's why for local development I recommend relaying on unit / integration tests and than jump to remote execution on a development cloud deployment.
You need to have DynamoDB Local running. You can use provided docker-compose.yaml:
docker compose upThen run the test suite:
pnpm test -- --collectCoverage --verboseRun tests with --maxWorkers=1 to prevent concurrent tests from working on the same DynamoDB Table (optional, tests are safe to run concurrently).
NOTE: You need to have AWS credentials
Run command below to deploy to your active AWS account and watch for changes.
pnpm cdk deploy --watch