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

Offline function invoke (cross-project) + helper #10

Closed
johncmckim opened this issue Feb 9, 2017 · 6 comments
Closed

Offline function invoke (cross-project) + helper #10

johncmckim opened this issue Feb 9, 2017 · 6 comments
Assignees

Comments

@johncmckim
Copy link
Collaborator

johncmckim commented Feb 9, 2017

Feature Proposal)

Description

When running functions locally, as soon as you access the aws-sdk all subsequent calls are made to the cloud. The SERVERLESS_SIMULATE environment variable as specified in #8 will allow people to avoid this by creating factories that change behaviour when running locally.

For example, if you wanted to use DynamoDB or Memcached you could do the following.

if (process.env.SERVERLESS_SIMULATE) {
   return new AWS.DynamoDB({ endpoint: new AWS.Endpoint('http://localhost:8000') });
}

But there is no simple way of achieving this for Lambda. This is because there is no registry of what functions exist where on a machine.

I suggest we add a sls simulate register command and a register lifecycle event to invoke and serve. The register hook would store the functions + path in a common user file i.e. ~/.serverless-simulate/registry in the format {service:name}-{function:name}.

{
  "user-service-addUser": "/Users/john/project/handler"
}

We can then create a helper that would access the registry and invoke functions across services.

const simulateInvoker = require('serverless-docker/local-invoke')

if (process.env.SERVERLESS_SIMULATE) {
   return simulateInvoker.invoke('user-service-addUser', event);
}

Bonus
Support setting for where the registry lives

custom:
  simulate:
    registryLocation: ./simulate-registry
@johncmckim johncmckim self-assigned this Feb 9, 2017
@nicka
Copy link
Contributor

nicka commented Feb 10, 2017

@johncmckim Love the idea and initial design/goals!

One thing I noticed:

"user-service-addUser": "/Users/john/project/handler"`

What if the file includes more handlers? Might need some handler prefixing.

@johncmckim
Copy link
Collaborator Author

@nicka so the idea is that we'll identify by service name + function name. So the key will be ${serviceName}-${functionName}.

It does assume that this will be unique across an application (group of services). If we can set where the registry lives that should a reasonable assumption as they should be unique in AWS anyway.

@nicka
Copy link
Contributor

nicka commented Feb 10, 2017

@johncmckim Not sure if we're talking about the same thing (or I'm not getting it haha).
I'm talking about multiple handlers within the same Lambda function.

@johncmckim
Copy link
Collaborator Author

Oh sorry @nicka do you mean like /Users/john/project/index.handler. Yea. Need to support that which isn't hard.

I'm going to look at using dynamodb-local for the registry.

@nicka
Copy link
Contributor

nicka commented Feb 11, 2017

@johncmckim perfect!!!

@johncmckim
Copy link
Collaborator Author

I've ended up using lowdb and creating a HTTP endpoint for the registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants