Best Python code snippet using localstack_python
lambda_function.py
Source:lambda_function.py
...57 if len(versions) < 2:58 return59 try:60 try:61 cfn.deregister_type(Arn=versions[0]['Arn'])62 except cfn.exceptions.CFNRegistryException as e:63 if "is the default version" not in str(e):64 raise65 cfn.deregister_type(Arn=versions[1]['Arn'])66 except cfn.exceptions.TypeNotFoundException:67 print("version already deleted...")68@helper.delete69def delete(event, _):70 if not event['PhysicalResourceId'].startswith("arn:"):71 print("no valid arn to delete")72 return73 retries = 074 while True:75 try:76 try:77 cfn.deregister_type(Arn=event['PhysicalResourceId'])78 except cfn.exceptions.CFNRegistryException as e:79 if "is the default version" not in str(e):80 raise81 versions = cfn.list_type_versions(Type='RESOURCE', TypeName=event['ResourceProperties']['TypeName'])['TypeVersionSummaries']82 if len(versions) > 1:83 versions = [v['Arn'] for v in versions if v['Arn'] != event['PhysicalResourceId']]84 versions.sort(reverse=True)85 cfn.set_type_default_version(Arn=versions[0])86 cfn.deregister_type(Arn=event['PhysicalResourceId'])87 else:88 cfn.deregister_type(Type='RESOURCE', TypeName=event['ResourceProperties']['TypeName'])89 return90 except cfn.exceptions.TypeNotFoundException:91 print("type already deleted...")92 return93 except Exception as e:94 retries += 195 if retries > 5:96 raise97 logger.error(e, exc_info=True)98 sleep(random.choice([1, 2, 3, 4, 5]))99def lambda_handler(event, context):...
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!!