-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
58 lines (51 loc) · 1.95 KB
/
main.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
57
58
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws"
)
func main() {
svc := lambda.New(session.New(&aws.Config{
Region: aws.String(getEnv("PLUGIN_REGION", "us-east-1")),
}))
input := &lambda.UpdateFunctionCodeInput{
FunctionName: aws.String(os.Getenv("PLUGIN_FUNCTION_NAME")),
Publish: aws.Bool(true),
S3Bucket: aws.String(os.Getenv("PLUGIN_S3_BUCKET")),
S3Key: aws.String(os.Getenv("PLUGIN_FILE_NAME")),
}
result, err := svc.UpdateFunctionCode(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case lambda.ErrCodeServiceException:
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
case lambda.ErrCodeResourceNotFoundException:
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
case lambda.ErrCodeInvalidParameterValueException:
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
case lambda.ErrCodeTooManyRequestsException:
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
case lambda.ErrCodeCodeStorageExceededException:
fmt.Println(lambda.ErrCodeCodeStorageExceededException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
os.Exit(1)
}
fmt.Println(result)
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}