• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang lambda.Lambda类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/lambda.Lambda的典型用法代码示例。如果您正苦于以下问题:Golang Lambda类的具体用法?Golang Lambda怎么用?Golang Lambda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Lambda类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: createLambdaFunction

func (infra *Infrastructure) createLambdaFunction(svc *lambda.Lambda, roleArn string, payload []byte) error {
	function, err := svc.CreateFunction(&lambda.CreateFunctionInput{
		Code: &lambda.FunctionCode{
			ZipFile: payload,
		},
		FunctionName: aws.String("goad"),
		Handler:      aws.String("index.handler"),
		Role:         aws.String(roleArn),
		Runtime:      aws.String("nodejs"),
		MemorySize:   aws.Int64(1536),
		Publish:      aws.Bool(true),
		Timeout:      aws.Int64(300),
	})
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Calling this function too soon after creating the role might
			// fail, so we should retry after a little while.
			// TODO: limit the number of retries.
			if awsErr.Code() == "InvalidParameterValueException" {
				time.Sleep(time.Second)
				return infra.createLambdaFunction(svc, roleArn, payload)
			}
		}
		return err
	}
	return createLambdaAlias(svc, function.Version)
}
开发者ID:goadapp,项目名称:goad,代码行数:27,代码来源:infrastructure.go


示例2: lambdaPermissionExists

func lambdaPermissionExists(rs *terraform.ResourceState, conn *lambda.Lambda) (*LambdaPolicyStatement, error) {
	params := &lambda.GetPolicyInput{
		FunctionName: aws.String(rs.Primary.Attributes["function_name"]),
	}
	if v, ok := rs.Primary.Attributes["qualifier"]; ok {
		params.Qualifier = aws.String(v)
	}

	resp, err := conn.GetPolicy(params)
	if err != nil {
		return nil, fmt.Errorf("Lambda policy not found: %q", err)
	}

	if resp.Policy == nil {
		return nil, fmt.Errorf("Received Lambda policy is empty")
	}

	policyInBytes := []byte(*resp.Policy)
	policy := LambdaPolicy{}
	err = json.Unmarshal(policyInBytes, &policy)
	if err != nil {
		return nil, fmt.Errorf("Error unmarshalling Lambda policy: %s", err)
	}

	return findLambdaPolicyStatementById(&policy, rs.Primary.ID)
}
开发者ID:fromonesrc,项目名称:terraform,代码行数:26,代码来源:resource_aws_lambda_permission_test.go


示例3: createLambdaAlias

func createLambdaAlias(svc *lambda.Lambda, functionVersion *string) error {
	_, err := svc.CreateAlias(&lambda.CreateAliasInput{
		FunctionName:    aws.String("goad"),
		FunctionVersion: functionVersion,
		Name:            aws.String(version.LambdaVersion()),
	})
	return err
}
开发者ID:goadapp,项目名称:goad,代码行数:8,代码来源:infrastructure.go


示例4: updateLambdaFunction

func (infra *Infrastructure) updateLambdaFunction(svc *lambda.Lambda, roleArn string, payload []byte) error {
	function, err := svc.UpdateFunctionCode(&lambda.UpdateFunctionCodeInput{
		ZipFile:      payload,
		FunctionName: aws.String("goad"),
		Publish:      aws.Bool(true),
	})
	if err != nil {
		return err
	}
	return createLambdaAlias(svc, function.Version)
}
开发者ID:goadapp,项目名称:goad,代码行数:11,代码来源:infrastructure.go


示例5: listVersionsByFunctionPages

func listVersionsByFunctionPages(c *lambda.Lambda, input *lambda.ListVersionsByFunctionInput,
	fn func(p *lambda.ListVersionsByFunctionOutput, lastPage bool) bool) error {
	for {
		page, err := c.ListVersionsByFunction(input)
		if err != nil {
			return err
		}
		lastPage := page.NextMarker == nil

		shouldContinue := fn(page, lastPage)
		if !shouldContinue || lastPage {
			break
		}
	}
	return nil
}
开发者ID:hashicorp,项目名称:terraform,代码行数:16,代码来源:resource_aws_lambda_function.go


示例6: lambdaExists

func lambdaExists(svc *lambda.Lambda) (bool, error) {
	_, err := svc.GetFunction(&lambda.GetFunctionInput{
		FunctionName: aws.String("goad"),
	})

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			if awsErr.Code() == "ResourceNotFoundException" {
				return false, nil
			}
		}
		return false, err
	}

	return true, nil
}
开发者ID:goadapp,项目名称:goad,代码行数:16,代码来源:infrastructure.go


示例7: isLambdaPermissionGone

func isLambdaPermissionGone(rs *terraform.ResourceState, conn *lambda.Lambda) error {
	params := &lambda.GetPolicyInput{
		FunctionName: aws.String(rs.Primary.Attributes["function_name"]),
	}
	if v, ok := rs.Primary.Attributes["qualifier"]; ok {
		params.Qualifier = aws.String(v)
	}

	resp, err := conn.GetPolicy(params)
	if awsErr, ok := err.(awserr.Error); ok {
		if awsErr.Code() == "ResourceNotFoundException" {
			// no policy found => all statements deleted
			return nil
		}
	}
	if err != nil {
		return fmt.Errorf("Unexpected error when checking existence of Lambda permission: %s\n%s",
			rs.Primary.ID, err)
	}

	policyInBytes := []byte(*resp.Policy)
	policy := LambdaPolicy{}
	err = json.Unmarshal(policyInBytes, &policy)
	if err != nil {
		return fmt.Errorf("Error unmarshalling Lambda policy (%s): %s", *resp.Policy, err)
	}

	state, err := findLambdaPolicyStatementById(&policy, rs.Primary.ID)
	if err != nil {
		// statement not found => deleted
		return nil
	}

	return fmt.Errorf("Policy statement expected to be gone (%s):\n%s",
		rs.Primary.ID, *state)
}
开发者ID:fromonesrc,项目名称:terraform,代码行数:36,代码来源:resource_aws_lambda_permission_test.go


示例8: createLambdaFunction

func createLambdaFunction(l *lambda.Lambda, code []byte, runtime, role, name, handler string, timeout int) error {
	func_input := &lambda.CreateFunctionInput{
		Code:         &lambda.FunctionCode{ZipFile: code},
		Runtime:      aws.String(runtime),
		Role:         aws.String(role),
		FunctionName: aws.String(name),
		Handler:      aws.String(handler),
		Timeout:      aws.Int64(int64(timeout)),
	}

	resp, err := l.CreateFunction(func_input)
	if err != nil {
		if err.(awserr.Error).Code() == "ResourceConflictException" {
			log.Println("Function already exists, trying to update code")
			input := &lambda.UpdateFunctionCodeInput{
				FunctionName: aws.String(name),
				ZipFile:      code,
			}

			resp, err = l.UpdateFunctionCode(input)
			if err != nil {
				log.Println("Could not update function code", err)
				return err
			}

			configInput := &lambda.UpdateFunctionConfigurationInput{
				FunctionName: aws.String(name),
				Handler:      aws.String(handler),
				Timeout:      aws.Int64(int64(timeout)),
			}
			resp, err = l.UpdateFunctionConfiguration(configInput)
			if err != nil {
				log.Println("Could not update function configuration", err)
				return err
			}

		} else {
			return err
		}
	}

	log.Println(resp)
	return nil
}
开发者ID:iron-io,项目名称:lambda,代码行数:44,代码来源:main.go


示例9: 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
}
开发者ID:iron-io,项目名称:lambda,代码行数:98,代码来源:lambda.go



注:本文中的github.com/aws/aws-sdk-go/service/lambda.Lambda类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang machinelearning.New函数代码示例发布时间:2022-05-24
下一篇:
Golang lambda.FunctionCode类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap