How to use call_lambda method in localstack

Best Python code snippet using localstack_python

main.py

Source:main.py Github

copy

Full Screen

...23 'make_bucket' : {24 'bucket_name' : bucket_name,25 }26 }27 call_lambda(payload)28 29 30def del_bucket(b_name):31 """32 Deletes a bucket from s3, Takes in a bucket name33 """34 payload = {35 'task' : 'delete_bucket',36 'aws_region' : AWS_REGION,37 'delete_bucket' : {38 'bucket_name' : b_name,39 }40 }41 call_lambda(payload)42 43 44def del_file(b_name, f_name):45 """46 Deletes a file from s3. Takes in a bucket name and a file name/key47 """48 payload = {49 'task' : 'delete_object',50 'aws_region' : AWS_REGION,51 'delete_object' : {52 'bucket_name' : b_name,53 'key' : f_name54 }55 }56 call_lambda(payload) 57 58 59def upload_file(f_path, bucket, obj_name=None):60 """61 uploads a file to s3. Takes in a file path, bucket name and optionaly a name for62 the object in s363 """64 if obj_name is None: obj_name = os.path.basename(f_path)65 data = ''66 with open(f_path, 'r') as in_file:67 data = in_file.read()68 payload = {69 'task' : 'write_object',70 'aws_region' : AWS_REGION,71 'write_object' : {72 'bucket_name' : bucket,73 'key' : obj_name,74 'write_data' : data75 }76 }77 call_lambda(payload)78 79 80def list_bucket_contents(b_name):81 """82 lists the contents of a bucket taking in a bucket name.83 uses lambda function to preform the action retruns the contents84 of the bucket85 """86 payload = {87 'task' : 'get_objects',88 'aws_region' : AWS_REGION,89 'get_objects' : {90 'bucket_name' : b_name,91 }92 }93 resp = call_lambda(payload)94 return resp95def append_object(b_name, key, data):96 """97 appends data to the end of an object taking in a bucket name, key, and98 data to append. uses lambda function to preform the action99 """100 payload = {101 'task' : 'append_object',102 'aws_region' : AWS_REGION,103 'append_object' : {104 'bucket_name' : b_name,105 'key' : key,106 'write_data' : data107 }108 }109 call_lambda(payload)110 111 112def read_object(b_name, key):113 """114 reads in an object from a bucket taking in a bucket name and key115 uses lambda function to preform the action retruns the contents116 of the object117 """118 payload = {119 'task' : 'read_object',120 'aws_region' : AWS_REGION,121 'read_object' : {122 'bucket_name' : b_name,123 'key' : key124 }125 }126 return call_lambda(payload)127def call_lambda(payload):128 """129 takes in a payload and invokes lambda_crud with that payload,130 and handles the return for use131 """ 132 lmb_crud = boto3.client('lambda', region_name=AWS_REGION, 133 endpoint_url=ENDPOINT_URL)134 payload = json.dumps(payload, indent=3)135 objects = lmb_crud.invoke(FunctionName="lambda_crud",136 InvocationType='RequestResponse',137 Payload=payload)138 data = objects['Payload'].read()139 data = json.loads(data.decode('utf-8'))140 return data 141 ...

Full Screen

Full Screen

interpreter.py

Source:interpreter.py Github

copy

Full Screen

1from parser import Parser, AST_Node2import sys3import time4def call_lambda(var, body, arg):5 if body.node_type == Parser.VAR:6 if body.op1 == var.op1:7 return arg8 else:9 return body10 if body.node_type == Parser.STR or body.node_type == Parser.FORBIDDEN_BLOCK:11 return body12 if body.node_type == Parser.SCOPED_BLOCK:13 return AST_Node(Parser.SCOPED_BLOCK, call_lambda(var, body.op1, arg))14 if body.node_type == Parser.LAMBDA or body.node_type == Parser.SEQ:15 return AST_Node(body.node_type, call_lambda(var, body.op1, arg), call_lambda(var, body.op2, arg))16def eval_arg(ast):17 if ast.node_type == Parser.STR:18 return ast19 if ast.node_type == Parser.SCOPED_BLOCK or ast.node_type == Parser.FORBIDDEN_BLOCK:20 return AST_Node(ast.node_type, eval_arg(ast.op1))21 if ast.node_type == Parser.SEQ:22 if ast.op1.node_type == Parser.LAMBDA:23 return eval_arg(call_lambda(ast.op1.op1, ast.op1.op2, ast.op2))24 elif ast.op1.node_type == Parser.STR:25 return AST_Node(Parser.SEQ, ast.op1, eval_arg(ast.op2))26 return ast27def eval(ast):28 global out_buffer29 if ast.node_type == Parser.STR:30 out_buffer += ast.op131 return32 if ast.node_type == Parser.SCOPED_BLOCK or ast.node_type == Parser.FORBIDDEN_BLOCK:33 return ast.op134 if ast.node_type == Parser.SEQ:35 if ast.op1.node_type == Parser.LAMBDA:36 return call_lambda(ast.op1.op1, ast.op1.op2, eval_arg(ast.op2))37 elif ast.op1.node_type == Parser.STR:38 eval(ast.op1)39 return ast.op240 else:41 return AST_Node(Parser.SEQ, eval(ast.op1), ast.op2)42 if ast.node_type == Parser.VAR or ast.node_type == Parser.LAMBDA:43 raise Exception("Evaluation error. Var or Lambda left")44def str_ast(ast):45 if ast.node_type == Parser.STR:46 return '"' + ast.op1 + '"'47 if ast.node_type == Parser.VAR:48 return ast.op149 if ast.node_type == Parser.LAMBDA:50 return '{' + str_ast(ast.op1) + ' ' + str_ast(ast.op2) + '}'...

Full Screen

Full Screen

serial_run.py

Source:serial_run.py Github

copy

Full Screen

...22 mq.close()23 call(["rm", "-f", "/dev/mqueue/mytest"])24 except:25 pass26def call_lambda(lam, log, num_keys, depth, value_len):27 delete_queue()28 call(["./bin/admin", "workers", "-cluster=bench_resp", "-p=8081"])29 call(["./bin/admin", "workers", "-cluster=bench_call"])30 sleep(1)31 args = "{\"num_keys\" : \"" + str(num_keys) + "\", \"depth\" : \"" + str(depth) + "\", \"value_len\" : \"" + str(value_len) + "\" }"32 Popen(["curl", "-X", "POST", "localhost:8081/runLambda/" + lam + "_resp", "-d", args])33 sleep(1)34 call(["curl", "-X", "POST", "localhost:8080/runLambda/" + lam + "_call", "-d", args], stdout=log)35 call(["./clean_bench.sh"])36def t1():37 for b in benches:38 f = open("serial_results/" + b + ".t1.log", "a")39 for s in sizes:40 # Test 1: vary value_len41 call_lambda(b, f, 1, 1, s)42 f.write("\n")43 f.flush()44 f.close()45def t2():46 for b in benches:47 g = open("serial_results/" + b + ".t2.log", "a")48 for s in sizes:49 # Test 2: vary num_keys with 1B values50 call_lambda(b, g, s, 1, 1)51 g.write("\n")52 g.flush()53 g.close()54def t3():55 depths = map(lambda x: 2**x, range(maxdepth+1))56 for b in benches:57 g = open("serial_results/" + b + ".t3.log", "a")58 for d in depths:59 call_lambda(b, g, depthsize/d, d, 1)60 g.write("\n")61 g.flush()62 g.close()63def main():64 #t1()65 #t2()66 t3()67if __name__ == "__main__":...

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