@@ -86,24 +86,51 @@ the lambda does not utilize them in request payload.
8686
87873 . In another terminal, perform an HTTP request via another ` Makefile ` command:
8888
89+ The server's baseline readiness can be confirmed via the ping action:
8990``` shell
9091make sam-http-ping
9192```
9293
93- Response should have an HTTP status of ` 200 ` and respond with:
94+ The response should have an HTTP status of ` 200 ` and respond with:
9495
9596``` json
9697{
9798 "response" : " pong"
9899}
99100```
100101
102+ Actual predictions can be sent in via the predict action:
103+
104+ ``` shell
105+ make sam-http-predict
106+ ```
107+
108+ ``` json
109+ {
110+ "response" : " True"
111+ }
112+ ```
113+
114+ Custom payloads can be found in the ` tests/sam ` directory, and the default payload overridden via the ` PAYLOAD ` Makefile
115+ argument:
116+
117+ ``` shell
118+ make sam-http-predict PAYLOAD=tests/sam/noncitation.json
119+ ```
120+
121+ ``` json
122+ {
123+ "response" : " False"
124+ }
125+ ```
126+
101127### Invoking lambda directly
102128
103129While lambdas can be invoked via HTTP methods (ALB, Function URL, etc), they are also often invoked directly with an
104130` event ` payload. To do so with SAM, you do ** not** need to first start an HTTP server with ` make sam-run ` , you can
105131invoke the function image directly:
106132
133+ #### Example 1: ping
107134``` shell
108135echo ' {"action": "ping", "challenge_secret": "secret_phrase"}' | sam local invoke --env-vars tests/sam/env.json -e -
109136```
@@ -115,7 +142,23 @@ Response:
115142false, "body": "{\"response\": \"pong\"}"}
116143```
117144
118- As you can see from this response, the lambda is still returning a dictionary that _ would_ work for an HTTP response,
145+ #### Example 2: predict
146+
147+ The JSON files with example payloads in ` tests/sam ` can be helpful for working with the ` predict ` action, rather than
148+ trying to include all features and values directly within an echo command:
149+
150+ ``` shell
151+ echo " $( cat tests/sam/citation.json) " | sam local invoke --env-vars tests/sam/env.json -e -
152+ ```
153+
154+ Response:
155+
156+ ``` text
157+ {"statusCode": 200, "statusDescription": "200 OK", "headers": {"Content-Type": "application/json"}, "isBase64Encoded":
158+ false, "body": "{\"response\": \"True\"}"}
159+ ```
160+
161+ As you can see from these responses, the lambda is still returning a dictionary that _ would_ work for an HTTP response,
119162but is actually just a dictionary with the required information.
120163
121164It's unknown at this time if this lambda will get invoked via non-HTTP methods, but SAM will be helpful for testing and
0 commit comments