-
-
Notifications
You must be signed in to change notification settings - Fork 368
/
lambda.go
93 lines (73 loc) · 1.65 KB
/
lambda.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package config
import (
"errors"
)
// defaultPolicy is the default function role policy.
var defaultPolicy = IAMPolicyStatement{
"Effect": "Allow",
"Resource": "*",
"Action": []string{
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ssm:GetParametersByPath",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface",
},
}
// IAMPolicyStatement configuration.
type IAMPolicyStatement map[string]interface{}
// VPC configuration.
type VPC struct {
Subnets []string `json:"subnets"`
SecurityGroups []string `json:"security_groups"`
}
// Lambda configuration.
type Lambda struct {
// Memory of the function.
Memory int `json:"memory"`
// Timeout of the function.
Timeout int `json:"timeout"`
// Role of the function.
Role string `json:"role"`
// Runtime of the function.
Runtime string `json:"runtime"`
// Policy of the function role.
Policy []IAMPolicyStatement `json:"policy"`
// VPC configuration.
VPC *VPC `json:"vpc"`
}
// Default implementation.
func (l *Lambda) Default() error {
if l.Memory == 0 {
l.Memory = 512
}
if l.Runtime == "" {
l.Runtime = "nodejs10.x"
}
l.Policy = append(l.Policy, defaultPolicy)
return nil
}
// Validate implementation.
func (l *Lambda) Validate() error {
if l.Timeout != 0 {
return errors.New(".lambda.timeout is deprecated, use .proxy.timeout")
}
return nil
}
// Override config.
func (l *Lambda) Override(c *Config) {
if l.Memory != 0 {
c.Lambda.Memory = l.Memory
}
if l.Timeout != 0 {
c.Lambda.Timeout = l.Timeout
}
if l.Role != "" {
c.Lambda.Role = l.Role
}
if l.VPC != nil {
c.Lambda.VPC = l.VPC
}
}