How to use tag_resource method in localstack

Best Python code snippet using localstack_python

configrule_tagging.py

Source:configrule_tagging.py Github

copy

Full Screen

...27 for rule in rules:28 response = self.config_client.list_tags_for_resource( ResourceArn = rule['ConfigRuleArn'] )29 if len(response['Tags']) == 0:30 logger.info("No tags for rules %s.", rule['ConfigRuleName'])31 self.config_client.tag_resource( ResourceArn = rule['ConfigRuleArn'],32 Tags = [33 { 'Key': 'Name', 'Value': rule['ConfigRuleName'] },34 { 'Key': 'Service', 'Value': Service },35 { 'Key': 'Environment', 'Value': Environment },36 { 'Key': 'AccountNumber', 'Value': AccountNumber },37 { 'Key': 'CreatedBy', 'Value': AccountNumber }38 ] )39 else:40 # Name41 keys = [tag for tag in response['Tags'] if tag['Key'] == 'Name']42 if len(keys) == 0:43 logger.info("Start tagging Name: %s.", rule['ConfigRuleName'])44 self.config_client.tag_resource(ResourceArn = rule['ConfigRuleArn'], 45 Tags = [{'Key': 'Name', 'Value': rule['ConfigRuleName'] } ] )46 # AccountNumber47 keys = [tag for tag in response['Tags'] if tag['Key'] == 'AccountNumber']48 if len(keys) == 0:49 logger.info("Start tagging AccountNumber: %s.", rule['ConfigRuleName'])50 self.config_client.tag_resource(ResourceArn = rule['ConfigRuleArn'], 51 Tags = [{'Key': 'AccountNumber', 'Value': AccountNumber } ] )52 # Service53 keys = [tag for tag in response['Tags'] if tag['Key'] == 'Service']54 if len(keys) == 0:55 logger.info("Start tagging Service: %s.", rule['ConfigRuleName'])56 self.config_client.tag_resource(ResourceArn = rule['ConfigRuleArn'], 57 Tags = [{'Key': 'Service', 'Value': Service } ] )58 # Environment59 keys = [tag for tag in response['Tags'] if tag['Key'] == 'Environment']60 if len(keys) == 0:61 logger.info("Start tagging Environment: %s.", rule['ConfigRuleName'])62 self.config_client.tag_resource(ResourceArn = rule['ConfigRuleArn'], 63 Tags = [{'Key': 'Environment', 'Value': Environment } ] )64 # CreatedBy65 keys = [tag for tag in response['Tags'] if tag['Key'] == 'CreatedBy']66 if len(keys) == 0:67 logger.info("Start tagging CreatedBy: %s.", rule['ConfigRuleName'])68 self.config_client.tag_resource(ResourceArn = rule['ConfigRuleArn'], 69 Tags = [{'Key': 'CreatedBy', 'Value': CreatedBy } ] )70 return71 except ClientError:72 logger.exception("Error: {}".format(traceback.print_exc()))73 raise74def lambda_handler(event, context):75 config = ConfigWrapper(boto3.client('config'))76 try: 77 response = config.list_tags_for_resource()78 except Exception as e:79 logger.info("Error: {}".format(traceback.print_exc()))80 return {81 'statusCode': 404,82 'body': json.dumps("Error: {}".format(e))...

Full Screen

Full Screen

ecs_put_tags.py

Source:ecs_put_tags.py Github

copy

Full Screen

...18 )19 all_tags = response['tags']20 matches = [tag for tag in all_tags if tag['key'] == 'Name']21 if len(matches) == 0:22 response = client.tag_resource(23 resourceArn = i,24 tags = [{'key': 'Name', 'value': i.split("/")[1] }]25 )26 matches = [tag for tag in all_tags if tag['key'] == 'Service']27 if len(matches) == 0:28 response = client.tag_resource(29 resourceArn = i,30 tags = [{'key': 'Service', 'value': Service }]31 )32 matches = [tag for tag in all_tags if tag['key'] == 'Environment']33 if len(matches) == 0:34 response = client.tag_resource(35 resourceArn = i,36 tags = [{'key': 'Environment', 'value': Environment }]37 )38 matches = [tag for tag in all_tags if tag['key'] == 'AccountNumber']39 if len(matches) == 0:40 response = client.tag_resource(41 resourceArn = i,42 tags = [{'key': 'AccountNumber', 'value': AccountNumber }]43 )44 matches = [tag for tag in all_tags if tag['key'] == 'CreatedBy']45 if len(matches) == 0:46 response = client.tag_resource(47 resourceArn = i,48 tags = [{'key': 'CreatedBy', 'value': CreatedBy }]49 )50 51 response = client.list_clusters()52 for j in response['clusterArns']:53 response = client.list_tags_for_resource(54 resourceArn = j55 )56 all_cluster_tags = response['tags']57 cluster_matches = [t for t in all_cluster_tags if t['key'] == 'Name']58 if len(cluster_matches) == 0:59 response = client.tag_resource(60 resourceArn = j,61 tags = [{'key': 'Name', 'value': j.split("/")[1] }]62 )63 cluster_matches = [t for t in all_cluster_tags if t['key'] == 'Service']64 if len(cluster_matches) == 0:65 response = client.tag_resource(66 resourceArn = j,67 tags = [{'key': 'Service', 'value': Service }]68 )69 cluster_matches = [t for t in all_cluster_tags if t['key'] == 'Environment']70 if len(cluster_matches) == 0:71 response = client.tag_resource(72 resourceArn = j,73 tags = [{'key': 'Environment', 'value': Environment }]74 )75 cluster_matches = [t for t in all_cluster_tags if t['key'] == 'CreatedBy']76 if len(cluster_matches) == 0:77 response = client.tag_resource(78 resourceArn = j,79 tags = [{'key': 'CreatedBy', 'value': CreatedBy }]80 )81 cluster_matches = [t for t in all_cluster_tags if t['key'] == 'AccountNumber']82 if len(cluster_matches) == 0:83 response = client.tag_resource(84 resourceArn = j,85 tags = [{'key': 'AccountNumber', 'value': AccountNumber }]86 )87 88 89 except Exception as error:90 traceback.print_exc()91 92 return {93 'statusCode': 200,94 'body': json.dumps('Hello from Lambda!')...

Full Screen

Full Screen

tag_lambdas.py

Source:tag_lambdas.py Github

copy

Full Screen

...7client = boto3.client('lambda')8response = client.list_functions()9for i in response['Functions']:10 if re.search(r'dev', i['FunctionArn']):11 tag_response = client.tag_resource(12 Resource=i['FunctionArn'],13 Tags={14 'ProductCode': '<Code>',15 'Function': '<Function>',16 'ServiceLevel': 'DEVELOPMENT',17 'Customers': '<Customer>'18 }19 )20 elif re.search(r'sbx', i['FunctionArn']):21 tag_response = client.tag_resource(22 Resource=i['FunctionArn'],23 Tags={24 'ProductCode': '<Code>',25 'Function': '<Function>',26 'ServiceLevel': 'TEST',27 'Customers': '<Customer>'28 }29 )30 elif re.search(r'stg', i['FunctionArn']):31 tag_response = client.tag_resource(32 Resource=i['FunctionArn'],33 Tags={34 'ProductCode': '<Code>',35 'Function': '<Function>',36 'ServiceLevel': 'UAT',37 'Customers': '<Customer>'38 }39 )40 elif re.search(r'prd', i['FunctionArn']):41 tag_response = client.tag_resource(42 Resource=i['FunctionArn'],43 Tags={44 'ProductCode': '<Code>',45 'Function': '<Function>',46 'ServiceLevel': 'PRODUCTION',47 'Customers': '<Customer>'48 }49 )50 else:51 tag_response = client.tag_resource(52 Resource=i['FunctionArn'],53 Tags={54 'ProductCode': '<Code>',55 'Function': '<Function>',56 'ServiceLevel': 'Internal',57 'Customers': '<Customer>'58 }...

Full Screen

Full Screen

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