当我尝试从外部访问我的lambda端点时,出现此错误:
curl -XPOST 127.0.0.1:3000/create-loan
接收失败:对等连接重置
但是在docker内部,端点可以正常工作,端口3000不能从外部运行。
有帮助吗?
名称命令状态端口
billing_db_1 docker-entrypoint.sh postgres上升0.0.0.0:5432-> 5432 / tcp
billing_lambda_1 / usr / local / bin / sam local s ...向上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
我的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"]
已解决
CMD ["local","start-api","--host","0.0.0.0"]
答案 0 :(得分:1)
通过撰写文件,您已经暴露了端口3001
ports:
- "3001:3000"
但连接到3000
curl -XPOST 127.0.0.1:3000/create-loan