Use GoFormation structures

Overview

Now I use the Bucket_AnalyticsConfiguration structure directly, without unmarshaling to define the AnalyticsConfigurationProperty :

33   analyticsConfiguration :=  &[]s3.Bucket_AnalyticsConfiguration{
34     {
35       Id:                                   "AnalyticsConfigurationId",
36       Prefix:                               "AnalyticsConfigurationPrefix",
37       StorageClassAnalysis:                 &s3.Bucket_StorageClassAnalysis{
38         DataExport:                           &s3.Bucket_DataExport{
39           Destination:                          &s3.Bucket_Destination{
40             BucketAccountId:                      id,
41             BucketArn:                            *helper.BucketArn(),
42             Format:                               "CSV",
43             Prefix:                               "AnalyticsDestinationPrefix",
44           },
45           OutputSchemaVersion:                  "V_1",
46         },
47       },
48       TagFilters: []s3.Bucket_TagFilter{{
49         Key: "AnalyticsTagKey",
50         Value: "AnalyticsTagValue",
51         },
52       },
53     },
54   }

If you use a structure from the beginning, there are some advantages:

  • You get IDE support for filling the properties
  • You can reference other constructs directly
    44             Bucket: helper.BucketArn(),
  • It is not possible to misspell a object name like in a json file.

Summary

Using a structure, where all properties are defined is my go-to way. Maybe later the CDK GO will add that feature also, but for now you can just use GoFormation

See also

Source

See the full source on github.

Sources