import boto3
import botocore
import time
def lambda_handler(event, context):
param = event['queryStringParameters']
id = param['instanceid']
print(id)
client = boto3.client('ssm')
instance_id = id # hard-code for example
response = client.send_command(
InstanceIds=[instance_id],
DocumentName='AWS-RunShellScript',
Parameters={
'commands': [
'cd /home/ssm-user/',
'./flights.sh'
]
})
time.sleep(2)
command_id = response.get("Command").get("CommandId")
command_invocation_result=client.get_command_invocation(CommandId=command_id, InstanceId=id)
return {
'statusCode': 200,
'body': command_invocation_result
}
https://docs.aws.amazon.com/ko_kr/systems-manager/latest/userguide/run-command-setting-up.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html