【问题标题】:pass json file to serverless lambda将 json 文件传递​​给无服务器 lambda
【发布时间】:2023-03-28 06:49:01
【问题描述】:

我创建了一个简单的 api,它从 json 文件(作为输入传递)读取一个键并检查数据库是否存在 如果我在本地测试它

 serverless invoke local --function getVin --path input/input_212.json

作品

在 AWS 上部署后如何使用 curl 进行测试?

我正在尝试

curl --request GET 'https://xxxx.execute-api.us-east-1.amazonaws.com/dev/vin' --header 'content-type: text/plain' --data-raw  @input.json

curl -H "Content-Type: application/json" -X GET -d '{
    "CustomerId": 213,
    "VIN": "WDBJF65J1YB039213"
    }' https://xxxxx.execute-api.us-east-1.amazonaws.com/dev/vin

但不适用于此错误

curl -H "Content-Type: application/json" -X GET -d '{
"CustomerId": 213,
"VIN": "WDBJF65J1YB039213"
}' https://xxxxx.execute-api.us-east-1.amazonaws.com/dev/vin
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: iMPlncZFM2NQcVwotAWQmbear6akaktsKVTyin6Mmqcd7T5z0_Vijw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>%

输入的 json 是这样的

{
    "key1": 1,
    "key2": "abcdefg"
}

【问题讨论】:

标签: python amazon-web-services curl aws-lambda serverless


【解决方案1】:

您确定这是一个 GET 请求吗?您将 JSON 数据传递给 API,这意味着您必须确保在 CURL 请求、您编写的无服务器应用程序以及无服务器配置文件中使用 POST 请求。一旦你明白了,下面的 CURL 请求应该可以工作:

curl --request POST \
  --url https://xxxxx.execute-api.us-east-1.amazonaws.com/dev/vin \
  --header 'Content-Type: application/json' \
  --data '{
    "CustomerId": 213,
    "VIN": "WDBJF65J1YB039213"
}'

【讨论】:

  • 该方法实现为get,json是一个输入文件,用于检查json里面的数据是否存储在数据库中。我还有一个帖子,我仍然传递一个 json,然后将其存储在数据库中。我的问题是弄清楚如何从终端调用它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
相关资源
最近更新 更多