Best Python code snippet using localstack_python
lambda_function.py
Source:lambda_function.py
...35 process_event(instance_id, state, playbook)36def process_event(instance_id, state, playbook):37 ssm_client = boto3.client('ssm')38 instance_association_name = 'ansible-association-{}'.format(instance_id)39 status_infos = ssm_client.describe_instance_associations_status(40 InstanceId=instance_id41 )42 association = status_infos['InstanceAssociationStatusInfos']43 association_exists = False44 if association is not None:45 for i in range(len(association)):46 if instance_association_name == association[i]['AssociationName']:47 association_exists = True48 if association_exists is False and running == state:49 print('Creating SSM State Manager Association: {}'.format(instance_id))50 create_association(ssm_client, playbook, instance_id, instance_association_name)51 else:52 association_id = get_association_id(ssm_client, instance_id, instance_association_name)53 if association_id is not None:54 if running == state:55 print('Updating SSM State Manager Association: {}'.format(association_id))56 update_association(ssm_client, association_id, instance_association_name, playbook)57 elif terminated == state:58 print('Deleting SSM State Manager Association: {}'.format(association_id))59 delete_association(ssm_client, association_id)60 else:61 print('Association does not exist: {}'.format(instance_association_name))62def get_association_id(ssm_client, instance_id, instance_association_name):63 response = ssm_client.describe_instance_associations_status(64 InstanceId=instance_id65 )66 association = response['InstanceAssociationStatusInfos']67 for i in range(len(association)):68 if instance_association_name == association[i]['AssociationName']:69 return association[i]['AssociationId']70def create_association(ssm_client, playbook, instance_id, instance_association_name):71 response = ssm_client.create_association(72 Name='AWS-ApplyAnsiblePlaybooks',73 AssociationName=instance_association_name,74 Targets=[75 {76 'Key': 'InstanceIds',77 'Values': [...
ssm.py
Source:ssm.py
...9#response = client.list_inventory_entries()10ssm_inventory = client_ssm.get_inventory()["Entities"]11pprint(ssm_inventory[0]["Id"])12pprint(ssm_inventory[0]["Data"])...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!