How to use get_lambda_invocations_count method in localstack

Best Python code snippet using localstack_python

test_integration.py

Source:test_integration.py Github

copy

Full Screen

...219 # this can take a long time in CI, make sure we give it enough time/retries220 retry(check_events, retries=7, sleep=3)221 # make sure the we have the right amount of INSERT/MODIFY event types222 # check cloudwatch notifications223 num_invocations = get_lambda_invocations_count(TEST_LAMBDA_NAME_STREAM)224 assert num_invocations == 2 + num_events_lambda225 num_error_invocations = get_lambda_invocations_count(TEST_LAMBDA_NAME_STREAM, 'Errors')226 assert num_error_invocations == 1227def test_kinesis_lambda_forward_chain():228 kinesis = aws_stack.connect_to_service('kinesis')229 s3 = aws_stack.connect_to_service('s3')230 aws_stack.create_kinesis_stream(TEST_CHAIN_STREAM1_NAME, delete=True)231 aws_stack.create_kinesis_stream(TEST_CHAIN_STREAM2_NAME, delete=True)232 s3.create_bucket(Bucket=TEST_BUCKET_NAME)233 # deploy test lambdas connected to Kinesis streams234 zip_file = testutil.create_lambda_archive(load_file(TEST_LAMBDA_PYTHON), get_content=True,235 libs=TEST_LAMBDA_LIBS, runtime=LAMBDA_RUNTIME_PYTHON27)236 testutil.create_lambda_function(func_name=TEST_CHAIN_LAMBDA1_NAME, zip_file=zip_file,237 event_source_arn=get_event_source_arn(TEST_CHAIN_STREAM1_NAME), runtime=LAMBDA_RUNTIME_PYTHON27)238 testutil.create_lambda_function(func_name=TEST_CHAIN_LAMBDA2_NAME, zip_file=zip_file,239 event_source_arn=get_event_source_arn(TEST_CHAIN_STREAM2_NAME), runtime=LAMBDA_RUNTIME_PYTHON27)240 # publish test record241 test_data = {'test_data': 'forward_chain_data_%s' % short_uid()}242 data = clone(test_data)243 data[lambda_integration.MSG_BODY_MESSAGE_TARGET] = 'kinesis:%s' % TEST_CHAIN_STREAM2_NAME244 kinesis.put_record(Data=to_bytes(json.dumps(data)), PartitionKey='testId', StreamName=TEST_CHAIN_STREAM1_NAME)245 # check results246 time.sleep(5)247 all_objects = testutil.list_all_s3_objects()248 testutil.assert_objects(test_data, all_objects)249# ---------------250# HELPER METHODS251# ---------------252def get_event_source_arn(stream_name):253 kinesis = aws_stack.connect_to_service('kinesis')254 return kinesis.describe_stream(StreamName=stream_name)['StreamDescription']['StreamARN']255def get_lambda_invocations_count(lambda_name, metric=None):256 return get_lambda_metrics(lambda_name, metric)['Datapoints'][-1]['Sum']257def get_lambda_metrics(func_name, metric=None):258 metric = metric or 'Invocations'259 cloudwatch = aws_stack.connect_to_service('cloudwatch')260 return cloudwatch.get_metric_statistics(261 Namespace='AWS/Lambda',262 MetricName=metric,263 Dimensions=[{'Name': 'FunctionName', 'Value': func_name}],264 Period=60,265 StartTime=datetime.now() - timedelta(minutes=1),266 EndTime=datetime.now(),267 Statistics=['Sum']...

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