Skip to content

Instantly share code, notes, and snippets.

@cfbarbero
Created February 25, 2019 19:53
Show Gist options
  • Save cfbarbero/ec14ef77e5a15f67132f03fdff8c8d2d to your computer and use it in GitHub Desktop.
Save cfbarbero/ec14ef77e5a15f67132f03fdff8c8d2d to your computer and use it in GitHub Desktop.
Python data structure for handling reuse of resources across aws lambda invocations.
import uuid
from .some_object import SomeObject
class some_lambda:
def __init__(self):
self.instance_id = uuid.uuid4()
self.someobject = SomeObject()
def handle(self, event, context):
self.someobject.somemethod()
INSTANCE = None
def handler(event, context):
global INSTANCE
if not INSTANCE:
INSTANCE = some_lambda()
INSTANCE.handle(event, context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment