Best Python code snippet using localstack_python
decommission_ami_version.py
Source: decommission_ami_version.py
...36 snaps = ec2.describe_snapshots()37 for snap in snaps['Snapshots']:38 if amiID in snap['Description']:39 ec2.delete_snapshot(SnapshotId=snap['SnapshotId'])40 ssm.delete_parameters(Names=params)41 try:42 temp = ssm.get_parameter(Name=masterAmis)['Parameter']['Value']43 temp = temp.replace(amiID + ',', '').replace(',' + amiID, '').replace(amiID, '')44 if len(temp) == 0:45 ssm.delete_parameters(Names=[masterAmis])46 else:47 ssm.put_parameter(Name=masterAmis, Type='String', Value=temp, Overwrite=True)48 return 'Done'49 except botocore.exceptions.ClientError as e:50 if e.response['Error']['Code'] == 'ParameterNotFound':51 print('This indicates that the active amis are not present')52 return 'Done'53 mappingJSON = json.loads(amiIDRegionMapping)54 for region, amiID in mappingJSON.items():55 sc = boto3.client('servicecatalog', region)56 products = sc.search_products_as_admin(ProductSource='ACCOUNT')57 for product in products['ProductViewDetails']:58 productName = product['ProductViewSummary']['Name']59 if productName == prodName + '-' + prodOS:60 productID = product['ProductViewSummary']['ProductId']61 provisioningArtifacts = sc.list_provisioning_artifacts(ProductId=productID)[62 'ProvisioningArtifactDetails']63 if len(provisioningArtifacts) == 1:64 sc.delete_product(Id=productID)65 else:66 for artifact in provisioningArtifacts:67 if artifact['Name'] == version:68 sc.delete_provisioning_artifact(ProductId=productID, ProvisioningArtifactId=artifact['Id'])69 ec2 = boto3.client('ec2', region)70 ec2.deregister_image(ImageId=amiID)71 time.sleep(5)72 snaps = ec2.describe_snapshots()73 for snap in snaps['Snapshots']:74 if amiID in snap['Description']:75 ec2.delete_snapshot(SnapshotId=snap['SnapshotId'])76 ssm = boto3.client('ssm', region)77 ssm.delete_parameters(Names=[prefix])78 temp = ssm.get_parameter(Name=masterAmis)['Parameter']['Value']79 temp = temp.replace(amiID + ',', '').replace(',' + amiID, '').replace(amiID, '')80 if len(temp) == 0:81 ssm.delete_parameters(Names=[masterAmis])82 else:83 ssm.put_parameter(Name=masterAmis, Type='String', Value=temp, Overwrite=True)84 if region == sourceRegion:85 ssm.delete_parameters(Names=params)...
urlparser.py
Source: urlparser.py
1import re2from django.template import Library, Node, TemplateSyntaxError, VariableDoesNotExist3register = Library()4class ParameterNode(Node):5 @classmethod6 def create(cls, parser, token):7 set_parameters = {}8 delete_parameters = []9 set_re = re.compile(r'(\w+)=(.+)')10 delete_re = re.compile(r'!(\w+)')11 for bit in token.split_contents()[1:]:12 match = set_re.match(bit)13 if match:14 name, value = match.groups()15 set_parameters[name] = parser.compile_filter(value)16 continue17 match = delete_re.match(bit)18 if match:19 name, = match.groups()20 delete_parameters.append(name)21 continue22 raise TemplateSyntaxError("Malformed arguments to {set,form}_parameter tag", bit)23 return cls(set_parameters, delete_parameters)24 def __init__(self, set_parameters, delete_parameters):25 self.set_parameters = set_parameters26 self.delete_parameters = delete_parameters27 def get_query(self, context):28 query = context['request'].GET.copy()29 for argname, argvalue in self.set_parameters.items():30 try:31 query[argname] = argvalue.resolve(context)32 except AttributeError:33 query[argname] = argvalue34 except VariableDoesNotExist:35 query[argname] = None36 for argname in self.delete_parameters:37 try:38 del query[argname]39 except KeyError:40 pass41 return query42class ParameterGetNode(ParameterNode):43 def render(self, context):44 return "?" + self.get_query(context).urlencode()45class ParameterFormNode(ParameterNode):46 def render(self, context):47 query = self.get_query(context)48 return "".join(["<input type=\"hidden\" name=\"{}\" value=\"{}\" />".format(name, value) for name, value in query.items()])49@register.tag50def get_parameter(parser, token):51 return ParameterGetNode.create(parser, token)52@register.tag53def form_parameter(parser, token):54 return ParameterFormNode.create(parser, token)55@register.filter(is_safe=False)56def list_without(value, arg):57 return [item for item in value if item != arg]58@register.filter(is_safe=False)59def list_with(value, arg):...
ssm_delete_parameter.py
Source: ssm_delete_parameter.py
...35 Name=parameter_name36 )37 except ClientError as e:38 logging.error(e)39def delete_parameters(parameter_names):40 """Delete multiple parameters in AWS SSM41 :param parameter_names: List of parameter names to delete from AWS SSM42 """43 ssm_client = boto3.client('ssm')44 try:45 ssm_client.delete_parameters(46 Names=parameter_names47 )48 except ClientError as e:49 logging.error(e)50def main():51 # Assign these values before running the program52 parameter_name = 'test_param'53 # Set up logging54 logging.basicConfig(level=logging.DEBUG,55 format='%(levelname)s: %(asctime)s: %(message)s')56 # delete parameter from SSM57 delete_parameter(parameter_name)58 # delete multiple parameters from SSM59 parameter_names = ['test_param1', 'test_param2']60 delete_parameters(parameter_names)61if __name__ == '__main__':...
Check out the latest blogs from LambdaTest on this topic:
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 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.
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.
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.
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!!