aws-go-sdk-lambda-example-configure-function-for-notification.go - AWS Code Sample


Configures a Lambda function to accept notifications from a resource.

/* Copyright 2010-2020, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "flag" "fmt" "os" "" "" "" ) func main() { functionPtr := flag.String("f", "", "The name of the Lambda function") sourcePtr := flag.String("a", "", "The ARN of the entity invoking the function") flag.Parse() if *functionPtr == "" || *sourcePtr == "" { fmt.Println("You must supply the name of the function and of the entity invoking the function") flag.PrintDefaults() os.Exit(1) } // Initialize a session sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) svc := lambda.New(sess) permArgs := &lambda.AddPermissionInput{ Action: aws.String("lambda:InvokeFunction"), FunctionName: functionPtr, Principal: aws.String(""), SourceArn: sourcePtr, StatementId: aws.String("lambda_s3_notification"), } result, err := svc.AddPermission(permArgs) if err != nil { fmt.Println("Cannot configure function for notifications") os.Exit(0) } fmt.Println(result) }

Sample Details

Service: lambda

Last tested: 2020-1-6

Author: Doug-AWS

Type: full-example