Serverless deployment and invoking

Deploying services individually

To deploy individual services head to the root of the service (for example, for integrations, backend/src/serverless/integrations) and run npm run sls-deploy.

By default, it will be deployed to a stage staging. You can deploy to production by running npm run sls-deploy-prod.

๐Ÿ“˜

Why npm run sls-deploy instead of serverless deploy?

The reason why you need to run npm run sls-deploy instead of the standard Serverless commands is the management of environment files.

Serverless currently does not support environment variables in any location that is not the root of the service, therefore, the script behind npm run sls-deploy copies the relevant environment file to the serverless directory, and then deletes it.

This solution is not ideal and is only temporary.

Running functions individually

You can run any function defined in the serverless.yml file individually. This is particularly helpful during development.

Invoking serverless functions locally

Containers run in their own network, and donโ€™t know about the host machine. That is why serverless functions should be invoked from one of the containers, but not from host. (we canโ€™t use network mode: host because this mode is only supported on linux docker engine)

Since serverless deployer containers and node backend use the same backend container, we can execute an interactive bash in any of them to invoke serverless functions.

First, check the running containers using

docker ps
38183818

Get the id of the main backend container. In the example above it is e4aead827763

Now run an interactive bash on the container with this id

docker exec -it e4aead827763 /bin/bash

Cd into desired serverless stack. Letโ€™s say that we want to invoke check_merge coordinator

cd src/serverless/microservices/python/serverless
npm run invoke-local -- --function coordinator --data '{"service": "check_merge"}'

Invoking serverless functions in the cloud

npm run invoke -- --function {functionName} --stage {prod | staging} --args

You can find a list of args here.


Did this page help you?