forked from awsdocs/aws-doc-sdk-examples
/
ShowFunctions.go
56 lines (48 loc) · 1.76 KB
/
ShowFunctions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// snippet-start:[lambda.go.show_functions]
package main
// snippet-start:[lambda.go.show_functions.imports]
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/lambda/lambdaiface"
)
// snippet-end:[lambda.go.show_functions.imports]
// GetFunctions retrieves a list of AWS Lambda functions
// Inputs:
// svc is a Lambda service client
// Output:
// If success, the list of functions and nil
// Otherwise, nil and an error from the call to ListFunctions
func GetFunctions(svc lambdaiface.LambdaAPI) (*lambda.ListFunctionsOutput, error) {
// snippet-start:[lambda.go.show_functions.call]
result, err := svc.ListFunctions(nil)
// snippet-end:[lambda.go.show_functions.call]
return result, err
}
func main() {
// snippet-start:[lambda.go.show_functions.session]
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := lambda.New(sess)
// snippet-end:[lambda.go.show_functions.session]
result, err := GetFunctions(svc)
if err != nil {
fmt.Println("Got an error listing functions:")
fmt.Println(err)
return
}
// snippet-start:[lambda.go.show_functions.display]
fmt.Println("Functions:")
for _, f := range result.Functions {
fmt.Println("Name: " + aws.StringValue(f.FunctionName))
fmt.Println("Description: " + aws.StringValue(f.Description))
fmt.Println("")
}
// snippet-end:[lambda.go.show_functions.display]
}
// snippet-end:[lambda.go.show_functions]