Professional Documents
Culture Documents
Install System Manager Agent Using User Data
Install System Manager Agent Using User Data
#!/bin/bash
cd /tmp
sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-
windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
sudo systemctl enable amazon-ssm-agent
sudo systemctl start amazon-ssm-agent
cd /etc/amazon/ssm/
touch amazon.ssm.agent.json
cp amazon-ssm-agent.json.template amazon-ssm-agent.json
sudo systemctl restart amazon-ssm-agent
#!/bin/bash
cd /tmp
wget https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-
cloudwatch-agent.rpm
#!/bin/bash
cd /tmp
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m
ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json –s
cd ..
cat <<EOT >> /opt/aws/amazon-cloudwatch-agent/bin/config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "cwagent"
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"cpu": {
"measurement": [
"cpu_usage_idle",
"cpu_usage_iowait",
"cpu_usage_user",
"cpu_usage_system"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"totalcpu": false
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"diskio": {
"measurement": [
"io_time"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
EOT
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config –m
ec2 -s -c file:etc/opt/aws/amazon-cloudwatch-agent/bin/config.json
If the AWS Systems Manager home page opens, scroll down and choose Explore Run
Command.
3. Choose Run command.
4. In the Command document list, choose AmazonCloudWatch-ManageAgent.
5. In the Targets area, choose the instance where you installed the CloudWatch agent.
6. In the Action list, choose configure.
7. In the Optional Configuration Source list, choose ssm.
8. In the Optional Configuration Location box, enter the name of the agent configuration
file that you created and saved to Systems Manager Parameter Store, as explained in Create the
CloudWatch agent configuration file.
9. In the Optional Restart list, choose yes to start the agent after you have finished these
steps.
10. Choose Run.
11. Optionally, in the Targets and outputs areas, select the button next to an instance name
and choose View output. Systems Manager should show that the agent was successfully started.
References:
Role: https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-service-role.html
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-
EC2-Instance-fleet.html
Configuration: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-
cloudwatch-agent-configuration-file-wizard.html