0
votes

When i try to access my lambda endpoint from outside i receive this error:

curl -XPOST 127.0.0.1:3000/create-loan

Recv failure: Connection reset by peer

But inside docker the endpoint work, the port 3000 does not working from outside.

Any help?

Name Command State Ports
billing_db_1 docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp

billing_lambda_1 /usr/local/bin/sam local s ... Up 0.0.0.0:3000->3000/tcp

docker-compose.yml

version: '3'
services:
  lambda:
    build: .
    volumes:
      - ./:/app
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - db
    environment:
      - PYTHONPATH=${PWD}/billing 
    ports:
      - "3001:3000"
  db:
    image: postgres
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=${BILLING_USER}
      - POSTGRES_PASSWORD=${BILLING_PASSWORD}
      - POSTGRES_DB=${BILLING_DB}
      - POSTGRES_HOST=${BILLING_HOST}
volumes:
  db-data:
    driver: local

My DockerFile:

FROM python:3.7

RUN pip3 install aws-sam-cli

EXPOSE 3000

ENTRYPOINT ["/usr/local/bin/sam"]

RUN apt-get install curl

RUN pip3 install pipenv

WORKDIR /app
RUN pipenv install --dev
CMD ["local", "start-api"]

Solved

CMD ["local","start-api","--host","0.0.0.0"]
1

1 Answers

2
votes

By the compose file you've exposed the port 3001

ports:
  - "3001:3000"

But connecting to 3000

curl -XPOST 127.0.0.1:3000/create-loan