从AWS Lambda Python函数发送Python API请求错误



我正在尝试从AWS python lambda函数发送POST请求,但在发送时出现以下错误:

[ERROR] ConnectionError: HTTPConnectionPool(host= . net********************s3-website.ap-south-1.amazonaws.com', port=80): url:/的重试次数超过了最大重试次数(由NewConnectionError(':建立新连接失败:[Errno 110] connection timed out'))回溯(最近一次调用):

!(响应)

我尝试了以下代码:

import json
import uuid
import datetime
import re
import base64
import requests
import httpx
import asyncio
def lambda_handler(event,context):
INVENTORY_CP_OPERATION_URL="************.s3-website.ap-south- 
1.amazonaws.com/"
message={
"email":"*******@********.com",
"password":"123456"
}
result=requests.post(**************,json=message)
return "success".

考虑到您的Connection timed out,您的AWS Lambda函数似乎难以连接到互联网。

当AWS Lambda函数NOT连接到VPC

但是,当Lambda函数连接到VPC时,,只有当Lambda函数连接到私有子网,并且在公共子网中有NAT网关时,它才能访问Internet。

因此,如果该函数不需要访问VPC中的任何资源(例如Amazon RDS数据库),那么最好将从VPC断开连接。.

最新更新