99x / 99x/serverless-dynamodb-local

Error: connect ECONNREFUSED 127.0.0.1:8000 Docker

Open
#228 3 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
621
Forks
232
PR merge metrics
No merged PRs in 30d

Description

Hi everyone, i have this issue. When i run `sls dynamodb migrate` I have this error:

![image](https://user-images.githubusercontent.com/6276555/63251096-4e285280-c26d-11e9-81a3-567f95159455.png)

My serverless.yml

```
service: asistencias-api

# serverless supports different cloud environments to run at.
# we will be deploying and running this project at AWS cloud with Node v8.10 environment
provider:
name: aws
runtime: nodejs10.0
region: us-east-1
stage: dev
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"

# here we describe our lambda function
functions:
main: # function name
handler: src/handler.main
events:
- http:
path: /
method: get
cors: true
login:
handler: src/handler.login
events:
- http:
path: /login
method: post
cors: true

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

custom:
dynamodb:
start:
port: 8000
inMemory: false
migrate: false
dbPath: .
stages:
- dev
serverless-offline:
host: 0.0.0.0

resources:
Resources:
ItemsDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.DYNAMODB_TABLE}
```

I am using docker and this is my configuration:

Dockefile

```
FROM node:10-alpine

RUN mkdir -p /var/www/app
WORKDIR /var/www/app

RUN apk update && apk add openjdk7-jre
RUN npm install -g serverless

COPY . /var/www/app
RUN npm install
RUN npm run db:install
```

Docker-compose

```
version: '3'
services:
asistencia-api:
build: .
image: backend_asistencia-api_1:latest
depends_on:
- dynamodb
restart: always
ports:
- 3000:3000
links:
- dynamodb
volumes:
- ./:/var/www/app
- /var/www/app/.dynamodb
- /var/www/app/node_modules
- /var/www/app/dynamodb_local_db
command: npm run start
networks:
- net
dynamodb:
image: backend_asistencia-api_1:latest
ports:
- 8000:8000
expose:
- "8080"
command: npm run db:start
networks:
- net

networks:
net:
```

The table is not being created. When I make a connection in the code it gives me timeout.

The docker container lifts well, and even the dynamodb shell.

![image](https://user-images.githubusercontent.com/6276555/63251350-d4449900-c26d-11e9-92de-5c75464be07c.png)

My dynamodb client configuration:

```
'use strict';

const AWS = require('aws-sdk');

let options = {};

// connect to local DB if running offline
if (process.env.IS_OFFLINE) {
options = {
region: 'localhost',
accessKeyId: 'xxxx',
secretAccessKey: 'xxxx',
endpoint: 'http://dynamodb:8000',
};
}

const client = new AWS.DynamoDB.DocumentClient(options);
module.exports = client;
```

I don't know what I may be missing. Thanks!

Contributor guide

Open the contributing guide

Research direction

Start with serverless.yml and docker-compose, then trace the `sls dynamodb migrate` and `npm run db:start` entry points alongside the DynamoDB client configuration. Check how the containers expose and reach the local database; done means the table is created by migration and the application client connects without timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, docker-compose, javascript, node.js
Domain
backend, database, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.