Describing CloudWatch Alarms - AWS SDK for Go (version 1)

Describing CloudWatch Alarms

This example shows you how to retrieve basic information that describes your CloudWatch alarms.

You can download complete versions of these example files from the aws-doc-sdk-examples repository on GitHub.


An alarm watches a single metric over a time period you specify. The alarm performs one or more actions based on the value of the metric relative to a given threshold over a number of time periods.

In this example, Go code is used to describe alarms in CloudWatch. The code uses the AWS SDK for Go to describe alarms by using this method of the AWS.CloudWatch client class:


Describe Alarms

Choose Copy to save the code locally.

Create the file describe_alarms.go. Import the packages used in the example.

import ( "" "" "fmt" "os" )

Initialize a session that the SDK will use to load credentials from the shared credentials file ~/.aws/credentials, load your configuration from the shared configuration file ~/.aws/config, and create a CloudWatch client.

sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) svc := cloudwatch.New(sess)

Call DescribeAlarms, and print the results.

resp, err := svc.DescribeAlarms(nil) for _, alarm := range resp.MetricAlarms { fmt.Println(*alarm.AlarmName) }

See the complete example on GitHub.