當前位置: 首頁>>代碼示例>>Golang>>正文


Golang lambda.New函數代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/lambda.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addToLambda

func addToLambda(dir string) error {
	desc, err := util.ReadTestDescription(dir)
	if err != nil {
		return err
	}

	var zipContents []byte
	if desc.Runtime == "java8" {
		zipContents, err = ioutil.ReadFile(filepath.Join(dir, "test-build.jar"))
		if err != nil {
			return err
		}
	} else {
		zipContents, err = makeZip(dir)
		if err != nil {
			return err
		}
	}

	s := session.New(&aws.Config{Region: aws.String("us-east-1"), Credentials: credentials.NewEnvCredentials()})

	l := lambda.New(s)

	err = createLambdaFunction(l, zipContents, desc.Runtime, lambdaRole, desc.Name, desc.Handler, desc.Timeout)
	return err
}
開發者ID:iron-io,項目名稱:lambda,代碼行數:26,代碼來源:main.go

示例2: ExampleLambda_UpdateFunctionCode

func ExampleLambda_UpdateFunctionCode() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := lambda.New(sess)

	params := &lambda.UpdateFunctionCodeInput{
		FunctionName:    aws.String("FunctionName"), // Required
		Publish:         aws.Bool(true),
		S3Bucket:        aws.String("S3Bucket"),
		S3Key:           aws.String("S3Key"),
		S3ObjectVersion: aws.String("S3ObjectVersion"),
		ZipFile:         []byte("PAYLOAD"),
	}
	resp, err := svc.UpdateFunctionCode(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:acquia,項目名稱:fifo2kinesis,代碼行數:29,代碼來源:examples_test.go

示例3: ExampleLambda_InvokeAsync

func ExampleLambda_InvokeAsync() {
	svc := lambda.New(nil)

	params := &lambda.InvokeAsyncInput{
		FunctionName: aws.String("FunctionName"),         // Required
		InvokeArgs:   bytes.NewReader([]byte("PAYLOAD")), // Required
	}
	resp, err := svc.InvokeAsync(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, the SDK should always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
開發者ID:jasonmoo,項目名稱:aws-sdk-go,代碼行數:27,代碼來源:examples_test.go

示例4: InvokeLambda

func (s *Service) InvokeLambda(payload *bridge.Request) (br bridge.Response) {
	if s.lamdbaSvc == nil {
		// Setup the AWS Creds.
		c := aws.NewConfig().WithCredentials(credentials.NewStaticCredentials(s.AWS.AccessKey, s.AWS.SecretKey, "")).WithRegion(s.AWS.Region)
		s.lamdbaSvc = lambda.New(session.New(c))
	}

	params := &lambda.InvokeInput{
		FunctionName: aws.String(s.FunctionName),
		Payload:      payload.JSON(),
	}

	resp, err := s.lamdbaSvc.Invoke(params)
	if err != nil {
		return bridge.ErrorResponse(fmt.Sprintf("lambda invoke error %v", err))
	}

	// Pretty-print the response data.
	log.Println("lambda response", string(resp.Payload))

	err = json.Unmarshal(resp.Payload, &br)
	if err != nil {
		log.Println("failed to unmarshal response", err)
		return bridge.ErrorResponse("failed to unmarshal response")
	}

	return
}
開發者ID:acksin,項目名稱:bridge,代碼行數:28,代碼來源:service.go

示例5: ExampleLambda_UpdateAlias

func ExampleLambda_UpdateAlias() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := lambda.New(sess)

	params := &lambda.UpdateAliasInput{
		FunctionName:    aws.String("FunctionName"), // Required
		Name:            aws.String("Alias"),        // Required
		Description:     aws.String("Description"),
		FunctionVersion: aws.String("Version"),
	}
	resp, err := svc.UpdateAlias(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:acquia,項目名稱:fifo2kinesis,代碼行數:27,代碼來源:examples_test.go

示例6: ExampleLambda_ListFunctions

func ExampleLambda_ListFunctions() {
	svc := lambda.New(nil)

	params := &lambda.ListFunctionsInput{
		Marker:   aws.String("String"),
		MaxItems: aws.Int64(1),
	}
	resp, err := svc.ListFunctions(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, the SDK should always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.Prettify(resp))
}
開發者ID:Talos208,項目名稱:aws-sdk-go,代碼行數:27,代碼來源:examples_test.go

示例7: ExampleLambda_AddPermission

func ExampleLambda_AddPermission() {
	svc := lambda.New(session.New())

	params := &lambda.AddPermissionInput{
		Action:           aws.String("Action"),       // Required
		FunctionName:     aws.String("FunctionName"), // Required
		Principal:        aws.String("Principal"),    // Required
		StatementId:      aws.String("StatementId"),  // Required
		EventSourceToken: aws.String("EventSourceToken"),
		Qualifier:        aws.String("Qualifier"),
		SourceAccount:    aws.String("SourceOwner"),
		SourceArn:        aws.String("Arn"),
	}
	resp, err := svc.AddPermission(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:ColourboxDevelopment,項目名稱:aws-sdk-go,代碼行數:25,代碼來源:examples_test.go

示例8: CreateLambda

func (b *Build) CreateLambda() error {

	zipBytes, err := ioutil.ReadFile(b.Directory + ".zip")
	if err != nil {
		return err
	}

	svc := lambda.New(&aws.Config{Region: aws.String("us-east-1")})

	params := &lambda.CreateFunctionInput{
		Code: &lambda.FunctionCode{
			ZipFile: zipBytes,
		},
		FunctionName: aws.String(b.Directory),                                             // Required
		Handler:      aws.String("handler_example.handler"),                               // Required
		Role:         aws.String("arn:aws:iam::651778473396:role/lambda_basic_execution"), // Required
		Runtime:      aws.String("nodejs"),                                                // Required
		// Description:  aws.String("nodejs"),
		MemorySize: aws.Int64(150),
		Timeout:    aws.Int64(3),
	}
	resp, err := svc.CreateFunction(params)
	_ = resp
	if err != nil {
		return err
	}
	return nil
}
開發者ID:maxmcd,項目名稱:gitbao,代碼行數:28,代碼來源:builder.go

示例9: ExampleLambda_UpdateFunctionConfiguration

func ExampleLambda_UpdateFunctionConfiguration() {
	svc := lambda.New(nil)

	params := &lambda.UpdateFunctionConfigurationInput{
		FunctionName: aws.String("FunctionName"), // Required
		Description:  aws.String("Description"),
		Handler:      aws.String("Handler"),
		MemorySize:   aws.Int64(1),
		Role:         aws.String("RoleArn"),
		Timeout:      aws.Int64(1),
	}
	resp, err := svc.UpdateFunctionConfiguration(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, the SDK should always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.Prettify(resp))
}
開發者ID:Talos208,項目名稱:aws-sdk-go,代碼行數:31,代碼來源:examples_test.go

示例10: ExampleLambda_RemovePermission

func ExampleLambda_RemovePermission() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := lambda.New(sess)

	params := &lambda.RemovePermissionInput{
		FunctionName: aws.String("FunctionName"), // Required
		StatementId:  aws.String("StatementId"),  // Required
		Qualifier:    aws.String("Qualifier"),
	}
	resp, err := svc.RemovePermission(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:acquia,項目名稱:fifo2kinesis,代碼行數:26,代碼來源:examples_test.go

示例11: ExampleLambda_RemovePermission

func ExampleLambda_RemovePermission() {
	svc := lambda.New(nil)

	params := &lambda.RemovePermissionInput{
		FunctionName: aws.String("FunctionName"), // Required
		StatementID:  aws.String("StatementId"),  // Required
	}
	resp, err := svc.RemovePermission(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, the SDK should always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.Prettify(resp))
}
開發者ID:Talos208,項目名稱:aws-sdk-go,代碼行數:27,代碼來源:examples_test.go

示例12: ExampleLambda_InvokeAsync

func ExampleLambda_InvokeAsync() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := lambda.New(sess)

	params := &lambda.InvokeAsyncInput{
		FunctionName: aws.String("FunctionName"),         // Required
		InvokeArgs:   bytes.NewReader([]byte("PAYLOAD")), // Required
	}
	resp, err := svc.InvokeAsync(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:acquia,項目名稱:fifo2kinesis,代碼行數:25,代碼來源:examples_test.go

示例13: ExampleLambda_ListVersionsByFunction

func ExampleLambda_ListVersionsByFunction() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := lambda.New(sess)

	params := &lambda.ListVersionsByFunctionInput{
		FunctionName: aws.String("FunctionName"), // Required
		Marker:       aws.String("String"),
		MaxItems:     aws.Int64(1),
	}
	resp, err := svc.ListVersionsByFunction(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:acquia,項目名稱:fifo2kinesis,代碼行數:26,代碼來源:examples_test.go

示例14: ExampleLambda_Invoke

func ExampleLambda_Invoke() {
	sess, err := session.NewSession()
	if err != nil {
		fmt.Println("failed to create session,", err)
		return
	}

	svc := lambda.New(sess)

	params := &lambda.InvokeInput{
		FunctionName:   aws.String("FunctionName"), // Required
		ClientContext:  aws.String("String"),
		InvocationType: aws.String("InvocationType"),
		LogType:        aws.String("LogType"),
		Payload:        []byte("PAYLOAD"),
		Qualifier:      aws.String("Qualifier"),
	}
	resp, err := svc.Invoke(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		fmt.Println(err.Error())
		return
	}

	// Pretty-print the response data.
	fmt.Println(resp)
}
開發者ID:acquia,項目名稱:fifo2kinesis,代碼行數:29,代碼來源:examples_test.go

示例15: ExampleLambda_CreateEventSourceMapping

func ExampleLambda_CreateEventSourceMapping() {
	svc := lambda.New(nil)

	params := &lambda.CreateEventSourceMappingInput{
		EventSourceARN:   aws.String("Arn"),                 // Required
		FunctionName:     aws.String("FunctionName"),        // Required
		StartingPosition: aws.String("EventSourcePosition"), // Required
		BatchSize:        aws.Int64(1),
		Enabled:          aws.Bool(true),
	}
	resp, err := svc.CreateEventSourceMapping(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, the SDK should always return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.Prettify(resp))
}
開發者ID:Talos208,項目名稱:aws-sdk-go,代碼行數:30,代碼來源:examples_test.go


注:本文中的github.com/aws/aws-sdk-go/service/lambda.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。