0

I created a simple api that reads from json file (passed as input) a key and checks in a database if is present if I test it locally

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

works

how can I test with curl once deployed on AWS?

I am trying with

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

or

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

but does not work with this error

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>%

the input json is something like this

{
    "key1": 1,
    "key2": "abcdefg"
}
cbr
  • 12,563
  • 3
  • 38
  • 63
bruvio
  • 853
  • 1
  • 9
  • 30

1 Answers1

0

Are you sure that this is a GET request? You are passing JSON data to the API which means that you will have to make sure that you are using POST request in your CURL request, in the serverless application that you have written and also in the serverless config file. Once you have that figured, the following CURL request should work:

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"
}'
HawkEye
  • 49
  • 8
  • The method is implemented as a get and the json is an input file used to check if the data inside the json is stored in the database. I also have a post where I still pass a json that is then stored in the database. My problem was figuring out how to call it from terminal – bruvio Apr 25 '21 at 16:07