How to use delete_instance_profile method in localstack

Best Python code snippet using localstack_python

create_instance_profile.py

Source: create_instance_profile.py Github

copy

Full Screen

...66 cfnresponse.send(event, context, cfnresponse.FAILED, {}, resource_id)67def delete_all(iam, name):68 clean_policies(iam, name)69 clean_instance_profile(iam, name)70 delete_instance_profile(iam, name)71 delete_role(iam, name)72def clean_policies(iam, name):73 try:74 attached = iam.list_attached_role_policies(RoleName=name)75 for policy in attached["AttachedPolicies"]:76 iam.detach_role_policy(RoleName=name, PolicyArn=policy["PolicyArn"])77 except Exception as e:78 print str(e)79def clean_instance_profile(iam, name):80 try:81 instance_profile = iam.get_instance_profile(InstanceProfileName=name)82 for role in instance_profile["InstanceProfile"].get("Roles", []):83 iam.remove_role_from_instance_profile(84 InstanceProfileName=name,85 RoleName=role["RoleName"]86 )87 except Exception as e:88 print str(e)89def delete_instance_profile(iam, name):90 try:91 iam.delete_instance_profile(InstanceProfileName=name)92 except Exception as e:93 print str(e)94def delete_role(iam, name):95 try:96 iam.delete_role(RoleName=name)97 except Exception as e:98 print str(e)99def handler(event, context):100 if event["RequestType"] == "Create":101 handler_create(event, context)102 elif event["RequestType"] == "Update":103 handler_update(event, context)104 else:105 handler_delete(event, context)

Full Screen

Full Screen

ec2.py

Source: ec2.py Github

copy

Full Screen

...40 41 return to_terminate42def create_instance_profile(name, policy):43 # Remove it before starting44 delete_instance_profile(name)45 46 # Next, you need to create an Instance Profile in IAM.47 c = boto.connect_iam()48 instance_profile = c.create_instance_profile(name)49 # Once you have the instance profile, you need to create the role, 50 # add the role to the instance profile and associate the policy with the role.51 role = c.create_role(name)52 c.add_role_to_instance_profile(name, name)53 c.put_role_policy(name, name, policy)54 # Wait for it to be available55 for _ in xrange(10):56 57 # We want to wait in all cases, because I've seen the roles created58 # and available via the API but not to EC2 instances. So we better wait59 # for at least 1min60 logging.debug('Waiting for role %s to be available...' % name)61 time.sleep(60)62 63 try:64 c.get_role(name)65 c.get_instance_profile(name)66 break67 except:68 pass69 else:70 raise RuntimeError('Role creation for instance profile failed.')71 # Now, you can use that instance profile when you launch an instance72 return name73def delete_instance_profile(name):74 iam = boto.connect_iam()75 76 logging.warn('Removing IAM instance profile "%s"' % name)77 78 try:79 iam.remove_role_from_instance_profile(name, name)80 except Exception, e:81 pass82 83 try:84 iam.get_instance_profile(name)85 iam.delete_instance_profile(name)86 except Exception, e:87 pass88 89 try:90 iam.get_role_policy(name, name)91 iam.delete_role_policy(name, name)92 except Exception, e:93 pass94 try:95 iam.get_role(name)96 iam.delete_role(name)97 except Exception, e:...

Full Screen

Full Screen

teardown.py

Source: teardown.py Github

copy

Full Screen

...15 else:16 logging.debug('Removing security group "%s"' % NAME)17 conn.delete_security_group(SG_NAME)18 ...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

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