v4 – github.com/awslabs/goformation/v4 Index | Examples | Files | Directories

package goformation

import "github.com/awslabs/goformation/v4"

Example (To_go)

Code:

{

	// Open a template from file (can be JSON or YAML)
	template, err := goformation.Open("example/yaml-to-go/template.yaml")
	if err != nil {
		fmt.Printf("There was an error processing the template: %s", err)
		return
	}

	// You can extract all resources of a certain type
	// Each AWS CloudFormation resource is a strongly typed struct
	topics := template.GetAllSNSTopicResources()
	for name, topic := range topics {

		// E.g. Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName 'example'
		fmt.Printf("Found a %s with Logical ID %s and TopicName %s\n", topic.AWSCloudFormationType(), name, topic.TopicName)

	}

	// You can also search for specific resources by their logicalId
	search := "ExampleTopic"
	topic, err := template.GetSNSTopicWithName(search)
	if err != nil {
		fmt.Printf("SNS topic with logical ID %s not found", search)
		return
	}

	// E.g. Found a AWS::Serverless::Function named GetHelloWorld (runtime: nodejs6.10)
	fmt.Printf("Found a %s with Logical ID %s and TopicName %s\n", topic.AWSCloudFormationType(), search, topic.TopicName)

	// Output:
	// Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName example
	// Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName example

}

Output:

Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName example
Found a AWS::SNS::Topic with Logical ID ExampleTopic and TopicName example
Example (To_json)

Code:

{

	// Create a new CloudFormation template
	template := cloudformation.NewTemplate()

	// Create an Amazon SNS topic, with a unique name based off the current timestamp
	template.Resources["MyTopic"] = &sns.Topic{
		TopicName: "my-topic-1575143839",
	}

	// Create a subscription, connected to our topic, that forwards notifications to an email address
	template.Resources["MyTopicSubscription"] = &sns.Subscription{
		TopicArn: cloudformation.Ref("MyTopic"),
		Protocol: "email",
		Endpoint: "some.email@example.com",
	}

	// Let's see the JSON AWS CloudFormation template
	j, err := template.JSON()
	if err != nil {
		fmt.Printf("Failed to generate JSON: %s\n", err)
	} else {
		fmt.Printf("%s\n", string(j))
	}

	// Output:
	// {
	//   "AWSTemplateFormatVersion": "2010-09-09",
	//   "Resources": {
	//     "MyTopic": {
	//       "Properties": {
	//         "TopicName": "my-topic-1575143839"
	//       },
	//       "Type": "AWS::SNS::Topic"
	//     },
	//     "MyTopicSubscription": {
	//       "Properties": {
	//         "Endpoint": "some.email@example.com",
	//         "Protocol": "email",
	//         "TopicArn": {
	//           "Ref": "MyTopic"
	//         }
	//       },
	//       "Type": "AWS::SNS::Subscription"
	//     }
	//   }
	// }
}

Output:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "MyTopic": {
      "Properties": {
        "TopicName": "my-topic-1575143839"
      },
      "Type": "AWS::SNS::Topic"
    },
    "MyTopicSubscription": {
      "Properties": {
        "Endpoint": "some.email@example.com",
        "Protocol": "email",
        "TopicArn": {
          "Ref": "MyTopic"
        }
      },
      "Type": "AWS::SNS::Subscription"
    }
  }
}
Example (To_yaml)

Code:

{

	// Create a new CloudFormation template
	template := cloudformation.NewTemplate()

	// Create an Amazon SNS topic, with a unique name based off the current timestamp
	template.Resources["MyTopic"] = &sns.Topic{
		TopicName: "my-topic-1575143970",
	}

	// Create a subscription, connected to our topic, that forwards notifications to an email address
	template.Resources["MyTopicSubscription"] = &sns.Subscription{
		TopicArn: cloudformation.Ref("MyTopic"),
		Protocol: "email",
		Endpoint: "some.email@example.com",
	}

	// Let's see the YAML AWS CloudFormation template
	y, err := template.YAML()
	if err != nil {
		fmt.Printf("Failed to generate YAML: %s\n", err)
	} else {
		fmt.Printf("%s\n", string(y))
	}

	// Output:
	// AWSTemplateFormatVersion: 2010-09-09
	// Resources:
	//   MyTopic:
	//     Properties:
	//       TopicName: my-topic-1575143970
	//     Type: AWS::SNS::Topic
	//   MyTopicSubscription:
	//     Properties:
	//       Endpoint: some.email@example.com
	//       Protocol: email
	//       TopicArn:
	//         Ref: MyTopic
	//     Type: AWS::SNS::Subscription

}

Output:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyTopic:
    Properties:
      TopicName: my-topic-1575143970
    Type: AWS::SNS::Topic
  MyTopicSubscription:
    Properties:
      Endpoint: some.email@example.com
      Protocol: email
      TopicArn:
        Ref: MyTopic
    Type: AWS::SNS::Subscription

Index

Examples

Functions

func Open

func Open(filename string) (*cloudformation.Template, error)

Open and parse a AWS CloudFormation template from file. Works with either JSON or YAML formatted templates.

func OpenWithOptions

func OpenWithOptions(filename string, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)

OpenWithOptions opens and parse a AWS CloudFormation template from file. Works with either JSON or YAML formatted templates. Parsing can be tweaked via the specified options.

func ParseJSON

func ParseJSON(data []byte) (*cloudformation.Template, error)

ParseJSON an AWS CloudFormation template (expects a []byte of valid JSON)

func ParseJSONWithOptions

func ParseJSONWithOptions(data []byte, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)

ParseJSONWithOptions an AWS CloudFormation template (expects a []byte of valid JSON) Parsing can be tweaked via the specified options.

func ParseYAML

func ParseYAML(data []byte) (*cloudformation.Template, error)

ParseYAML an AWS CloudFormation template (expects a []byte of valid YAML)

func ParseYAMLWithOptions

func ParseYAMLWithOptions(data []byte, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error)

ParseYAMLWithOptions an AWS CloudFormation template (expects a []byte of valid YAML) Parsing can be tweaked via the specified options.

Source Files

goformation.go test.go

Directories

PathSynopsis
cloudformation
cloudformation/accessanalyzer
cloudformation/acmpca
cloudformation/amazonmq
cloudformation/amplify
cloudformation/apigateway
cloudformation/apigatewayv2
cloudformation/appconfig
cloudformation/appflow
cloudformation/appintegrations
cloudformation/applicationautoscaling
cloudformation/applicationinsights
cloudformation/appmesh
cloudformation/apprunner
cloudformation/appstream
cloudformation/appsync
cloudformation/ask
cloudformation/athena
cloudformation/auditmanager
cloudformation/autoscaling
cloudformation/autoscalingplans
cloudformation/backup
cloudformation/batch
cloudformation/budgets
cloudformation/cassandra
cloudformation/ce
cloudformation/certificatemanager
cloudformation/chatbot
cloudformation/cloud9
cloudformation/cloudformation
cloudformation/cloudfront
cloudformation/cloudtrail
cloudformation/cloudwatch
cloudformation/codeartifact
cloudformation/codebuild
cloudformation/codecommit
cloudformation/codedeploy
cloudformation/codeguruprofiler
cloudformation/codegurureviewer
cloudformation/codepipeline
cloudformation/codestar
cloudformation/codestarconnections
cloudformation/codestarnotifications
cloudformation/cognito
cloudformation/config
cloudformation/cur
cloudformation/customerprofiles
cloudformation/databrew
cloudformation/datapipeline
cloudformation/datasync
cloudformation/dax
cloudformation/detective
cloudformation/devopsguru
cloudformation/directoryservice
cloudformation/dlm
cloudformation/dms
cloudformation/docdb
cloudformation/dynamodb
cloudformation/ec2
cloudformation/ecr
cloudformation/ecs
cloudformation/efs
cloudformation/eks
cloudformation/elasticache
cloudformation/elasticbeanstalk
cloudformation/elasticloadbalancing
cloudformation/elasticloadbalancingv2
cloudformation/elasticsearch
cloudformation/emr
cloudformation/emrcontainers
cloudformation/events
cloudformation/eventschemas
cloudformation/finspace
cloudformation/fis
cloudformation/fms
cloudformation/frauddetector
cloudformation/fsx
cloudformation/gamelift
cloudformation/globalaccelerator
cloudformation/glue
cloudformation/greengrass
cloudformation/greengrassv2
cloudformation/groundstation
cloudformation/guardduty
cloudformation/iam
cloudformation/imagebuilder
cloudformation/inspector
cloudformation/iot
cloudformation/iot1click
cloudformation/iotanalytics
cloudformation/iotcoredeviceadvisor
cloudformation/iotevents
cloudformation/iotfleethub
cloudformation/iotsitewise
cloudformation/iotthingsgraph
cloudformation/iotwireless
cloudformation/ivs
cloudformation/kendra
cloudformation/kinesis
cloudformation/kinesisanalytics
cloudformation/kinesisanalyticsv2
cloudformation/kinesisfirehose
cloudformation/kms
cloudformation/lakeformation
cloudformation/lambda
cloudformation/licensemanager
cloudformation/location
cloudformation/logs
cloudformation/lookoutmetrics
cloudformation/lookoutvision
cloudformation/macie
cloudformation/managedblockchain
cloudformation/mediaconnect
cloudformation/mediaconvert
cloudformation/medialive
cloudformation/mediapackage
cloudformation/mediastore
cloudformation/msk
cloudformation/mwaa
cloudformation/neptune
cloudformation/networkfirewall
cloudformation/networkmanager
cloudformation/nimblestudio
cloudformation/opsworks
cloudformation/opsworkscm
cloudformation/pinpoint
cloudformation/pinpointemail
cloudformation/policies
cloudformation/qldb
cloudformation/quicksight
cloudformation/ram
cloudformation/rds
cloudformation/redshift
cloudformation/resourcegroups
cloudformation/robomaker
cloudformation/route53
cloudformation/route53resolver
cloudformation/s3
cloudformation/s3objectlambda
cloudformation/s3outposts
cloudformation/sagemaker
cloudformation/sdb
cloudformation/secretsmanager
cloudformation/securityhub
cloudformation/serverless
cloudformation/servicecatalog
cloudformation/servicecatalogappregistry
cloudformation/servicediscovery
cloudformation/ses
cloudformation/signer
cloudformation/sns
cloudformation/sqs
cloudformation/ssm
cloudformation/ssmcontacts
cloudformation/ssmincidents
cloudformation/sso
cloudformation/stepfunctions
cloudformation/synthetics
cloudformation/tags
cloudformation/timestream
cloudformation/transfer
cloudformation/utils
cloudformation/waf
cloudformation/wafregional
cloudformation/wafv2
cloudformation/workspaces
cloudformation/xray
example
example/go-to-yaml
example/yaml-to-go
generate
intrinsics
schema
Version
v4.19.5 (latest)
Published
Jun 10, 2021
Platform
linux/amd64
Imports
5 packages
Last checked
2 months ago

Tools for package owners.