Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Changing lambda API and server to listen in the same port #235

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions provided/run/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,16 @@ func main() {
os.Setenv("AWS_DEFAULT_REGION", curContext.Region)
os.Setenv("_X_AMZN_TRACE_ID", curContext.XAmznTraceID)

runtimeRouter := createRuntimeRouter()

runtimeListener, err := net.Listen("tcp", ":9001")
runtimeListener, err := net.Listen("tcp", ":"+apiPort)
if err != nil {
log.Fatal(err)
return
}

var runtimeServer *http.Server
if apiPort == "9001" {
runtimeServer = &http.Server{Handler: addAPIRoutes(runtimeRouter)}
} else {
runtimeServer = &http.Server{Handler: runtimeRouter}
apiListener, err := net.Listen("tcp", ":"+apiPort)
if err != nil {
log.Fatal(err)
return
}
apiServer := &http.Server{Handler: addAPIRoutes(chi.NewRouter())}
go apiServer.Serve(apiListener)
}

runtimeRouter := createRuntimeRouter()
runtimeServer = &http.Server{Handler: addAPIRoutes(runtimeRouter)}

go runtimeServer.Serve(runtimeListener)

Expand All @@ -181,7 +170,7 @@ func main() {
<-interrupt
} else {
res, err := http.Post(
"http://127.0.0.1:9001/2015-03-31/functions/"+curContext.FnName+"/invocations",
"http://127.0.0.1:"+apiPort+"/2015-03-31/functions/"+curContext.FnName+"/invocations",
"application/json",
bytes.NewBuffer(eventBody),
)
Expand Down Expand Up @@ -272,7 +261,7 @@ func ensureBootstrapIsRunning(context *mockLambdaContext) error {
awsSessionToken := getEnv("AWS_SESSION_TOKEN", os.Getenv("AWS_SECURITY_TOKEN"))

bootstrapCmd.Env = append(os.Environ(),
"AWS_LAMBDA_RUNTIME_API=127.0.0.1:9001",
"AWS_LAMBDA_RUNTIME_API=127.0.0.1:"+apiPort,
"AWS_ACCESS_KEY_ID="+awsAccessKey,
"AWS_SECRET_ACCESS_KEY="+awsSecretKey,
)
Expand Down