簡體   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)

本地堆棧 12.5

用於 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)

在處理程序中,當我調用另一個容器中的 get api 時,我收到連接被拒絕的錯誤。

錯誤:"ConnectionError","errorMessage":"HTTPConnectionPool(host='localhost', port=9090): Max retries exceeded with url: Caused by NewConnectionError('\ : Failed to build一個新的連接:

但是通過郵遞員,我可以訪問 http://localhost:9090/ping API

另外,如果我替換 x = requests.get('https://w3schools.com') 那么我得到 200 。

該問題已通過在 localstack 中添加以下 env 變量解決

LAMBDA_DOCKER_NETWORK="主機"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM