Skip to content

Commit

Permalink
Address PR feedback: add short form -l + pass duration to Invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
acmcelwee committed Apr 28, 2023
1 parent cfbd9dc commit 6ed8e01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 4 additions & 7 deletions awslambdarpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Available options:
path to the event JSON to be used as input
-d, --data
data passed to the function as input, in JSON format, defaults to "{}"
-l, --execution-limit
maximum execution limit for your handler, expressed as a duration, defaults to 15s
help, -h, --help
show this help
Expand All @@ -35,7 +37,6 @@ import (
"os"
"time"

"github.com/aws/aws-lambda-go/lambda/messages"
"github.com/blmayer/awslambdarpc/client"
)

Expand Down Expand Up @@ -96,7 +97,7 @@ func main() {
case "-d", "--data":
i++
payload = []byte(os.Args[i])
case "--execution-limit":
case "-l", "--execution-limit":
i++
duration, err := time.ParseDuration(os.Args[i])
if err != nil {
Expand All @@ -114,11 +115,7 @@ func main() {
}
}

deadline := time.Now().Add(executionLimit)
res, err := client.Invoke(addr, payload, messages.InvokeRequest_Timestamp{
Seconds: deadline.Unix(),
Nanos: int64(deadline.Nanosecond()),
})
res, err := client.Invoke(addr, payload, executionLimit)
if err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(-2)
Expand Down
9 changes: 7 additions & 2 deletions client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package client
import (
"fmt"
"net/rpc"
"time"

"github.com/aws/aws-lambda-go/lambda/messages"
)
Expand All @@ -15,8 +16,12 @@ import (
// to the lambda function as body.
// If the lambda returned an error then this function will return
// the error message in the error interface
func Invoke(addr string, data []byte, deadline messages.InvokeRequest_Timestamp) ([]byte, error) {
request := messages.InvokeRequest{Payload: data, Deadline: deadline}
func Invoke(addr string, data []byte, executionLimit time.Duration) ([]byte, error) {
deadline := time.Now().Add(executionLimit)
request := messages.InvokeRequest{Payload: data, Deadline: messages.InvokeRequest_Timestamp{
Seconds: deadline.Unix(),
Nanos: int64(deadline.Nanosecond()),
}}
client, err := rpc.Dial("tcp", addr)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6ed8e01

Please sign in to comment.