Skip to content

Commit

Permalink
Merge pull request #3 from jdgiotta/feature/timeout-option
Browse files Browse the repository at this point in the history
Timeout with Refactored File Input Flags
  • Loading branch information
joffotron authored Feb 16, 2018
2 parents 06704c5 + eeccf61 commit 7cc796f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ go run !(*_test).go &
LAMBDA_PID=$!
trap kill_lambda EXIT

_LAMBDA_SERVER_PORT=${RPC_PORT} bin/run-go-lambda ${TEST_FILE}
_LAMBDA_SERVER_PORT=${RPC_PORT} bin/run-go-lambda -f ${TEST_FILE} -t 300

20 changes: 19 additions & 1 deletion src/run-go-lambda/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/run-go-lambda/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
[[constraint]]
name = "github.com/cenkalti/backoff"
version = "1.1.0"

[[constraint]]
name = "github.com/spf13/cobra"
version = "0.0.1"
39 changes: 34 additions & 5 deletions src/run-go-lambda/run-go-lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,58 @@ import (
"github.com/cenkalti/backoff"

"github.com/aws/aws-lambda-go/lambda/messages"
"github.com/spf13/cobra"
)

func main() {
args := &messages.InvokeRequest{
var (
rootCmd = &cobra.Command{
Use: "run-go-lambda",
RunE: invoke,
}
timeout int64
payloadFile string
)

// initialize command options
func init() {
rootCmd.Flags().Int64VarP(&timeout, "timeout", "t", 300, "duration of timeout")
rootCmd.Flags().StringVarP(&payloadFile, "file", "f", "", "JSON file")
rootCmd.MarkFlagRequired("file")
}

// invoke the lambda
func invoke(cmd *cobra.Command, args []string) error {

req := &messages.InvokeRequest{
Payload: readPayload(),
RequestId: "1",
XAmznTraceId: "1",
Deadline: messages.InvokeRequest_Timestamp{Seconds: 300, Nanos: 0},
Deadline: messages.InvokeRequest_Timestamp{Seconds: timeout, Nanos: 0},
InvokedFunctionArn: "arn:aws:lambda:an-antarctica-1:123456789100:function:test",
}

client := connect()

var response *messages.InvokeResponse
err := client.Call("Function.Invoke", args, &response)
err := client.Call("Function.Invoke", req, &response)

if err != nil {
log.Println("Invocation:", err)
log.Fatal("Response:", response)
return err
}
return nil
}

func main() {
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}

}

func readPayload() []byte {
payload, err := ioutil.ReadFile(os.Args[1])
payload, err := ioutil.ReadFile(payloadFile)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 7cc796f

Please sign in to comment.