How to use tag_log_group method in localstack

Best Python code snippet using localstack_python

svccwl.py

Source: svccwl.py Github

copy

Full Screen

...60 except botocore.exceptions.ClientError as e:61 if self._utils.is_resource_not_found(e): return None62 raise RdqError(self._utils.fail(e, op, 'LogGroupName', logGroupName))63 #PREVIEW64 def tag_log_group(self, logGroupName, tags :Tags):65 op = 'tag_log_group'66 args = {67 'LogGroupName': logGroupName,68 'Tags' : tags.toDict()69 }70 if self._utils.preview(op, args): return71 try:72 self._client.tag_log_group(73 logGroupName=logGroupName,74 tags=tags.toDict()75 )76 except botocore.exceptions.ClientError as e:77 if self._utils.is_resource_not_found(e): return78 raise RdqError(self._utils.fail(e, op, 'LogGroupName', logGroupName))79 #PREVIEW80 def associate_kms_key(self, logGroupName, kmsArn):81 op = 'associate_kms_key'82 args = {83 'LogGroupName': logGroupName,84 'KmsKeyId' : kmsArn85 }86 if self._utils.preview(op, args): return87 try:88 self._client.associate_kms_key(89 logGroupName=logGroupName,90 kmsKeyId=kmsArn91 )92 except botocore.exceptions.ClientError as e:93 if self._utils.is_resource_not_found(e): return94 raise RdqError(self._utils.fail(e, op, 'LogGroupName', logGroupName, 'KmsKeyId', kmsArn))95 #PREVIEW96 def disassociate_kms_key(self, logGroupName):97 op = 'disassociate_kms_key'98 args = {99 'LogGroupName': logGroupName100 }101 if self._utils.preview(op, args): return102 try:103 self._client.disassociate_kms_key(104 logGroupName=logGroupName105 )106 except botocore.exceptions.ClientError as e:107 if self._utils.is_resource_not_found(e): return108 raise RdqError(self._utils.fail(e, op, 'LogGroupName', logGroupName))109 def getLogGroupDescriptor(self, logGroupName :str) -> LogGroupDescriptor:110 exBase = self.describe_log_group(logGroupName)111 if not exBase: return None112 optTagDict = self.list_log_group_tags(logGroupName)113 exTags = Tags(optTagDict, logGroupName)114 return LogGroupDescriptor(exBase, exTags)115 #PREVIEW116 def associateKmsKeyWithLogGroup(self, logGroupName :str, cmkArn :str):117 self.associate_kms_key(logGroupName, cmkArn)118 #PREVIEW119 def disassociateKmsKeyWithLogGroup(self, logGroupName :str):120 self.associate_kms_key(logGroupName)121 #PREVIEW122 def putTags(self, logGroupName: str, tags :Tags):...

Full Screen

Full Screen

tag_cloudwatch_logs.py

Source: tag_cloudwatch_logs.py Github

copy

Full Screen

...24 # List tags and start tagging25 for logs in log_list:26 list_tags = client.list_tags_log_group(logGroupName = logs)27 if len(list_tags['tags']) == 0:28 start_tagging = client.tag_log_group(29 logGroupName = logs,30 tags = {31 'Name': logs,32 'CreatedBy': CreatedBy,33 'Environment': Environment,34 'Service': Service,35 'AccountNumber': AccountNumber36 }37 )38 else:39 # Name40 tags = [tag for tag in list_tags['tags'] if tag == 'Name']41 if len(tags) == 0:42 logger.info('Start tagging Name: %s' % (logs) )43 start_tagging = client.tag_log_group( logGroupName = logs, tags = { 'Name': logs })44 # Environment45 tags = [tag for tag in list_tags['tags'] if tag == 'Environment']46 if len(tags) == 0:47 logger.info('Start tagging Environment: %s' % (logs) )48 start_tagging = client.tag_log_group( logGroupName = logs, tags = { 'Environment': Environment })49 # Service50 tags = [tag for tag in list_tags['tags'] if tag == 'Service']51 if len(tags) == 0:52 logger.info('Start tagging Service: %s' % (logs) )53 start_tagging = client.tag_log_group( logGroupName = logs, tags = { 'Service': Service })54 # AccountNumber55 tags = [tag for tag in list_tags['tags'] if tag == 'AccountNumber']56 if len(tags) == 0:57 logger.info('Start tagging AccountNumber: %s' % (logs) )58 start_tagging = client.tag_log_group( logGroupName = logs, tags = { 'AccountNumber': AccountNumber })59 # CreatedBy60 tags = [tag for tag in list_tags['tags'] if tag == 'CreatedBy']61 if len(tags) == 0:62 logger.info('Start tagging CreatedBy: %s' % (logs) )63 start_tagging = client.tag_log_group( logGroupName = logs, tags = { 'CreatedBy': CreatedBy })64 except Exception as e:65 logger.info("Error: {}".format(traceback.print_exc()))66 return {67 'statusCode': 404,68 'body': json.dumps("Error: {}".format(e))69 }70 else:71 logger.info("Success!")72 return {73 'statusCode': 200,74 'body': json.dumps("Success, tagging complete!")...

Full Screen

Full Screen

tag_log_groups.py

Source: tag_log_groups.py Github

copy

Full Screen

...3import botocore4import jmespath5import time6import libs.notag_modules as ntm7def tag_log_group(logs_client, log_group, environment_tag, system_code):8 logs_client.tag_log_group(9 logGroupName=log_group,10 tags={11 "Environment": environment_tag,12 "SystemCode": system_code.upper()13 }14 )15def tag_log_groups(region, session, environment_tag, system_codes, **kwargs):16 print(f"Checking region {region}")17 my_config = botocore.config.Config(18 region_name=region19 )20 logs_client = session.client('logs', config=my_config)21 paginator = logs_client.get_paginator('describe_log_groups')22 response_iterator = paginator.paginate()23 log_groups = []24 for page in response_iterator:25 log_groups = log_groups + page['logGroups']26 log_groups = [log_group['logGroupName'] for log_group in log_groups]27 print(f"Total log groups: {len(log_groups)}")28 tag_counter = 029 if log_groups:30 for idx, log_group in enumerate(log_groups):31 time.sleep(0.25)32 if not idx % 10:33 print(f"Checking tags on log group #{idx + 1}...")34 tags = logs_client.list_tags_log_group(35 logGroupName=log_group36 )['tags']37 try:38 tagged = tags["SystemCode"]39 except KeyError:40 tagged = False41 for system_code in system_codes:42 if system_code in log_group.lower():43 tag_log_group(logs_client, log_group,44 environment_tag, system_code)45 tag_counter += 146 tagged = True47 break48 if not tagged:49 system_code = ntm.manual_system_code_input(50 log_group, system_codes)51 if system_code:52 tag_log_group(logs_client, log_group,53 environment_tag, system_code)54 tag_counter += 155 print(56 f"Tagged {tag_counter} log group{'s' if tag_counter != 1 else ''}.")57if __name__ == "__main__":58 available_regions, initial_parameters = ntm.initial_setup()59 for region in available_regions:...

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