I have a docker setup that runs serverless and dynamodb both in docker. In my serverless.yml I defined instructions for creating a table, yet when I run docker compose up
it does not create the table (I’ve checked by running a query to list tables.
...
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: eu-west-1
plugins:
- serverless-dynamodb-local
- serverless-offline
custom:
dynamodb:
inMemory: true
port: 8000
migrate: true # create tables on start
onStart: true
serverless-offline:
babelOptions:
presets: ["es2015"]
resources:
Resources:
UserTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: UserTable
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: fullname
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
docker-compose.yml
version: "3"
services:
serverless:
build: .
restart: always
privileged: true
working_dir: /home/node-app
environment:
- NODE_ENV=development
- DYNAMO_ENDPOINT=http://dynamodb:8000
- AWS_ACCESS_KEY_ID='dev-key-id'
- AWS_SECRET_ACCESS_KEY='dev-key'
- AWS_REGION='eu-west-1'
links:
- "dynamodb:dynamodb"
command: npm run start
....
dynamodb:
image: amazon/dynamodb-local
ports:
- "8000:8000"
environment:
- AWS_ACCESS_KEY_ID='dev-key-id'
- AWS_SECRET_ACCESS_KEY='dev-key'
npm run start
simply runs sls offline
. Once I run the docker compose, everything starts up fine but the UserTable
is not created.