Implementing custom telemetry using AWS CloudWatch SDK.

Implementing custom telemetry using AWS CloudWatch SDK.

Table of contents

No heading

No headings in the article.

Hello Friends, Today we will be creating custom telemetry using AWS Cloudwatch SDK. This will use Cloudwatch to store the data. To understand more about Cloudwatch metrics please visit this LINK.


AWS Account.

GO setup on the machine.

VS code.

Now that we know what we are doing let's start the implementation.

  • Create a golang project in vs code. add the below code to main.go and import all the necessary libraries. Please create an IAM role to add SECRET_KEY, ACCESS_KEY. Also, add the region to the placeholder.

  • the below code will create a namespace in AWS Cloudwatch with the name MyAppTelemetry and add a custom metric with the name CustomMetric. this metric will spit out random values when you run the application.

package main

import (



func main() {
    // Initialize a session that the SDK uses to load

    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
        Config: aws.Config{
            // ...
            Region: aws.String("<MY_REGION>"),
            Credentials: credentials.NewStaticCredentials(

    // Create new cloudwatch client.
    svc := cloudwatch.New(sess)

    _, err := svc.PutMetricData(&cloudwatch.PutMetricDataInput{
        Namespace: aws.String("MyAppTelemetry"),
        MetricData: []*cloudwatch.MetricDatum{
                MetricName: aws.String("CustomMetric"),
                Unit:       aws.String("Count"),
                Value:      aws.Float64(rand.Float64() * 10),
                Dimensions: []*cloudwatch.Dimension{
                        Name:  aws.String("mymobileapp"),
                        Value: aws.String(""),
    if err != nil {
        fmt.Println("Error adding metrics:", err.Error())

    // Get information about metrics
    result, err := svc.ListMetrics(&cloudwatch.ListMetricsInput{
        Namespace: aws.String("MyAppTelemetry"),
    if err != nil {
        fmt.Println("Error getting metrics:", err.Error())

    for _, metric := range result.Metrics {

        for _, dim := range metric.Dimensions {
            fmt.Println(*dim.Name+":", *dim.Value)
  • Once all the changes are made please run the application with the below command.
go run main.go

Screenshot 2022-06-23 at 11.41.45 PM.png

  • if you got no error that means the application execution was successful and data values are being sent to Cloudwatch.

  • You can visit the Cloudwatch metric section of AWS to visualize the telemetry.

Screenshot 2022-06-23 at 11.44.00 PM.png

Thanks for reading. I hope this story was helpful. If you are interested, check out my other articles.

you can also visit

Did you find this article valuable?

Support Shubham Deshmukh by becoming a sponsor. Any amount is appreciated!