Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of Lightrun sdk containerised in lambda #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sample_aws_container/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to pass num somehow?


1 change: 1 addition & 0 deletions sample_aws_container/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lightrun==1.2.2
21 changes: 21 additions & 0 deletions sample_aws_container/src/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
LIGHTRUN_KEY = 'LIGHTRUN_KEY'
LIGHTRUN_SERVER = 'LIGHTRUN_SERVER_URL'

def import_lightrun():
try:
import lightrun
lightrun.enable(com_lightrun_server=LIGHTRUN_SERVER, company_key=LIGHTRUN_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you miss lightrun_wait_for_init=true that is required for lambdas, this will be released in 1.2.3, next week.
Probably need to change requirements too

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))
return start_fibonacci(num)