Here is something super cool I do with AWS SSM Send-Command!
Using Apache Airflow I create a brand new EC2-Instance using a Cloud Formation Template (or CFT for short) that's just a JSON file with all the configuration values for my EC2-Instance that I want; also note that in this CFT I also have a bootstrap command that copies a Python script from an S3 location to the new EC2-Instance so that I can execute it later on using an SSM Send-Command! I do this using Python3 and the AWS SDK for Python3 called the Boto3 library. Here's part of the command for creating the new CFT Stack that in turn creates my new EC2-Instance:
import boto3
cft = boto3.client("cloudformation", "us-east-1")
response = cft.create_stack(
StackName='foobarStackName',
TemplateBody=json.dumps(json_data))
Then I can get the Instance-ID of the new EC2-Instance (required to use SSM Send-Command) using something like this:
response = cft.describe_stacks(
StackName='foobarStackName',
)
Then I can get the Instance-ID of the current Airflow Worker's server's EC2-Instance by running this command wget -q -O - http://169.254.169.254/latest/meta-data/instance-id
through Python:
output = subprocess.Popen(['wget', '-q', '-O', '-', 'http://169.254.169.254/latest/meta-data/instance-id'],
stdout=subprocess.PIPE)
# Do some weird stuff to get the value (I'm a Java developer so excuse my bad Python skilz)
instanceId = output.communicate()
instanceId = str(instanceId).split("'")[1]
NOW!!!! FOR THE GRAND FINALE
I can then execute a script on the new EC2-Instance I created and send that script whatever parameters/arguments I want... including the Instance-ID of the server that sent the SSM Send-Command so that way when my script is done running on the new EC2-Instance it can send another SSM Send-Command back to my Airflow server to tell it that the script is finished. This is at a very high level without details but it's just to demonstrate an idea :)
subprocess.run(shlex.split('sudo aws ssm send-command --document-name "AWS-RunShellScript" --parameters commands=["sudo python3 /home/ec2-user/ec2_file_sensor.py ' + filepath + ' ' + batchIdValue + ' ' + source + ' ' + fileType + ' ' + airflowWorkerInstanceId + '"] --instance-ids ' + ec2ResourceInstanceId + ' --region us-east-1'))
Not sure if this helped anyone but it's a cool and FUN example of doing something with the AWS SSM Send-Command! Albeit, probably a code smell xD