Skip to content

Fix serverless-dynamodb examples #774

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions aws-node-express-dynamodb-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ If you try to retrieve user that does not exist, you should receive the followin

### Local development

It is also possible to emulate DynamoDB, API Gateway and Lambda locally using the `serverless-dynamodb-local` and `serverless-offline` plugins. In order to do that, run:
It is also possible to emulate DynamoDB, API Gateway and Lambda locally using the `serverless-dynamodb` and `serverless-offline` plugins. In order to do that, run:

```bash
serverless plugin install -n serverless-dynamodb-local
serverless plugin install -n serverless-dynamodb
serverless plugin install -n serverless-offline
```

It will add both plugins to `devDependencies` in `package.json` file as well as will add it to `plugins` in `serverless.yml`. Make sure that `serverless-offline` is listed as last plugin in `plugins` section:

```
plugins:
- serverless-dynamodb-local
- serverless-dynamodb
- serverless-offline
```

Expand Down Expand Up @@ -134,6 +134,6 @@ After that, running the following command with start both local API Gateway emul
serverless offline start
```

To learn more about the capabilities of `serverless-offline` and `serverless-dynamodb-local`, please refer to their corresponding GitHub repositories:
To learn more about the capabilities of `serverless-offline` and `serverless-dynamodb`, please refer to their corresponding GitHub repositories:
- https://github.com/dherault/serverless-offline
- https://github.com/99x/serverless-dynamodb-local
- https://github.com/raisenational/serverless-dynamodb
1 change: 1 addition & 0 deletions aws-node-http-api-dynamodb-local/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.serverless
node_modules
.dynamodb
8 changes: 3 additions & 5 deletions aws-node-http-api-dynamodb-local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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
framework: v3
platform: AWS
language: nodeJS
authorLink: 'https://github.com/adambrgmn'
Expand All @@ -16,7 +16,7 @@ This example demonstrates how to run a service locally, using the
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)
[serverless-dynamodb](https://github.com/raisenational/serverless-dynamodb)
plugin.

## Use-case
Expand All @@ -27,9 +27,7 @@ Test your service locally, without having to deploy it first.

```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)
serverless dynamodb install # or to use a persistent docker dynamodb instead, open a new terminal: cd ./dynamodb && docker-compose up -d
```

## Run service offline
Expand Down
16 changes: 16 additions & 0 deletions aws-node-http-api-dynamodb-local/db-seeds/todos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"text": "Deploy my first service",
"id": "849fbd50-c926-4e08-9029-d47438b5f487",
"checked": true,
"createdAt": 1707175709304,
"updatedAt": 1707175709304
},
{
"text": "Learn Serverless",
"id": "cc6fbe30-c47f-11ee-9a7b-7d80f9b962e5",
"checked": false,
"createdAt": 1707175709241,
"updatedAt": 1707175770849
}
]
21 changes: 0 additions & 21 deletions aws-node-http-api-dynamodb-local/offline/migrations/todos.json

This file was deleted.

8 changes: 4 additions & 4 deletions aws-node-http-api-dynamodb-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"author": "Christoph Gysin <christoph.gysin@gmail.com>",
"license": "MIT",
"dependencies": {
"uuid": "^2.0.3"
"uuid": "^9.0.1"
},
"devDependencies": {
"aws-sdk": "^2.12.0",
"serverless-dynamodb-local": "^0.2.18",
"serverless-offline": "^6.8.0"
"aws-sdk": "^2.1551.0",
"serverless-dynamodb": "^0.2.49",
"serverless-offline": "^13.3.3"
}
}
16 changes: 11 additions & 5 deletions aws-node-http-api-dynamodb-local/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ service: serverless-http-api-dynamodb-local
frameworkVersion: "3"

plugins:
- serverless-dynamodb-local
- serverless-dynamodb
- serverless-offline

custom:
Expand All @@ -13,11 +13,17 @@ custom:
start:
port: 8000
inMemory: true
# Uncomment if you have a DynamoDB instance already running locally you want to use instead
# noStart: true
# Create the tables according to the resources.Resources block
migrate: true
# Comment if you don't have a DynamoDB running locally
noStart: true
migration:
dir: offline/migrations
# Insert seed items on creation, configured by the custom.dynamodb.seed block
seed: true
seed:
default:
sources:
- table: ${self:provider.environment.DYNAMODB_TABLE}
sources: [./db-seeds/todos.json]

provider:
name: aws
Expand Down
1 change: 1 addition & 0 deletions aws-node-rest-api-with-dynamodb-and-offline/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.serverless
node_modules
.dynamodb
18 changes: 8 additions & 10 deletions aws-node-rest-api-with-dynamodb-and-offline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 'AWS Serverless REST 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 a REST API to manage Todos stored in DynamoDB.'
layout: Doc
framework: v1
framework: v3
platform: AWS
language: nodeJS
priority: 10
Expand All @@ -17,7 +17,7 @@ This example demonstrates how to run a service locally, using the
provides a REST API to manage Todos stored in a DynamoDB, similar to the
[aws-node-rest-api-with-dynamodb](https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb)
example. A local DynamoDB instance is provided by the
[serverless-dynamodb-local](https://github.com/99xt/serverless-dynamodb-local)
[serverless-dynamodb](https://github.com/raisenational/serverless-dynamodb)
plugin.

## Use-case
Expand All @@ -28,9 +28,7 @@ Test your service locally, without having to deploy it first.

```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)
serverless dynamodb install # or to use a persistent docker dynamodb instead, open a new terminal: cd ./dynamodb && docker-compose up -d
```

## Run service offline
Expand All @@ -46,7 +44,7 @@ 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" }'
curl -X POST -H "Content-Type:application/json" http://localhost:3000/dev/todos --data '{ "text": "Learn Serverless" }'
```

Example Result:
Expand All @@ -57,7 +55,7 @@ Example Result:
### List all Todos

```bash
curl -H "Content-Type:application/json" http://localhost:3000/todos
curl -H "Content-Type:application/json" http://localhost:3000/dev/todos
```

Example output:
Expand All @@ -69,7 +67,7 @@ Example output:

```bash
# Replace the <id> part with a real id from your todos table
curl -H "Content-Type:application/json" http://localhost:3000/todos/<id>
curl -H "Content-Type:application/json" http://localhost:3000/dev/todos/<id>
```

Example Result:
Expand All @@ -81,7 +79,7 @@ Example Result:

```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 }'
curl -X PUT -H "Content-Type:application/json" http://localhost:3000/dev/todos/<id> --data '{ "text": "Learn Serverless", "checked": true }'
```

Example Result:
Expand All @@ -93,7 +91,7 @@ Example Result:

```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>
curl -X DELETE -H "Content-Type:application/json" http://localhost:3000/dev/todos/<id>
```

No output
16 changes: 16 additions & 0 deletions aws-node-rest-api-with-dynamodb-and-offline/db-seeds/todos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"text": "Deploy my first service",
"id": "849fbd50-c926-4e08-9029-d47438b5f487",
"checked": true,
"createdAt": 1707175709304,
"updatedAt": 1707175709304
},
{
"text": "Learn Serverless",
"id": "cc6fbe30-c47f-11ee-9a7b-7d80f9b962e5",
"checked": false,
"createdAt": 1707175709241,
"updatedAt": 1707175770849
}
]

This file was deleted.

8 changes: 4 additions & 4 deletions aws-node-rest-api-with-dynamodb-and-offline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"author": "Christoph Gysin <christoph.gysin@gmail.com>",
"license": "MIT",
"dependencies": {
"uuid": "^2.0.3"
"serverless-dynamodb": "^0.2.49",
"uuid": "^9.0.1"
},
"devDependencies": {
"aws-sdk": "^2.12.0",
"serverless-dynamodb-local": "^0.2.18",
"serverless-offline": "^6.8.0"
"aws-sdk": "^2.1551.0",
"serverless-offline": "^13.3.3"
}
}
20 changes: 13 additions & 7 deletions aws-node-rest-api-with-dynamodb-and-offline/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ service: serverless-rest-api-with-dynamodb
frameworkVersion: "3"

plugins:
- serverless-dynamodb-local
- serverless-dynamodb
- serverless-offline

custom:
Expand All @@ -13,17 +13,23 @@ custom:
start:
port: 8000
inMemory: true
# Uncomment if you have a DynamoDB instance already running locally you want to use instead
# noStart: true
# Create the tables according to the resources.Resources block
migrate: true
# Comment if you don't have a DynamoDB running locally
noStart: true
migration:
dir: offline/migrations
# Insert seed items on creation, configured by the custom.dynamodb.seed block
seed: true
seed:
default:
sources:
- table: ${self:provider.environment.DYNAMODB_TABLE}
sources: [./db-seeds/todos.json]

provider:
name: aws
runtime: nodejs18.x
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
DYNAMODB_TABLE: ${self:service}-${sls:stage}
iam:
role:
statements:
Expand All @@ -35,7 +41,7 @@ provider:
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
Resource: "arn:aws:dynamodb:${aws:region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"

functions:
create:
Expand Down
8 changes: 4 additions & 4 deletions aws-python-flask-dynamodb-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ pip install werkzeug boto3
pip install -r requirements.txt
```

Additionally, you will need to emulate DynamoDB locally, which can be done by using `serverless-dynamodb-local` plugin. In order to do that, execute the following commands:
Additionally, you will need to emulate DynamoDB locally, which can be done by using `serverless-dynamodb` plugin. In order to do that, execute the following commands:

```bash
serverless plugin install -n serverless-dynamodb-local
serverless plugin install -n serverless-dynamodb
serverless dynamodb install
```

Expand Down Expand Up @@ -162,6 +162,6 @@ At this point, you can run your application locally with the following command:
serverless wsgi serve
```

For additional local development capabilities of `serverless-wsgi` and `serverless-dynamodb-local` plugins, please refer to corresponding GitHub repositories:
For additional local development capabilities of `serverless-wsgi` and `serverless-dynamodb` plugins, please refer to corresponding GitHub repositories:
- https://github.com/logandk/serverless-wsgi
- https://github.com/99x/serverless-dynamodb-local
- https://github.com/raisenational/serverless-dynamodb
12 changes: 6 additions & 6 deletions aws-ruby-sinatra-dynamodb-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ bundle install --path vendor/bundle
serverless rack serve
```

Additionally, you will need to emulate DynamoDB locally, which can be done by using `serverless-dynamodb-local` plugin. In order to do that, execute the following commands:
Additionally, you will need to emulate DynamoDB locally, which can be done by using `serverless-dynamodb` plugin. In order to do that, execute the following commands:

```bash
serverless plugin install -n serverless-dynamodb-local
serverless plugin install -n serverless-dynamodb
serverless dynamodb install
```

Expand All @@ -152,8 +152,8 @@ client_options = if ENV['IS_OFFLINE']
region: 'localhost',
endpoint: 'http://localhost:8000',
credentials: Aws::Credentials.new(
'DEFAULT_ACCESS_KEY',
'DEFAULT_SECRET'
'MockAccessKeyId',
'MockSecretAccessKey'
)
}
else
Expand All @@ -174,7 +174,7 @@ At this point, you can run your application locally with the following command:
serverless rack serve
```

For additional local development capabilities of `serverless-rack` and `serverless-dynamodb-local` plugins, please refer to corresponding GitHub repositories:
For additional local development capabilities of `serverless-rack` and `serverless-dynamodb` plugins, please refer to corresponding GitHub repositories:

- https://github.com/logandk/serverless-rack
- https://github.com/99x/serverless-dynamodb-local
- https://github.com/99x/serverless-dynamodb