You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地AWS Lambda容器无法通过curl/httr2调用的问题排查

本地AWS Lambda容器调用异常:curl与httr2报错,Postman/Wget正常

问题概述

部署本地AWS Lambda容器后,Postman测试可正常获取响应、查看日志,但使用curl终端命令或R语言httr2包调用时均出现错误。

curl命令相关问题及现象

  1. 初始curl命令(Postman生成,与AWS官方测试命令类似):
curl --location --request GET 'http://localhost:9000/2015-03-31/functions/function/invocations' \
--header 'Content-Type: text/plain' \
--data '{
    ...
}'

执行后返回错误:curl: (1) Received HTTP/0.9 when not allowed

  1. 添加--http0.9参数后:
    出现以下警告:
Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.
  1. 再添加--output -参数后:
    终端仅显示部分内容,无完整结果返回:
?:000
User-Agent: curl/7.86.0
Accept: */*
Content-Type: txt/json
Content-Length: 402

{
    ...
  1. 对比:wget命令正常工作
    Postman生成的等价wget命令可正常调用,能查看日志并获取输出:
wget --no-check-certificate --quiet \
  --method GET \
  --timeout=0 \
  --header 'Content-Type: text/plain' \
  --body-data '{
    ...
}' \
   'http://localhost:9000/2015-03-31/functions/function/invocations'

R语言httr2调用代码

以下是用于调用的httr2代码片段,执行时同样出现错误:

library(httr2)

url <- "http://localhost:9000/2015-03-31/functions/function/invocations"

req <- request(url)

headers = c(
  'Content-Type' = 'text/plain'
)

body = list(
    # 自定义请求体内容
)

req <- req |>
    req_headers(
        'Content-Type' = 'text/plain'
    )  |>
    req_body_json(body)

result <- req |> req_method("GET") |> req_perform()

内容的提问来源于stack exchange,提问作者clabornd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 08:25:20