AWS SDK for Go
Developer Guide

Set up SDK Metrics in the AWS SDK for Go

The following steps demonstrate how to set up SDK Metrics for the AWS SDK for Go. These steps pertain to an Amazon EC2 instance running Amazon Linux for a client application that is using the AWS SDK for Go. SDK Metrics is also available for your production environments if you enable it while configuring the AWS SDK for Go.

To use SDK Metrics, run the latest version of the CloudWatch agent.

For details about IAM Permissions for SDK Metrics, see Authorize SDK Metrics to Collect and Send Metrics in the AWS SDK for Go.

To set up SDK Metrics with the AWS SDK for Go:

  1. Create an application with an AWS SDK for Go client to use an AWS service.

  2. Host your project on an Amazon EC2 instance or in your local environment.

  3. Install and use the latest version of the AWS SDK for Go.

  4. Install and configure a CloudWatch agent on an Amazon EC2 instance or in your local environment.

  5. Authorize SDK Metrics to collect and send metrics.

  6. Enable SDK Metrics for the AWS SDK for Go.

For more information, see:

Enable SDK Metrics for the AWS SDK for Go

By default, SDK Metrics is turned off, and the port is set to 31000. The following are the default parameters.

//default values [ 'enabled' => false, 'port' => 31000, ]

Enabling SDK Metrics is independent of configuring your credentials to use an AWS service.

You can enable SDK Metrics by setting environment variables or by using the AWS Shared config file.

Option 1: Set Environment Variables

The SDK first checks the profile specified in the environment variable under AWS_PROFILE to determine if SDK Metrics is enabled.

To turn on SDK Metrics, add the following to your environmental variables.

export AWS_CSM_ENABLED=true

Other configuration settings are available, see update_cw_agent for details. For more information about using shared files, see the environment variables information in Configuring the AWS SDK for Go.

Note

Enabling SDK Metrics does not configure your credentials to use an AWS service. To do that, see Specifying Credentials.

Option 2: AWS Shared Config File

If no SDK Metrics configuration is found in the environment variables, the AWS SDK for Go looks for your customized AWS profile field. Then it checks the aws_csm profile. To enable SDK Metrics, add csm_enabled to the shared config file ~/.aws/config.

[default] csm_enabled = true [profile aws_csm] csm_enabled = true

Other configuration settings are available, see update_cw_agent for details. For more information about using shared files, see the environment variables information in Configuring the AWS SDK for Go.

Note

Enabling SDK Metrics does not configure your credentials to use an AWS service. To do that, see Specifying Credentials.

Update a CloudWatch Agent

To make changes to the port ID, set the values and then restart any AWS jobs that are currently active.

Option 1: Set Environment Variables

Most AWS services use the default port. But if the service you want SDK Metrics to monitor uses a unique port, add AWS_CSM_PORT=[PORT-NUMBER], where PORT-NUMBER is the port number, to the host's environment variables.

export AWS_CSM_ENABLED=true export AWS_CSM_PORT=1234

Option 2: AWS Shared Config File

Most services use the default port. If your service requires a unique port ID, add AWS_CSM_PORT=[PORT-NUMBER], where PORT-NUMBER is the port number, to ~/.aws/config.

[default] csm_enabled = false csm_port = 1234 [profile aws_csm] csm_enabled = false csm_port = 1234

Restart SDK Metrics

To restart a job, run the following commands.

amazon-cloudwatch-agent-ctl -a stop; amazon-cloudwatch-agent-ctl -a start;

Disable SDK Metrics

To turn off SDK Metrics, set csm_enabled to false in your environment variables or in your AWS Shared config file ~/.aws/config. Then restart your CloudWatch agent so that the changes can take effect.

Set csm_enabled to false

Option 1: Environment Variables

export AWS_CSM_ENABLED=false

Option 2: AWS Shared Config File

Note

Environment variables override the AWS Shared config file. If SDK Metrics is enabled in the environment variables, the SDK Metrics remains enabled.

[default] csm_enabled = false [profile aws_csm] csm_enabled = false

Stop SDK Metrics and Restart CloudWatch Agent

To disable SDK Metrics, use the following command.

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop && echo "Done"

If you are using other CloudWatch features, restart CloudWatch with the following command.

amazon-cloudwatch-agent-ctl -a start;