Best Python code snippet using localstack_python
instance_profile.py
Source:instance_profile.py
...66 '''67 self.logger.debug('Add role to %s with parameters: %s'68 % (self.type_name, params))69 self.client.add_role_to_instance_profile(**params)70 def remove_role_from_instance_profile(self, params=None):71 '''72 Remove a role from an AWS IAM Profile.73 '''74 self.logger.debug('Remove role from %s with parameters: %s'75 % (self.type_name, params))76 self.client.remove_role_from_instance_profile(**params)77@decorators.aws_resource(IAMInstanceProfile, RESOURCE_TYPE)78def create(ctx, iface, resource_config, **_):79 '''Creates an AWS IAM Profile'''80 # Build API params81 params = \82 dict() if not resource_config else resource_config.copy()83 resource_id = \84 utils.get_resource_id(85 ctx.node,86 ctx.instance,87 params.get(RESOURCE_NAME),88 use_instance_id=True89 ) or iface.resource_id90 params[RESOURCE_NAME] = resource_id91 utils.update_resource_id(ctx.instance, resource_id)92 role_name = params.pop('RoleName', None)93 create_response = iface.create(params)94 resource_id = create_response['InstanceProfile'][RESOURCE_NAME]95 iface.update_resource_id(resource_id)96 utils.update_resource_id(ctx.instance, resource_id)97 utils.update_resource_arn(98 ctx.instance, create_response['InstanceProfile']['Arn'])99 role_name = role_name or \100 utils.find_resource_id_by_type(ctx.instance,101 IAM_ROLE_TYPE)102 if role_name:103 add_role_params = {104 RESOURCE_NAME: iface.resource_id,105 'RoleName': role_name106 }107 iface.add_role_to_instance_profile(add_role_params)108 ctx.instance.runtime_properties['RoleName'] = role_name109@decorators.aws_resource(IAMInstanceProfile, RESOURCE_TYPE)110def delete(ctx, iface, resource_config, **_):111 '''Deletes an AWS IAM Profile'''112 # Create a copy of the resource config for clean manipulation.113 params = \114 dict() if not resource_config else resource_config.copy()115 instance_profile_name = params.get(RESOURCE_NAME)116 if not instance_profile_name:117 instance_profile_name = iface.resource_id118 params[RESOURCE_NAME] = instance_profile_name119 # Path parameter is not accepted by delete_instance_profile.120 try:121 del params['Path']122 except KeyError:123 pass124 role_name = params.pop('RoleName', None)125 if not role_name:126 role_name = \127 utils.find_resource_id_by_type(ctx.instance,128 IAM_ROLE_TYPE)129 if role_name:130 remove_role_params = {131 RESOURCE_NAME: instance_profile_name,132 'RoleName': role_name133 }134 iface.remove_role_from_instance_profile(remove_role_params)...
teardown.py
Source:teardown.py
...26 response = ecs.delete_cluster(27 cluster=cluster_name28 )29 return response30def remove_role_from_instance_profile():31 iam_client.remove_role_from_instance_profile(32 InstanceProfileName=config.ec2_instance_profile,33 RoleName=config.ec2_container_service_role34 )35def delete_security_group():36 ec2.delete_security_group(37 GroupName=config.security_group_name38 )39def detach_policy():40 role = iam_resource.Role(config.ec2_container_service_role)41 role.detach_policy(PolicyArn=config.aws_ec2_container_service_role)42def delete_role():43 role = iam_resource.Role(config.ec2_container_service_role)44 role.delete()45def teardown():46 print(delete_cluster())47 print(deregister_task_definition(family_name, family_version))48 delete_security_group()49 detach_policy()50 remove_role_from_instance_profile()51 time.sleep(3)52 delete_role()53 print(disassociate_iam_instance_profile())54 print(delete_instance_profile())55if __name__ == "__main__":...
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!!