AWS ssm.send_command result

문학적인유사성·2023년 2월 1일
0

AWS

목록 보기
40/63

https://stackoverflow.com/questions/67440685/is-there-a-way-to-check-that-ssm-send-command-is-running-properly

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

profile
Are you nervous? Don't be

0개의 댓글