From ad74e2ac1dbf9e66e8ff5cd4666116fcd76b5947 Mon Sep 17 00:00:00 2001 From: Anna Remez Date: Wed, 1 Dec 2021 11:43:05 +0200 Subject: [PATCH 1/4] Example of Lightrun sdk containerised in lambda --- sample_aws_container/Dockerfile | 10 ++++++++++ sample_aws_container/requirements.txt | 1 + sample_aws_container/src/sample.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 sample_aws_container/Dockerfile create mode 100644 sample_aws_container/requirements.txt create mode 100644 sample_aws_container/src/sample.py diff --git a/sample_aws_container/Dockerfile b/sample_aws_container/Dockerfile new file mode 100644 index 0000000..987d97c --- /dev/null +++ b/sample_aws_container/Dockerfile @@ -0,0 +1,10 @@ +FROM amazon/aws-lambda-python + +COPY requirements.txt . +COPY src/ . + +RUN pip install --upgrade pip \ + && pip install -r requirements.txt + +CMD ["sample.main"] + diff --git a/sample_aws_container/requirements.txt b/sample_aws_container/requirements.txt new file mode 100644 index 0000000..040746e --- /dev/null +++ b/sample_aws_container/requirements.txt @@ -0,0 +1 @@ +lightrun==1.2.2 \ No newline at end of file diff --git a/sample_aws_container/src/sample.py b/sample_aws_container/src/sample.py new file mode 100644 index 0000000..1ab7f64 --- /dev/null +++ b/sample_aws_container/src/sample.py @@ -0,0 +1,18 @@ +def import_lightrun(): + try: + import lightrun + lightrun.enable(com_lightrun_server='https://app.lightrun.com/company/success', company_key='b33aaabc-2ef0-4bcd-9c09-e3de48ac90fe') + except ImportError as e: + print("Error importing Lightrun: ", e) + +def start_fibonacci(n): + if n in {0, 1}: + return n + return start_fibonacci(n - 1) + start_fibonacci(n - 2) + +def main(event, context): + import_lightrun() + num = event['num'] + + print("Calculating Fibonacci of {}...".format(num)) + start_fibonacci(num) \ No newline at end of file From 0a8f7eba5be5ec97c256a154ad0b44772ae471c9 Mon Sep 17 00:00:00 2001 From: Anna Remez Date: Wed, 1 Dec 2021 13:51:06 +0200 Subject: [PATCH 2/4] some review comments --- sample_aws_container/src/sample.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sample_aws_container/src/sample.py b/sample_aws_container/src/sample.py index 1ab7f64..24fed76 100644 --- a/sample_aws_container/src/sample.py +++ b/sample_aws_container/src/sample.py @@ -1,7 +1,10 @@ +LIGHTRUN_KEY = 'LIGHTRUN_KEY' +LIGHTRUN_SERVER = 'LIGHTRUN_KEY' + def import_lightrun(): try: import lightrun - lightrun.enable(com_lightrun_server='https://app.lightrun.com/company/success', company_key='b33aaabc-2ef0-4bcd-9c09-e3de48ac90fe') + lightrun.enable(com_lightrun_server=LIGHTRUN_SERVER, company_key=LIGHTRUN_KEY) except ImportError as e: print("Error importing Lightrun: ", e) @@ -15,4 +18,4 @@ def main(event, context): num = event['num'] print("Calculating Fibonacci of {}...".format(num)) - start_fibonacci(num) \ No newline at end of file + start_fibonacci(num) From 975ceab4d5a7e024e83c8d61711e6cc6780c155e Mon Sep 17 00:00:00 2001 From: Anna Remez Date: Wed, 1 Dec 2021 14:55:25 +0200 Subject: [PATCH 3/4] typo --- sample_aws_container/src/sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample_aws_container/src/sample.py b/sample_aws_container/src/sample.py index 24fed76..86b4c2e 100644 --- a/sample_aws_container/src/sample.py +++ b/sample_aws_container/src/sample.py @@ -1,5 +1,5 @@ LIGHTRUN_KEY = 'LIGHTRUN_KEY' -LIGHTRUN_SERVER = 'LIGHTRUN_KEY' +LIGHTRUN_SERVER = 'LIGHTRUN_SERVER_URL' def import_lightrun(): try: From 3278c9e56ee30b25e7ec10a70cfc7ea927bd9fb3 Mon Sep 17 00:00:00 2001 From: Anna Remez Date: Wed, 1 Dec 2021 16:40:39 +0200 Subject: [PATCH 4/4] rtrn --- sample_aws_container/src/sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample_aws_container/src/sample.py b/sample_aws_container/src/sample.py index 86b4c2e..f63e8b5 100644 --- a/sample_aws_container/src/sample.py +++ b/sample_aws_container/src/sample.py @@ -18,4 +18,4 @@ def main(event, context): num = event['num'] print("Calculating Fibonacci of {}...".format(num)) - start_fibonacci(num) + return start_fibonacci(num)