How to use describe_log_streams method in localstack

Best Python code snippet using localstack_python

data.py

Source:data.py Github

copy

Full Screen

...12def _fetch_task(ecs, logs, cluster: str, task_arn: str):13 described_task = ecs.describe_tasks(cluster=cluster, tasks=[task_arn])["tasks"][0]14 task_definition = ecs.describe_task_definition(taskDefinition=described_task["taskDefinitionArn"])15 log_configuration = task_definition["taskDefinition"]["containerDefinitions"][0]["logConfiguration"]16 describe_log_streams = logs.describe_log_streams(17 logGroupName=log_configuration["options"]["awslogs-group"],18 orderBy="LastEventTime",19 descending=True,20 limit=1,21 )22 log_events = logs.get_log_events(23 logGroupName=log_configuration["options"]["awslogs-group"],24 logStreamName=describe_log_streams["logStreams"][0]["logStreamName"],25 limit=100,26 startFromHead=False,27 )28 return {"task": described_task, "task_definition": task_definition["taskDefinition"], "logs": log_events}29def fetch_task(context: ContextObject, click_params):30 return _fetch_task(context.ecs, context.logs, click_params["cluster"], _task_arn_helper(context, click_params))31def fetch_run_task(context: ContextObject, click_params):32 if not getattr(fetch_run_task, "task_ran", False):33 args = {"cluster": click_params["cluster"]}34 try:35 _, _ = click_params["task_definition"].split(":")36 args["taskDefinition"] = click_params["task_definition"]37 except ValueError:38 args["taskDefinition"] = _fetch_latest_active_task_definition(context.ecs, click_params["task_definition"])39 if click_params["command"]:40 args["overrides"] = {41 "containerOverrides": [42 {"name": args["taskDefinition"].rsplit("/")[1], "command": click_params["command"]}43 ]44 }45 if click_params["capacity_provider_strategy"]:46 args["capacityProviderStrategy"] = [json.loads(click_params["capacity_provider_strategy"])]47 if click_params["network_configuration"]:48 args["networkConfiguration"] = json.loads(click_params["network_configuration"])49 result = context.ecs.run_task(**args)50 fetch_run_task.task_ran = True51 fetch_run_task.task_arn = result["tasks"][0]["taskArn"]52 return _fetch_task(context.ecs, context.logs, click_params["cluster"], fetch_run_task.task_arn)53def fetch_listing(context: ContextObject, click_params):54 return base_fetch_listing(55 context.ecs,56 paginator_type="list_tasks",57 arn_index="taskArns",58 describe_function=context.ecs.describe_tasks,59 describe_filter="tasks",60 result_key="tasks",61 paginator_params={"cluster": click_params["cluster"]},62 )63def fetch_logs(context: ContextObject, click_params):64 task_arn = _task_arn_helper(context, click_params)65 described_task = context.ecs.describe_tasks(cluster=click_params["cluster"], tasks=[task_arn])["tasks"][0]66 task_definition = context.ecs.describe_task_definition(taskDefinition=described_task["taskDefinitionArn"])67 log_configuration = task_definition["taskDefinition"]["containerDefinitions"][0]["logConfiguration"]68 describe_log_streams = context.logs.describe_log_streams(69 logGroupName=log_configuration["options"]["awslogs-group"],70 orderBy="LastEventTime",71 descending=True,72 limit=1,73 )74 log_events = context.logs.get_log_events(75 logGroupName=log_configuration["options"]["awslogs-group"],76 logStreamName=describe_log_streams["logStreams"][0]["logStreamName"],77 limit=25,78 startFromHead=False,79 )...

Full Screen

Full Screen

cw_utils.py

Source:cw_utils.py Github

copy

Full Screen

...58 upper_timestamp = iso_to_timestamp(older_than)59 fetched_files = []60 next_token = None61 while next_token is not 'theEnd':62 streams = describe_log_streams(client, log_group, next_token)63 next_token = streams.get('nextToken', 'theEnd')64 for stream in streams['logStreams']:65 if lower_timestamp and stream['lastEventTimestamp'] < lower_timestamp:66 return fetched_files # we're done, next logs will be even older67 if upper_timestamp and stream['firstEventTimestamp'] > upper_timestamp:68 continue69 stream_prefix = stream['logStreamName'].split("/")[0]70 file_name = "%s%s.log" % (pathprefix, stream_prefix)71 download_log(file_name, stream_prefix=stream_prefix, log_group=log_group)72 fetched_files.append(73 (file_name, stream_prefix, stream['firstEventTimestamp'], stream['lastEventTimestamp']))74 return fetched_files75def describe_log_streams(client, log_group, next_token):76 if next_token:77 streams = client.describe_log_streams(logGroupName=log_group, orderBy='LastEventTime',78 descending=True, nextToken=next_token)79 else:80 streams = client.describe_log_streams(logGroupName=log_group, orderBy='LastEventTime',81 descending=True)82 return streams83def iso_to_timestamp(iso_date):...

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