How to use log_group_arn method in localstack

Best Python code snippet using localstack_python

test_log.py

Source:test_log.py Github

copy

Full Screen

...53 self.provision()54 def _get_logs(self, log_group):55 logs = {}56 for region in self.app.regions.keys():57 log_group_arn = self._log_group_arn(region, log_group)58 if not log_group_arn:59 continue60 logs[region] = self._log_events(region, log_group_arn)61 return logs62 def _log_events(self, region, log_group_arn):63 cwl = self.clients.logs(region)64 region_logs = []65 # Don't paginate: recent logs are in the first page66 streams = cwl.describe_log_streams(logGroupName=log_group_arn,67 orderBy='LastEventTime',68 descending=True)69 for stream in streams.get('logStreams', ()):70 stream_name = stream['logStreamName']71 print(stream_name)72 # Don't paginate: recent logs are in the first page73 events = cwl.get_log_events(74 logGroupName=log_group_arn,75 logStreamName=stream_name,76 startTime=self.start77 )78 for event in events.get('events', ()):79 region_logs.append(event)80 return region_logs81 def _log_group_arn(self, region, log_group):82 cf = self.clients.cloudformation(region)83 resource = cf.describe_stack_resource(84 StackName='sl-test-laika',85 LogicalResourceId=log_group86 )...

Full Screen

Full Screen

index.py

Source:index.py Github

copy

Full Screen

...14 except cloudwatch_client.exceptions.ResourceAlreadyExistsException:15 pass16 retention_in_days = int(properties['RetentionInDays'])17 cloudwatch_client.put_retention_policy(logGroupName=log_group_name, retentionInDays=retention_in_days)18 return log_group_arn(log_group_name)19@helper.update20def update(event: dict, context) -> str:21 properties_old = event['OldResourceProperties']22 properties = event['ResourceProperties']23 log_group_arn = event['PhysicalResourceId']24 if log_group_arn.find('arn:aws:logs:') != 0 or ':log-group:' not in log_group_arn:25 return log_group_arn # not a valid log-group arn26 log_group_name = log_group_arn.rsplit(maxsplit=2, sep=':')[1]27 if properties['LogGroupName'] != properties_old['LogGroupName']:28 raise Exception(f'Renaming a LogGroup is not supported.')29 if properties['RetentionInDays'] != properties_old['RetentionInDays']:30 retention_in_days = int(properties['RetentionInDays'])31 cloudwatch_client.put_retention_policy(logGroupName=log_group_name, retentionInDays=retention_in_days)32 return log_group_arn33@helper.delete34def delete(event: dict, context) -> str:35 log_group_arn = event['PhysicalResourceId']36 if log_group_arn.find('arn:aws:logs:') != 0 or ':log-group:' not in log_group_arn:37 return log_group_arn # not a valid log-group arn38 log_group_name = log_group_arn.rsplit(maxsplit=2, sep=':')[1]39 try:40 cloudwatch_client.delete_log_group(logGroupName=log_group_name)41 except cloudwatch_client.exceptions.ResourceNotFoundException:42 pass43 return log_group_arn44def log_group_arn(log_group_name: str) -> str:45 response = cloudwatch_client.describe_log_groups(logGroupNamePrefix=log_group_name, limit=1)46 return response['logGroups'][0]['arn']47def handle(event: dict, context) -> None:48 logger.info(json.dumps(event))...

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