// Satisfies the Listener interface and calls the Lambda function func (this *Lambda) Exec(evt event.Event) { this.Log.Handler(this, &evt) msg := magicString(this.Config.GetMessage(), evt) reg := magicString(this.Config.GetRegion(), evt) fun := magicString(this.Config.GetFunction(), evt) svc := lambda.New(&aws.Config{Region: reg}) params := &lambda.InvokeInput{ FunctionName: aws.String(fun), // Required Payload: []byte(msg), } resp, err := svc.Invoke(params) if err != nil { if awsErr, ok := err.(awserr.Error); ok { msg := fmt.Sprintf("%s %s", awsErr.Code(), awsErr.Message()) this.Log.HandlerError(this, msg, &evt) if _, ok := err.(awserr.RequestFailure); ok { } } else { this.Log.HandlerError(this, err.Error(), &evt) } return } this.Log.Debug("LAMBDA OUT %s %s \"%s\"", evt.GetId(), this.GetName(), awsutil.StringValue(resp)) }
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.Long(1), Enabled: aws.Boolean(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 alwsy return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleLambda_CreateFunction() { svc := lambda.New(nil) params := &lambda.CreateFunctionInput{ Code: &lambda.FunctionCode{ // Required ZipFile: []byte("PAYLOAD"), }, FunctionName: aws.String("FunctionName"), // Required Handler: aws.String("Handler"), // Required Role: aws.String("RoleArn"), // Required Runtime: aws.String("Runtime"), // Required Description: aws.String("Description"), MemorySize: aws.Long(1), Timeout: aws.Long(1), } resp, err := svc.CreateFunction(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 alwsy return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleLambda_UpdateFunctionCode() { svc := lambda.New(nil) params := &lambda.UpdateFunctionCodeInput{ FunctionName: aws.String("FunctionName"), // Required ZipFile: []byte("PAYLOAD"), // Required } resp, err := svc.UpdateFunctionCode(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 alwsy return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleLambda_ListFunctions() { svc := lambda.New(nil) params := &lambda.ListFunctionsInput{ Marker: aws.String("String"), MaxItems: aws.Long(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 alwsy return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleLambda_AddPermission() { svc := lambda.New(nil) params := &lambda.AddPermissionInput{ Action: aws.String("Action"), // Required FunctionName: aws.String("FunctionName"), // Required Principal: aws.String("Principal"), // Required StatementID: aws.String("StatementId"), // Required SourceARN: aws.String("Arn"), SourceAccount: aws.String("SourceOwner"), } resp, err := svc.AddPermission(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 alwsy return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func TestInterface(t *testing.T) { assert.Implements(t, (*lambdaiface.LambdaAPI)(nil), lambda.New(nil)) }
func init() { Before("@lambda", func() { World["client"] = lambda.New(nil) }) }