forked from mweagle/Sparta
/
versioning.go
37 lines (33 loc) · 1.02 KB
/
versioning.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
package decorator
import (
"time"
sparta "github.com/mweagle/Sparta"
gocf "github.com/mweagle/go-cloudformation"
"github.com/sirupsen/logrus"
)
// LambdaVersioningDecorator returns a TemplateDecorator
// that is responsible for including a versioning resource
// with the given lambda function
func LambdaVersioningDecorator() sparta.TemplateDecoratorHookFunc {
return func(serviceName string,
lambdaResourceName string,
lambdaResource gocf.LambdaFunction,
resourceMetadata map[string]interface{},
S3Bucket string,
S3Key string,
buildID string,
template *gocf.Template,
context map[string]interface{},
logger *logrus.Logger) error {
lambdaResName := sparta.CloudFormationResourceName("LambdaVersion",
buildID,
time.Now().UTC().String())
versionResource := &gocf.LambdaVersion{
FunctionName: gocf.GetAtt(lambdaResourceName, "Arn").String(),
}
lambdaVersionRes := template.AddResource(lambdaResName, versionResource)
lambdaVersionRes.DeletionPolicy = "Retain"
// That's it...
return nil
}
}