forked from omerxx/drone-lambda-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.42 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
59
package main
import (
"errors"
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/rs/zerolog/log"
)
func main() {
region := os.Getenv("PLUGIN_REGION")
if region == "" {
log.Fatal().
Err(errors.New("env: aws region is required")).
Send()
}
secret, id := os.Getenv("PLUGIN_AWS_SECRET_ACCESS_KEY"),
os.Getenv("PLUGIN_AWS_ACCESS_KEY_ID")
if secret == "" || id == "" {
log.Fatal().
Err(errors.New("auth: aws Credentials Key or ID is not provieded")).
Send()
}
svc := lambda.New(session.New(&aws.Config{
Region: aws.String(region),
Credentials: credentials.NewStaticCredentials(id, secret, ""),
}))
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 {
log.Info().Msgf("[Deploy Success]: %s", result.GoString())
return
}
e, ok := err.(awserr.Error)
if !ok {
log.Fatal().Err(fmt.Errorf("deploy failed: %q", err))
}
awsErrField := map[string]interface{}{
e.Code(): e.Message(),
"originErr": e.OrigErr(),
}
log.Fatal().Fields(awsErrField).Send()
}