AWS SDK for Go
Developer Guide

Configuring a Lambda Function to Receive Notifications

The following example configures the Lambda function functionName to accept notifications from the resource with the ARN sourceArn.

The first step is to create the session and Lambda client.

sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) svc := lambda.New(sess, &aws.Config{Region: aws.String("us-west-2")})

Next, we create the structure for the input argument to the AddPermission function.

permArgs := &lambda.AddPermissionInput{ Action: aws.String("lambda:InvokeFunction"), FunctionName: functionName, Principal: aws.String(""), SourceArn: sourceArn, StatementId: aws.String("lambda_s3_notification"), }

Finally, we call AddPermission and display a message with the result of the call.

result, err := svc.AddPermission(permArgs) if err != nil { fmt.Println("Cannot configure function for notifications") os.Exit(0) } else { fmt.Println(result) }

See the complete example on GitHub.