v5.0.0
5.0.0 (2021-06-20)
Features
BREAKING CHANGES
- schema: Improved implementation of Globals (in SAM tempates)
This PR introduces a new implementation for both defining SAM templates with Global
values, as well as parsing templates containing them.
Note: Globals only apply to SAM templates - if you are using regular CloudFormation templates this breaking change should not impact you. The only impact you might see is if you are creating cloudFormation.Template
structs manually rather than using the cloudformation.NewTemplate()
constructor. As part of this change, a new field (Globals
) was added to the Template{}
struct. If you are not using the constructor, your compiler will probably complain that this field is missing from the struct instantiation in your code.
For more information about what Globals
are in SAM templates, see this link:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html
In previous versions of Goformation (before v5), goformation was able to parse SAM templates that contained a Globals
section, however the implementation just overwrote the resource properties in the template, with the global values at parse time.
This meant that:
- It was not possible to compose a template in Go that had a Globals section.
- The JSON Schema generated by this repo, had no concept of Globals.
This new implementation DOES NOT does not overwrite the values in the template, like the previous implementation did. It replaces the old implementation completely, and exposes Globals as a series of structs that are marshalled/unmarshalled to/from JSON/YAML.
This allows you to compose a template:
template := cloudformation.NewTemplate()
template.Globals["Function"] = &global.Function{
Timeout: 1800,
}
As well as parse a JSON/YAML template, and inspect the global properties:
template, err := goformation.Open("../some-template-with-globals.yml")
if err != nil {
fmt.Printf("failed to open template: %s\n", err)
os.Exit(1)
}
fmt.Printf("%v", template.Globals["Function"])
// You can view the global as above, however it's type is downcast to a basic interface.
// If you want to inspect properties specific to the global type (e.g. the timeout for a Lambda function)
// then use the following helper methods to get the various global types from the template:
globalAPI, _:= template.GetServerlessGlobalApi()
globalFunction, _ := template.GetServerlessGlobalFunction()
globalHttpApi, _ := template.GetServerlessGlobalHttpApi()
globalSimpleTable, _ := template.GetServerlessGlobalSimpleTable()
fmt.Printf("Global Function Timeout: %d\n", globalFunction.Timeout)