本文整理匯總了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
}
示例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)
}
示例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))
}
示例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
}
示例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)
}
示例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))
}
示例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)
}
示例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
}
示例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))
}
示例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)
}
示例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))
}
示例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)
}
示例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)
}
示例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)
}
示例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))
}