Best Python code snippet using localstack_python
AccountMigrationClassTest_v0.0.9.py
Source:AccountMigrationClassTest_v0.0.9.py
...124 print(f"Accepting the handshake with ID: {identifier}")125 self.org.accept_handshake(126 HandshakeId=identifier127 )128 def update_resolver_rule(self,vpc_list,resolverRuleId=NEW_RESOLVER_RULE):129 client = self.session.client("route53resolver")130 for vpc in list(vpc_list):131 client.associate_resolver_rule(132 ResolverRuleId=resolverRuleId,133 VPCId=vpc.id134 )135 return136class Master:137 def __init__(self,accountId):138 self.accountId = accountId 139 if accountId == "741252614647":140 self.session = boto3.session.Session(141 profile_name="master",142 region_name="us-west-2"143 )144 self.rootId = "r-7w8p"145 self.executionRole = "OrganizationAccountAccessRole"146 elif accountId == "662627786878":147 self.session = boto3.session.Session(148 profile_name="ct_master",149 region_name="us-west-2"150 ) 151 self.rootId = "r-mdy1"152 self.executionRole = "AWSControlTowerExecution"153 else:154 print("Account ID is not a valid Master Account")155 self.org = self.session.client("organizations")156 self.sts = self.session.client("sts")157 self.get_caller_account()158 def get_caller_account(self):159 try:160 return self.session.client('sts').get_caller_identity().get('Account')161 except (UnauthorizedSSOTokenError, SSOTokenLoadError) as e:162 if "expired or is otherwise invalid" in str(e):163 delimiter()164 logger.info(e)165 logger.info("Reinitiating SSO Login...")166 os.system(f"aws sso login --profile {self.session.profile_name}")167 return self.session.client('sts').get_caller_identity().get('Account')168 def invite_account(self,identifier): 169 response = self.org.invite_account_to_organizaiton(170 Target={171 'Id':identifier,172 'Type':'ACCOUNT'173 }174 )175 return response['Handshake']176 def move_account(self,accountId,sourceId,destinationId):177 self.org.move_account(178 AccountId=accountId,179 SourceParentId=sourceId,180 DestinationParentId=destinationId181 )182 return183 def find_ou(self,identifier):184 ou = [ ou for ou in self.org.list_children(ParentId=self.rootId,185 ChildType='ORGANIZATIONAL_UNIT')['Children']186 if identifier == self.org.describe_organizational_unit(187 OrganizationalUnitId=ou['Id'])['OrganizationalUnit']['Name']188 ] 189 response = ou[0]['Id']190 return response191def delimiter(symbol='='):192 logger.info(symbol * 120)193def create_filter(name=None, values=[]):194 return {195 "Name": name,196 "Values": values197 }198legacy_master = Master('741252614647')199new_master = Master('662627786878')200target_input = input("List the Account IDs for the target account " 201 "(Separate multiple entries with a comma ','): ")202accounts = target_input.split(',') 203for account in accounts:204 accnt = Account(205 account_id=account,206 master_obj=legacy_master)207 print(accnt.ou)208 for vpc in accnt.vpcs:209 print(vpc.id) 210 # handshake_info = new_master.invite_account(account)211 # accnt = Account(account)212 # accnt.config_cleanup()213 # accnt.leave_organization()214 # accnt.accept_invitation(handshake_info['Id'])215 # accnt.update_resolver_rule(accnt.vpcs)216 # new_master.move_account(217 # accountId=accnt.accountid,218 # sourceId=new_master.rootId,219 # destinationId=new_master.find_ou(220 # identifier=accnt.ou['Name']221 # )...
client.py
Source:client.py
...55 def untag_resource(self, ResourceArn: str, TagKeys: List) -> Dict:56 pass57 def update_resolver_endpoint(self, ResolverEndpointId: str, Name: str = None) -> Dict:58 pass59 def update_resolver_rule(self, ResolverRuleId: str, Config: Dict) -> Dict:...
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!!