AWS SDK for Go
Developer Guide

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

Import the packages we use in the example.

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

Initialize a session that the SDK will use to load credentials from the shared credentials file, ~/.aws/credentials, and create a new Amazon EC2 service client.

sess, err := session.NewSession() if err != nil { fmt.Println("failed to create session,", err) os.Exit(1) } svc := cloudwatch.New(sess, &aws.Config{Region: aws.String("us-west-2")})

Call the DescribeAlarms method, and print the results.

resp, err := svc.DescribeAlarms(nil) if err != nil { fmt.Println(err.Error()) os.Exit(1) } fmt.Println(resp)

See the complete example on GitHub.