简体   繁体   English

我无法使用 localstack 12.5 lambda(在 4566 端口运行)调用在 localhost:9090 上运行的另一个容器中的 rest api

[英]I am not able to call rest api which is in another container running at localhost:9090, using localstack 12.5 lambda (running at 4566 port)

localstack 12.5本地堆栈 12.5

dummy.py file for lambda hanlder用于 lambda 处理程序的 dummy.py 文件

import sys
import requests

def handler(event, context):
    print("Inside handler")
    x = requests.get('http://localhost:9090/ping')
    print(x.status_code)
    return str(x.content)

In handler when i am calling get api which is in another container i am getting connection refused error.在处理程序中,当我调用另一个容器中的 get api 时,我收到连接被拒绝的错误。

Error: "ConnectionError","errorMessage":"HTTPConnectionPool(host='localhost', port=9090): Max retries exceeded with url: Caused by NewConnectionError('\ : Failed to establish a new connection: 错误:"ConnectionError","errorMessage":"HTTPConnectionPool(host='localhost', port=9090): Max retries exceeded with url: Caused by NewConnectionError('\ : Failed to build一个新的连接:

However with postman I am able to hit http://localhost:9090/ping API但是通过邮递员,我可以访问 http://localhost:9090/ping API

Also If I replace x = requests.get('https://w3schools.com') then I am getting 200 .另外,如果我替换 x = requests.get('https://w3schools.com') 那么我得到 200 。

The issue has been resolved by adding below env variable in localstack该问题已通过在 localstack 中添加以下 env 变量解决

LAMBDA_DOCKER_NETWORK="host" LAMBDA_DOCKER_NETWORK="主机"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker容器无法从本地主机调用另一个正在运行的Docker容器? - Docker container not able to call another running docker container from localhost? 我在从 Docker 容器到本地运行的 API 的此 API 调用上映射端口是否错误? - Am I mapping ports wrong on this API call from a Docker container to a locally running API? 我是否在容器上运行? - Am I running on container or not? Docker容器只能使用内部IP /端口访问在另一个容器中运行的MSSQL - Docker container is only able to access MSSQL running inside another container with the internal IP/port 前端【在docker容器中运行】无法访问ASP.Net核心API【在另一个容器中运行】 - Front end [running in docker container] not able to access ASP.Net core API [running in another container] 在 docker 容器中针对 Localstack 运行 shell 脚本 - Running shell script against Localstack in docker container docker 正在运行,但我无法使用 localhost 进行连接 - docker is running but I am unable to connect using localhost Docker-使用localhost访问正在运行的容器 - Docker - Using localhost for to access running container 从Shell脚本运行容器后,将端口公开到localhost url - Expose port to localhost url after running container from Shell script 无法使用http:// localhost:8080 / getAll访问我在容器中运行的应用 - not able to access my app running in container using http://localhost:8080/getAll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM