本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/lambda.Lambda.Invoke方法的典型用法代碼示例。如果您正苦於以下問題:Golang Lambda.Invoke方法的具體用法?Golang Lambda.Invoke怎麽用?Golang Lambda.Invoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aws/aws-sdk-go/service/lambda.Lambda
的用法示例。
在下文中一共展示了Lambda.Invoke方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runOnLambda
//Returns a result and a debug channels. The channels are closed on test run finalization
func runOnLambda(l *lambda.Lambda, cw *cloudwatchlogs.CloudWatchLogs, test *util.TestDescription) (<-chan string, <-chan string) {
result := make(chan string, 1)
debug := make(chan string, 1)
go func() {
defer close(result)
defer close(debug)
name := test.Name
debug <- "Getting old log"
old_invocation_log, err := getLog(cw, name)
if err != nil {
old_invocation_log = ""
}
payload, _ := json.Marshal(test.Event)
invoke_input := &lambda.InvokeInput{
FunctionName: aws.String(name),
InvocationType: aws.String("Event"),
Payload: payload,
}
debug <- "Enqueuing task"
_, err = l.Invoke(invoke_input)
if err != nil {
debug <- fmt.Sprintf("Error invoking function %s ", err)
return
}
timeout := time.Duration(test.Timeout) * time.Second
debug <- "Waiting for task"
now := time.Now()
elapsed := time.After(timeout)
ticker := time.NewTicker(3 * time.Second)
defer ticker.Stop()
log := ""
completed := false
requestId := ""
logGetter := func() (string, error) {
return getLog(cw, name)
}
// waiting for test.Timeout or for the full log whichever occurs first
logWaitLoop:
for {
select {
case <-elapsed:
break logWaitLoop
case <-ticker.C:
log, requestId, completed, err = getLogAndDetectRequestComplete(logGetter, old_invocation_log, requestId)
if err != nil {
debug <- fmt.Sprintf("Error getting log %s ", err)
return
}
if completed {
break logWaitLoop
}
}
}
if !completed {
log, requestId, completed, err = getLogAndDetectRequestComplete(logGetter, old_invocation_log, requestId)
if err != nil {
debug <- fmt.Sprintf("Error getting log %s ", err)
return
}
if !completed {
if requestId != "" {
debug <- fmt.Sprintf("Request Id: %s", requestId)
}
debug <- time.Now().Sub(now).String()
logLines := strings.Split(log, "\n")
switch len(logLines) {
case 0:
debug <- "Log for current test run is empty"
case 1:
debug <- fmt.Sprintf("Log does not contain entries for current test run:\n%s", logLines[0])
default:
debug <- fmt.Sprintf("Log does not contain entries for current test run:\n%s\n...\n%s", logLines[0], logLines[len(logLines)-1])
}
return
}
}
debug <- fmt.Sprintf("Request Id: %s", requestId)
final, err := cleanLambda(log)
if err != nil {
debug <- fmt.Sprintf("Error cleaning log %s", err)
return
}
result <- final
}()
return result, debug
}