@@ -5,11 +5,13 @@ import (
55 "bytes"
66 "encoding/json"
77 "fmt"
8+ "io"
9+ "net/http"
10+
11+ "github.com/aws/aws-lambda-runtime-interface-emulator/internal/lsapi"
812 "github.com/go-chi/chi"
913 "github.com/go-chi/chi/middleware"
1014 log "github.com/sirupsen/logrus"
11- "io"
12- "net/http"
1315)
1416
1517const apiPort = 9563
@@ -30,7 +32,7 @@ func main() {
3032 router .Post ("/status/{runtime_id}/{status}" , statusHandler )
3133
3234 router .Get ("/success" , func (w http.ResponseWriter , r * http.Request ) {
33- invokeRequest , _ := json .Marshal (InvokeRequest {InvokeId : uid , Payload : "{\" counter\" :0}" })
35+ invokeRequest , _ := json .Marshal (lsapi. InvokeRequest {InvokeId : uid , Payload : "{\" counter\" :0}" })
3436 _ , err := http .Post (invokeUrl , "application/json" , bytes .NewReader (invokeRequest ))
3537 if err != nil {
3638 log .Error (err )
@@ -44,7 +46,7 @@ func main() {
4446 })
4547
4648 router .Get ("/fail" , func (w http.ResponseWriter , r * http.Request ) {
47- invokeRequest , _ := json .Marshal (InvokeRequest {InvokeId : uid , Payload : "{\" counter\" :0, \" fail\" : \" yes\" }" })
49+ invokeRequest , _ := json .Marshal (lsapi. InvokeRequest {InvokeId : uid , Payload : "{\" counter\" :0, \" fail\" : \" yes\" }" })
4850 _ , err := http .Post (invokeUrl , "application/json" , bytes .NewReader (invokeRequest ))
4951 if err != nil {
5052 log .Error (err )
@@ -67,7 +69,7 @@ func main() {
6769func invokeLogsHandler (w http.ResponseWriter , r * http.Request ) {
6870 invokeId := chi .URLParam (r , "invoke_id" )
6971 log .Println (invokeId )
70- var logResponse LogResponse
72+ var logResponse lsapi. LogResponse
7173 if err := json .NewDecoder (r .Body ).Decode (& logResponse ); err != nil {
7274 log .Error ("invalid logs payload: " , err )
7375 } else {
@@ -76,26 +78,13 @@ func invokeLogsHandler(w http.ResponseWriter, r *http.Request) {
7678 w .WriteHeader (http .StatusAccepted )
7779}
7880
79- // InvokeRequest is sent by LocalStack to trigger an invocation.
80- type InvokeRequest struct {
81- InvokeId string `json:"invoke-id"`
82- InvokedFunctionArn string `json:"invoked-function-arn"`
83- Payload string `json:"payload"`
84- TraceId string `json:"trace-id"`
85- }
86-
87- // LogResponse is sent by the runtime to report logs for a completed invocation.
88- type LogResponse struct {
89- Logs string `json:"logs"`
90- }
91-
9281func statusHandler (w http.ResponseWriter , r * http.Request ) {
9382 runtime_id := chi .URLParam (r , "runtime_id" )
9483 status := chi .URLParam (r , "status" )
9584 log .Println (runtime_id + " + " + status )
9685 if status == "ready" {
9786 go func () {
98- invokeRequest , _ := json .Marshal (InvokeRequest {InvokeId : "12345" , Payload : "{\" counter\" :0}" })
87+ invokeRequest , _ := json .Marshal (lsapi. InvokeRequest {InvokeId : "12345" , Payload : "{\" counter\" :0}" })
9988 _ , err := http .Post (invokeUrl , "application/json" , bytes .NewReader (invokeRequest ))
10089 if err != nil {
10190 log .Error (err )
0 commit comments