Use AWS lambda to run any command in EC2 with SSM agent installed
- Runs any command for a given set of instances having SSM installed.
- Runs any command to all the instances having SSM agent installed.
- Can be invoked from multiple cloudwatch rules.
- sends a notification email whenever the service is inactive or failed using sns.
Not found
These are the input JSON can be sent from cloudwatch in certain intervals/onetime.
for running different commands to different instances at once
{
"inputs": [
{
"InstanceIds": [
"i-0b03ded3f5e064fbb",
"i-0513c5e33ac0abf90"
],
"Commands": [
"#!/bin/bash",
"echo $PATH",
"exit 1"
]
},
{
"InstanceIds": [
"i-0b03ded3f5e064fbb",
"i-0513c5e33ac0abf90"
],
"Commands": [
"echo \"Rajdeep\""
]
}
]
}
for running multiple commands to instances at once
{
"inputs": [
{
"InstanceIds": [
"i-0adebd38dd364aba8"
],
"Commands": [
"#!/bin/bash",
"sudo systemctl is-active persistwebapp.service; if [[ $? -eq 0 ]]; then echo \"Service is running\"; else sudo systemctl start persistwebapp.service; echo \"Service Started\"; fi"
]
}
]
}
for running multiple commands to all SSM enabled instances at once
{
"inputs": [
{
"InstanceIds": [ ],
"Commands": [
"#!/bin/bash",
"status=$(pgrep exim 2>&1); if [[ -n \"$status\" ]]; then echo \"exim exists :: Trying to remove\"; sudo rpm -e --nodeps \"exim\"; else echo \"exim does not exists\"; fi"
]
}
]
}
Rajdeep Das