How to use do_list_functions method in localstack

Best Python code snippet using localstack_python

34072_lambda_api.py

Source:34072_lambda_api.py Github

copy

Full Screen

...424 if not is_zip and not is_jar:425 raise Exception('Uploaded Lambda code is neither a ZIP nor JAR file.')426 add_function_mapping(lambda_name, lambda_handler, lambda_cwd)427 return {'FunctionName': lambda_name}428def do_list_functions():429 funcs = []430 for f_arn, func in iteritems(arn_to_lambda):431 func_name = f_arn.split(':function:')[-1]432 arn = func_arn(func_name)433 funcs.append({434 'Version': '$LATEST',435 'CodeSize': arn_to_lambda.get(arn).get_version('$LATEST').get('CodeSize'),436 'FunctionName': func_name,437 'FunctionArn': f_arn,438 'Handler': arn_to_lambda.get(arn).handler,439 'Runtime': arn_to_lambda.get(arn).runtime,440 'Timeout': LAMBDA_DEFAULT_TIMEOUT,441 # 'Description': ''442 # 'MemorySize': 192,443 })444 return funcs445@app.route('%s/functions' % PATH_ROOT, methods=['POST'])446def create_function():447 """ Create new function448 ---449 operationId: 'createFunction'450 parameters:451 - name: 'request'452 in: body453 """454 arn = 'n/a'455 try:456 data = json.loads(to_str(request.data))457 lambda_name = data['FunctionName']458 event_publisher.fire_event(event_publisher.EVENT_LAMBDA_CREATE_FUNC,459 payload={'n': event_publisher.get_hash(lambda_name)})460 arn = func_arn(lambda_name)461 if arn in arn_to_lambda:462 return error_response('Function already exist: %s' %463 lambda_name, 409, error_type='ResourceConflictException')464 arn_to_lambda[arn] = LambdaFunction(arn)465 arn_to_lambda[arn].versions = {'$LATEST': {'CodeSize': 50}}466 arn_to_lambda[arn].handler = data['Handler']467 arn_to_lambda[arn].runtime = data['Runtime']468 arn_to_lambda[arn].envvars = data.get('Environment', {}).get('Variables', {})469 result = set_function_code(data['Code'], lambda_name)470 if isinstance(result, Response):471 del arn_to_lambda[arn]472 return result473 result.update({474 'DeadLetterConfig': data.get('DeadLetterConfig'),475 'Description': data.get('Description'),476 'Environment': {'Error': {}, 'Variables': arn_to_lambda[arn].envvars},477 'FunctionArn': arn,478 'FunctionName': lambda_name,479 'Handler': arn_to_lambda[arn].handler,480 'MemorySize': data.get('MemorySize'),481 'Role': data.get('Role'),482 'Runtime': arn_to_lambda[arn].runtime,483 'Timeout': data.get('Timeout'),484 'TracingConfig': {},485 'VpcConfig': {'SecurityGroupIds': [None], 'SubnetIds': [None], 'VpcId': None}486 })487 return jsonify(result or {})488 except Exception as e:489 del arn_to_lambda[arn]490 return error_response('Unknown error: %s' % e)491@app.route('%s/functions/<function>' % PATH_ROOT, methods=['GET'])492def get_function(function):493 """ Get details for a single function494 ---495 operationId: 'getFunction'496 parameters:497 - name: 'request'498 in: body499 - name: 'function'500 in: path501 """502 funcs = do_list_functions()503 for func in funcs:504 if func['FunctionName'] == function:505 result = {506 'Configuration': func,507 'Code': {508 'Location': '%s/code' % request.url509 }510 }511 return jsonify(result)512 result = {513 'ResponseMetadata': {514 'HTTPStatusCode': 404515 }516 }517 return make_response((jsonify(result), 404, {}))518@app.route('%s/functions/' % PATH_ROOT, methods=['GET'])519def list_functions():520 """ List functions521 ---522 operationId: 'listFunctions'523 parameters:524 - name: 'request'525 in: body526 """527 funcs = do_list_functions()528 result = {}529 result['Functions'] = funcs530 return jsonify(result)531@app.route('%s/functions/<function>' % PATH_ROOT, methods=['DELETE'])532def delete_function(function):533 """ Delete an existing function534 ---535 operationId: 'deleteFunction'536 parameters:537 - name: 'request'538 in: body539 """540 arn = func_arn(function)541 try:...

Full Screen

Full Screen

lambda_api.py

Source:lambda_api.py Github

copy

Full Screen

...415 if not is_zip and not is_jar:416 raise Exception('Uploaded Lambda code is neither a ZIP nor JAR file.')417 add_function_mapping(lambda_name, lambda_handler, lambda_cwd)418 return {'FunctionName': lambda_name}419def do_list_functions():420 funcs = []421 for f_arn, func in iteritems(arn_to_lambda):422 func_name = f_arn.split(':function:')[-1]423 arn = func_arn(func_name)424 funcs.append({425 'Version': '$LATEST',426 'CodeSize': arn_to_lambda.get(arn).get_version('$LATEST').get('CodeSize'),427 'FunctionName': func_name,428 'FunctionArn': f_arn,429 'Handler': arn_to_lambda.get(arn).handler,430 'Runtime': arn_to_lambda.get(arn).runtime,431 'Timeout': LAMBDA_DEFAULT_TIMEOUT,432 # 'Description': ''433 # 'MemorySize': 192,434 })435 return funcs436@app.route('%s/functions' % PATH_ROOT, methods=['POST'])437def create_function():438 """ Create new function439 ---440 operationId: 'createFunction'441 parameters:442 - name: 'request'443 in: body444 """445 arn = 'n/a'446 try:447 data = json.loads(to_str(request.data))448 lambda_name = data['FunctionName']449 event_publisher.fire_event(event_publisher.EVENT_LAMBDA_CREATE_FUNC,450 payload={'n': event_publisher.get_hash(lambda_name)})451 arn = func_arn(lambda_name)452 if arn in arn_to_lambda:453 return error_response('Function already exist: %s' %454 lambda_name, 409, error_type='ResourceConflictException')455 arn_to_lambda[arn] = LambdaFunction(arn)456 arn_to_lambda[arn].versions = {'$LATEST': {'CodeSize': 50}}457 arn_to_lambda[arn].handler = data['Handler']458 arn_to_lambda[arn].runtime = data['Runtime']459 arn_to_lambda[arn].envvars = data.get('Environment', {}).get('Variables', {})460 result = set_function_code(data['Code'], lambda_name)461 if isinstance(result, Response):462 del arn_to_lambda[arn]463 return result464 result.update({465 "DeadLetterConfig": data.get('DeadLetterConfig'),466 "Description": data.get('Description'),467 "Environment": {"Error": {}, "Variables": arn_to_lambda[arn].envvars},468 "FunctionArn": arn,469 "FunctionName": lambda_name,470 "Handler": arn_to_lambda[arn].handler,471 "MemorySize": data.get('MemorySize'),472 "Role": data.get('Role'),473 "Runtime": arn_to_lambda[arn].runtime,474 "Timeout": data.get('Timeout'),475 "TracingConfig": {},476 "VpcConfig": {"SecurityGroupIds": [None], "SubnetIds": [None], "VpcId": None}477 })478 return jsonify(result or {})479 except Exception as e:480 del arn_to_lambda[arn]481 return error_response('Unknown error: %s' % e)482@app.route('%s/functions/<function>' % PATH_ROOT, methods=['GET'])483def get_function(function):484 """ Get details for a single function485 ---486 operationId: 'getFunction'487 parameters:488 - name: 'request'489 in: body490 - name: 'function'491 in: path492 """493 funcs = do_list_functions()494 for func in funcs:495 if func['FunctionName'] == function:496 result = {497 'Configuration': func,498 'Code': {499 'Location': '%s/code' % request.url500 }501 }502 return jsonify(result)503 result = {504 'ResponseMetadata': {505 'HTTPStatusCode': 404506 }507 }508 return make_response((jsonify(result), 404, {}))509@app.route('%s/functions/' % PATH_ROOT, methods=['GET'])510def list_functions():511 """ List functions512 ---513 operationId: 'listFunctions'514 parameters:515 - name: 'request'516 in: body517 """518 funcs = do_list_functions()519 result = {}520 result['Functions'] = funcs521 return jsonify(result)522@app.route('%s/functions/<function>' % PATH_ROOT, methods=['DELETE'])523def delete_function(function):524 """ Delete an existing function525 ---526 operationId: 'deleteFunction'527 parameters:528 - name: 'request'529 in: body530 """531 arn = func_arn(function)532 try:...

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