How to use get_discovered_resource_counts method in localstack

Best Python code snippet using localstack_python

collector.py

Source:collector.py Github

copy

Full Screen

...51 client = boto3.client("config", config=botoConfig, region_name=region)52 regionStats = {}53 # List resources recorded by AWS Config54 resourceCounts = []55 resp = client.get_discovered_resource_counts()56 while resp:57 resourceCounts.extend(resp['resourceCounts'])58 resp = client.get_discovered_resource_counts(NextToken=resp['NextToken']) if 'NextToken' in resp else None59 for resource in resourceCounts:60 compliantCount = 061 noncompliantCount = 062 resp = client.get_compliance_summary_by_resource_type(ResourceTypes=[resource['resourceType']])63 while resp:64 time.sleep(self.throttle) # Rate limit65 compliantCount += (resp['ComplianceSummariesByResourceType'][0]['ComplianceSummary']['CompliantResourceCount']['CappedCount'])66 noncompliantCount += (resp['ComplianceSummariesByResourceType'][0]['ComplianceSummary']['NonCompliantResourceCount']['CappedCount'])67 resp = client.get_compliance_summary_by_resource_type(ResourceTypes=[resource['resourceType']], NextToken=resp['NextToken']) if 'NextToken' in resp else None68 regionStats[resource['resourceType']] = (resource['count'], compliantCount, noncompliantCount)...

Full Screen

Full Screen

getResourceCount.py

Source:getResourceCount.py Github

copy

Full Screen

...7 response=boto3.client('ec2').describe_regions()8 return response['Regions']9def getResourceCount(region):10 client = boto3.client('config', region_name=region)11 response = client.get_discovered_resource_counts( limit=3 )12 return response['totalDiscoveredResources']13d['accountId'] = boto3.client('sts').get_caller_identity().get('Account')14d['resourcesInAcct'] = 015regions = getRegions()16for region in regions:17 regionName = region['RegionName']18 resourcesInRegion = getResourceCount(region['RegionName'])19 d[regionName] = resourcesInRegion20 d['resourcesInAcct'] = d['resourcesInAcct'] + resourcesInRegion21print(json.dumps(d, indent=2))22with open("resourceCount.json", "a") as outFile:...

Full Screen

Full Screen

config-compliance-stats.py

Source:config-compliance-stats.py Github

copy

Full Screen

1import boto32client = boto3.client('config')3organization_aggregator_name = 'OrganizationAggregator'4# resource_counts = client.get_discovered_resource_counts()5# comp = client.describe_compliance_by_config_rule()6paginator = client.get_paginator('describe_aggregate_compliance_by_config_rules')7response_iterator = paginator.paginate(ConfigurationAggregatorName=organization_aggregator_name)8# comps = client.describe_aggregate_compliance_by_config_rules(ConfigurationAggregatorName=organization_aggregator_name)9for iterator in response_iterator:10 for comp in iterator['AggregateComplianceByConfigRules']:11 config_rule_name = comp['ConfigRuleName']12 compliance = comp['Compliance']['ComplianceType']13 account_id = comp['AccountId']14 region = comp['AwsRegion']15 print(f'{account_id} ({region}): {compliance} - {config_rule_name}')...

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