Lambda handler trigger temporal client and workflow creation

I am trying to trigger a go function that will create a new client and execute temporal workflow by using lambda.Start(Handler) as the main point to trigger the whole workflow.

While I try to invoke the function the simple parameter passing works however creating a new client.NewClient(client.Options{}) did not work. It’s getting stuck with errors. Not sure what I am doing wring here.

func Handler(somedata workflow.Test) (string, error) {
	val, _ := json.MarshalIndent(somedata, "", "    ")
	log.Printf(
		"\nvideopost: %s",
		string(val),
	)
	// Create the client object just once per process
	c, err := client.NewClient(client.Options{})
	if err != nil {
		log.Fatalln("unable to create Temporal client", err)
	}
	defer c.Close()
	return "test hurrah!", nil
}


func main() {
	lambda.Start(Handler)
}

any feedback/guidance is appreciated! Not sure if that’s related to any permission issues.

It’s getting stuck with errors.

What errors are you getting? Are they Temporal or lambda specific?
Also I’m not lambda expert so could be wrong, but looking at their docs I wonder if it would make sense to initialize Temporal client in the global init function rather than in the handler? Creating client is typically a heavy weight operation and could be created once in init and reused across multiple handler calls here.

an error was just time out from serverless while initializing temporal client. I will give global init a shot probably that might resolve it.

Are you specifying the Temporal service endpoint in the client.Options?

Nope, I was just testing things locally and kept everything simple. Similar to what’s out there in the tutorial . I was getting timeouts, It’s due to the permission issue. It took quite a long time to get back to the error. I am new to go and temporal, thanks @tihomir for the idea. However, in my case, there is going to be a single lambda handler. Lambda will get some event which in turn should initialize the temporal client and delegate that to EKS. Global init for initializing the temporal client wouldn’t make any difference since the memory is ephemeral.