We announced
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
Scenario
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:
Prerequisites
-
You have set up and configured the AWS SDK for Go.
-
You are familiar with CloudWatch alarms. To learn more, see Creating Amazon CloudWatch Alarms in the Amazon CloudWatch User Guide.
Describe Alarms
Choose Copy to save the code locally.
Create the file describe_alarms.go
. Import the packages used in the
example.
import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" "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