flogo icon indicating copy to clipboard operation
flogo copied to clipboard

Lambda trigger executes build.go

Open retgits opened this issue 7 years ago • 2 comments

Current behavior (how does the issue manifest): When you're building a Flogo app using the Go API with a Lambda trigger, the go generate command tries to execute the build.go script from the Lambda trigger. This file expects a certain structure of folders which doesn't work with apps built using the Go API.

Expected behavior: Don't execute the build.go file if you're building a Flogo app using the Go API

Minimal steps to reproduce the problem (not required if feature enhancement):

Sample code

//go:generate go run ../../../TIBCOSoftware/flogo-lib/flogo/gen/gen.go -shim $GOPATH

package main

import (
	"context"
	"fmt"

	"github.com/TIBCOSoftware/flogo-contrib/activity/log"
	_ "github.com/TIBCOSoftware/flogo-contrib/activity/log"
	"github.com/TIBCOSoftware/flogo-contrib/trigger/lambda"
	"github.com/TIBCOSoftware/flogo-lib/core/data"
	"github.com/TIBCOSoftware/flogo-lib/flogo"
)

func shimApp() *flogo.App {

	app := flogo.NewApp()

	trg := app.NewTrigger(&lambda.LambdaTrigger{}, nil)
	trg.NewFuncHandler(nil, RunActivities)

	return app
}

func RunActivities(ctx context.Context, inputs map[string]*data.Attribute) (map[string]*data.Attribute, error) {

	fmt.Println(ctx)
	fmt.Println(inputs)

	in := map[string]interface{}{"message": "test"}
	_, err := flogo.EvalActivity(&log.LogActivity{}, in)

	if err != nil {
		return nil, err
	}

	response := make(map[string]interface{})

	response["id"] = "123"
	response["ref"] = "ref://blah"
	response["amount"] = "1"
	response["balance"] = "500"
	response["currency"] = "USD"

	ret := make(map[string]*data.Attribute)
	ret["code"], _ = data.NewAttribute("code", data.TypeInteger, 200)
	ret["data"], _ = data.NewAttribute("code", data.TypeAny, response)

	return ret, nil
}

Running go generate will create the shim.go and shim_support.go files, and will also try to execute the build.go file from the Lambda trigger (which will fail). After this you can run:

GOOS=linux go build
zip myapp.zip <app>

After that, uploading the zip to Lambda works perfectly!

(see https://github.com/TIBCOSoftware/flogo/issues/321)

Please tell us about your environment (Operating system, docker version, browser & web ui version, etc): Flogo 0.5.5 with the api_shim_gen branch of flogo-lib

Flogo version (CLI & contrib/lib. If unknown, leave empty or state unknown): 0.5.5

retgits avatar Jul 26 '18 18:07 retgits

What exactly fails? does it not create the zip, or is the zip structure incorrect?

fm-tibco avatar Jul 26 '18 19:07 fm-tibco

It’s the content of the zip that isn’t correct. When you use “Flogo build” to create a regular Flogo app for lambda it will generate an executable called “handler”. The build.go file expects the executable to exist in a specific folder. As you’re developing your own code, that folder structure doesn’t exist and neither does the executable. To fix it, we’d either need to pass in an additional flag that the command comes from the Go api, or have the build.go check for the existence of a JSON file and skip certain steps of that doesn’t exist

retgits avatar Jul 26 '18 19:07 retgits