forked from auspiciousdev99/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to HTTP APIs by default for Node examples
- Loading branch information
Showing
56 changed files
with
1,861 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: aws-node-express-api | ||
org: serverlessinc | ||
description: Deploys a Node Express API service with traditional Serverless Framework | ||
description: Deploys a Node Express API service with Serverless Framework | ||
keywords: aws, serverless, faas, lambda, node, express | ||
repo: https://github.com/serverless/examples/aws-node-express-api | ||
license: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: aws-node-express-dynamodb-api | ||
org: serverlessinc | ||
description: Deploys a Node Express API service backed by DynamoDB with traditional Serverless Framework | ||
description: Deploys a Node Express API service backed by DynamoDB with Serverless Framework | ||
keywords: aws, serverless, faas, lambda, node, express, dynamodb | ||
repo: https://github.com/serverless/examples/aws-node-express-dynamodb-api | ||
license: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.serverless | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<!-- | ||
title: 'AWS Serverless HTTP API with DynamoDB and offline support example in NodeJS' | ||
description: 'This example demonstrates how to run a service locally, using the ''serverless-offline'' plugin. It provides an HTTP API to manage Todos stored in DynamoDB.' | ||
layout: Doc | ||
framework: v1 | ||
platform: AWS | ||
language: nodeJS | ||
authorLink: 'https://github.com/adambrgmn' | ||
authorName: 'Adam Bergman' | ||
authorAvatar: 'https://avatars1.githubusercontent.com/u/13746650?v=4&s=140' | ||
--> | ||
# Serverless HTTP API with DynamoDB and offline support | ||
|
||
This example demonstrates how to run a service locally, using the | ||
[serverless-offline](https://github.com/dherault/serverless-offline) plugin. It | ||
provides an HTTP API to manage Todos stored in a DynamoDB, similar to the | ||
[aws-node-http-api-dynamodb](https://github.com/serverless/examples/tree/master/aws-node-http-api-dynamodb) | ||
example. A local DynamoDB instance is provided by the | ||
[serverless-dynamodb-local](https://github.com/99xt/serverless-dynamodb-local) | ||
plugin. | ||
|
||
## Use-case | ||
|
||
Test your service locally, without having to deploy it first. | ||
|
||
## Setup | ||
|
||
```bash | ||
npm install | ||
serverless dynamodb install (or to use a persistent docker dynamodb instead, open a new terminal: cd ./dynamodb && docker-compose up -d) | ||
serverless offline start | ||
serverless dynamodb migrate (this imports schema) | ||
``` | ||
|
||
## Run service offline | ||
|
||
```bash | ||
serverless offline start | ||
``` | ||
|
||
## Usage | ||
|
||
You can create, retrieve, update, or delete todos with the following commands: | ||
|
||
### Create a Todo | ||
|
||
```bash | ||
curl -X POST -H "Content-Type:application/json" http://localhost:3000/todos --data '{ "text": "Learn Serverless" }' | ||
``` | ||
|
||
Example Result: | ||
```bash | ||
{"text":"Learn Serverless","id":"ee6490d0-aa11e6-9ede-afdfa051af86","createdAt":1479138570824,"checked":false,"updatedAt":1479138570824}% | ||
``` | ||
|
||
### List all Todos | ||
|
||
```bash | ||
curl -H "Content-Type:application/json" http://localhost:3000/todos | ||
``` | ||
|
||
Example output: | ||
```bash | ||
[{"text":"Deploy my first service","id":"ac90feaa11e6-9ede-afdfa051af86","checked":true,"updatedAt":1479139961304},{"text":"Learn Serverless","id":"206793aa11e6-9ede-afdfa051af86","createdAt":1479139943241,"checked":false,"updatedAt":1479139943241}]% | ||
``` | ||
|
||
### Get one Todo | ||
|
||
```bash | ||
# Replace the <id> part with a real id from your todos table | ||
curl -H "Content-Type:application/json" http://localhost:3000/todos/<id> | ||
``` | ||
|
||
Example Result: | ||
```bash | ||
{"text":"Learn Serverless","id":"ee6490d0-aa11e6-9ede-afdfa051af86","createdAt":1479138570824,"checked":false,"updatedAt":1479138570824}% | ||
``` | ||
|
||
### Update a Todo | ||
|
||
```bash | ||
# Replace the <id> part with a real id from your todos table | ||
curl -X PUT -H "Content-Type:application/json" http://localhost:3000/todos/<id> --data '{ "text": "Learn Serverless", "checked": true }' | ||
``` | ||
|
||
Example Result: | ||
```bash | ||
{"text":"Learn Serverless","id":"ee6490d0-aa11e6-9ede-afdfa051af86","createdAt":1479138570824,"checked":true,"updatedAt":1479138570824}% | ||
``` | ||
|
||
### Delete a Todo | ||
|
||
```bash | ||
# Replace the <id> part with a real id from your todos table | ||
curl -X DELETE -H "Content-Type:application/json" http://localhost:3000/todos/<id> | ||
``` | ||
|
||
No output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM amazon/dynamodb-local | ||
|
||
WORKDIR /home/dynamodblocal | ||
|
||
RUN mkdir ./db && chown -R 1000 ./db | ||
|
||
CMD ["-jar", "DynamoDBLocal.jar", "-dbPath", "./db", "-sharedDb"] | ||
VOLUME ["./db"] |
15 changes: 15 additions & 0 deletions
15
aws-node-http-api-dynamodb-local/dynamodb/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: "3" | ||
|
||
services: | ||
dynamodb: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- 8000:8000 | ||
volumes: | ||
- aws-http-api-dynamodb:/home/dynamodblocal/db | ||
|
||
volumes: | ||
aws-http-api-dynamodb: | ||
driver: local |
21 changes: 21 additions & 0 deletions
21
aws-node-http-api-dynamodb-local/offline/migrations/todos.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"Table": { | ||
"TableName": "serverless-http-api-dynamodb-local-dev", | ||
"KeySchema": [ | ||
{ | ||
"AttributeName": "id", | ||
"KeyType": "HASH" | ||
} | ||
], | ||
"AttributeDefinitions": [ | ||
{ | ||
"AttributeName": "id", | ||
"AttributeType": "S" | ||
} | ||
], | ||
"ProvisionedThroughput": { | ||
"ReadCapacityUnits": 1, | ||
"WriteCapacityUnits": 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "serverless-http-api-dynamodb-local", | ||
"version": "1.0.0", | ||
"description": "Serverless HTTP API with DynamoDB and offline support", | ||
"repository": "", | ||
"author": "Christoph Gysin <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"uuid": "^2.0.3" | ||
}, | ||
"devDependencies": { | ||
"aws-sdk": "^2.12.0", | ||
"serverless-dynamodb-local": "^0.2.18", | ||
"serverless-offline": "^6.8.0" | ||
} | ||
} |
Oops, something went wrong.