How to use describe_instance_patches method in localstack

Best Python code snippet using localstack_python

ssmutil.py

Source:ssmutil.py Github

copy

Full Screen

...33 @AWSRetry.backoff()34 def get_command_invocation(self, command_id, instance_id):35 return self.ssm_client.list_command_invocations(CommandId=command_id, Details=True)36 @AWSRetry.backoff()37 def describe_instance_patches(self, instance_id, filter_key, filter_value):38 filters = [{'Key': filter_key, 'Values': filter_value}]39 return self.ssm_client.describe_instance_patches(InstanceId=instance_id, Filters=filters)40 @AWSRetry.backoff()41 def send_command_for_install(self, patch_baseline_document, patch_baseline_document_version, patch_baseline_mode, patch_baseline_reboot, instance_id, comments,42 pb_override_patch_data_file_url, patch_baseline_timeout, ssm_command_output_bucket, ssm_command_output_s3_key_prefix):43 parameters = {'Operation': [patch_baseline_mode], 'RebootOption': [patch_baseline_reboot], 'InstallOverrideList': [pb_override_patch_data_file_url]}44 return self.ssm_client.send_command(InstanceIds=[instance_id], DocumentName=patch_baseline_document, DocumentVersion=patch_baseline_document_version,45 TimeoutSeconds=patch_baseline_timeout, Comment=comments, Parameters=parameters, OutputS3BucketName=ssm_command_output_bucket,46 OutputS3KeyPrefix=ssm_command_output_s3_key_prefix)47 @AWSRetry.backoff()48 def describe_instance_patch_states(self, instance_id):49 return self.ssm_client.describe_instance_patch_states(InstanceIds=[instance_id])50 @AWSRetry.backoff()51 def describe_instance_information(self, instance_id):52 filters = [{'Key': "InstanceIds", 'Values': [instance_id]}]53 return self.ssm_client.describe_instance_information(Filters=filters)

Full Screen

Full Screen

ec2_patching_with_ssm.py

Source:ec2_patching_with_ssm.py Github

copy

Full Screen

...29 NextToken='string',30 MaxResults=5031)32#Get Patch details33response = client.describe_instance_patches(34 InstanceId='i-08d4c52a7c56db0bc',35 MaxResults=5036)37results = response["Patches"]38while "NextToken" in response:39 response = client.describe_instance_patches(InstanceId='i-08d4c52a7c56db0bc',MaxResults=50,NextToken=response['NextToken'])40 results.extend(response["Patches"])41print("Package status before patching\n"+str(results))42#Create AMI before patching43execution_response=client.start_automation_execution(44DocumentName='ami',45DocumentVersion='$LATEST',46Parameters={47 "InstanceId": [48 "i-08d4c52a7c56db0bc"49 ],50 "NoReboot": [51 "true"52 ],53 "AMINameValue": [54 "Ubuntu"55 ],56 "DeleteOnValue": [57 "19-10-2021"58 ]59 })60# Get AMI creation status61response = client.describe_automation_executions(62 Filters=[63 {64 'Key': 'ExecutionId',65 'Values': [execution_response['AutomationExecutionId']]66 },67 ],68 MaxResults=50,69)70while response['AutomationExecutionMetadataList'][0]['AutomationExecutionStatus'] in ["Pending","InProgress"]:71 print("Image creation in progress")72 time.sleep(10)73 response = client.describe_automation_executions(Filters=[{'Key': 'ExecutionId','Values': [execution_response['AutomationExecutionId']]},],MaxResults=50)74if response['AutomationExecutionMetadataList'][0]['AutomationExecutionStatus'] != "Success": 75 print("Image creation failed")76else:77 print("Image creation completed")78#Patch instance79print("Patching started")80response=client.send_command(81 InstanceIds=['i-08d4c52a7c56db0bc'],82 DocumentName='AWS-RunPatchBaseline',83 DocumentVersion='$LATEST',84 TimeoutSeconds=900,85 Parameters={86 'Operation': [87 'Install'88 ],89 'RebootOption': [90 'RebootIfNeeded'91 ]92 }93 )94time.sleep(10)95waiter = client.get_waiter('command_executed')96waiter.wait(CommandId=response['Command']['CommandId'],InstanceId='i-08d4c52a7c56db0bc',WaiterConfig={'Delay': 30,'MaxAttempts': 50})97# Post Patching State98response = client.describe_instance_patch_states(99 InstanceIds=[100 'i-08d4c52a7c56db0bc',101 ],102 NextToken='string',103 MaxResults=50104 )105#Post Patching details106response = client.describe_instance_patches(107 InstanceId='i-08d4c52a7c56db0bc',108 MaxResults=50109 )110results = response["Patches"]111while "NextToken" in response:112 response = client.describe_instance_patches(InstanceId='i-08d4c52a7c56db0bc',MaxResults=50,NextToken=response['NextToken'])113 results.extend(response["Patches"])...

Full Screen

Full Screen

get_patch_status.py

Source:get_patch_status.py Github

copy

Full Screen

...6 command=event['Input']['Payload']['command']7 response = client.describe_instance_patch_states(InstanceIds=instance_list)8 #Get Patch details9 for instance_id in instance_list:10 response = client.describe_instance_patches(InstanceId=instance_id,MaxResults=50,Filters=[11 {12 'Key': 'State',13 'Values': [14 'Missing'15 ]16 },17 ])18 results = response["Patches"]19 while "NextToken" in response:20 response = client.describe_instance_patches(InstanceId=instance_id,MaxResults=50,NextToken=response['NextToken'],Filters=[21 {22 'Key': 'State',23 'Values': [24 'Missing'25 ]26 },27 ])28 results.extend(response["Patches"])29 print("Package status on "+ instance_id+" before patching\n"+str(results))30 31 return{32 'instance_list': instance_list,33 'target_filter': target_filter,34 'command': command...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful