跳至內容

Title: Issue with Custom Script in AWS SSM Run Command for CloudWatch Agent Configuration

0

Hello,

I am trying to run a custom script using AWS Systems Manager (SSM) Run Command to configure the CloudWatch Agent on my Amazon Linux 2 instance. However, I am encountering the following error: 2024/10/23 10:24:16 E! Fail to fetch/remove json config: ParameterNotFound:

failed to run commands: exit status 1 my parameter store name is AmazonCloudwatchagent-Linux Here is the content of my script that I am trying to execute:

{ "metrics": { "metrics_collected": { "disk": { "measurement": [ "disk_free", "disk_total", "disk_used" ], "metrics_collection_interval": 10 }, "mem": { "measurement": [ "mem_used", "mem_free", "mem_total" ], "metrics_collection_interval": 10 } } } } I suspect that the error might be related to how the CloudWatch Agent is configured or perhaps the parameter store. Could someone please help me understand what might be causing this error and how I can resolve it?

Thank you!

已提問 1 年前檢視次數 1270 次
1 個回答
2

The error you're encountering suggests that there's an issue with the parameter store configuration for your CloudWatch agent. The message "ParameterNotFound" indicates that the agent is unable to find the configuration file in the Systems Manager Parameter Store.

To resolve this issue, you need to ensure that your configuration file is properly stored in the Parameter Store. Here are the steps you should follow:

  1. First, make sure that your configuration JSON is valid. The JSON you provided looks correct, but it's only a partial configuration focusing on metrics collection for disk and memory.

  2. You need to save this configuration to the Parameter Store. Use the AWS Systems Manager put-parameter command to do this. The command should look something like this:

    aws ssm put-parameter --name "AmazonCloudwatchagent-Linux" --type "String" --value file://your-config-file.json

    Replace "your-config-file.json" with the path to your configuration file.

  3. Ensure that the IAM role attached to your EC2 instance has the necessary permissions to access the Parameter Store and CloudWatch. The role should have the CloudWatchAgentServerPolicy attached.

  4. After storing the configuration, you can use the Systems Manager Run Command to configure and start the CloudWatch agent. Use the AmazonCloudWatch-ManageAgent document for this purpose.

  5. When running the command, make sure to specify the correct parameter name in the "Optional Configuration Source" field. In your case, it should be "AmazonCloudwatchagent-Linux".

If you've followed these steps and are still encountering issues, you may want to check the CloudWatch agent logs for more detailed error messages. On Amazon Linux 2, these logs are typically located at /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log.

Remember, the CloudWatch agent configuration file is quite extensive and can include more sections than just metrics. Depending on your monitoring needs, you might want to include sections for logs collection, agent settings, and other advanced configurations.
Sources
Manually create or edit the CloudWatch agent configuration file - Amazon CloudWatch
Troubleshooting the CloudWatch agent - Amazon CloudWatch
Troubleshoot permission errors for an instance on CloudWatch | AWS re:Post

已回答 1 年前
專家
已審閱 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。