First, install Serverless:
npm install -g serverless
and follow the instructions for setting your AWS credentials.
Then, install this command in your Sails app:
npm install sails-run-deploy-serverless
and invoke using
sails run deploy-serverless <options>.
The available options (you must choose one and only one) are:
--all: deploy (or redeploy) all functions. You may need to do this when first adding a new endoint, or modifying the URL of an existing one.
--f <function name>: deploy only the function with the specified name. Function names are the camel-cased version of the action name in Sails; for example, the action in
api/controllers/user/get.jscorresponds to a function named
--nodeploy: just generate the
serverlessfolder, but don't actually deploy. You can then go into the folder and deploy yourself with the Serverless CLI.
Note that every time you run the command, the local
serverless folder is recreated.
TODO: document route authorization
TODO: document CORS
This file allows you to declare which parts of your Sails app should be copied into the package that is deployed to AWS. Available settings are:
include: An array of file or folder paths (relative to the project root) to copy into the deployment package. Defaults to
['api/controllers', 'api/helpers', 'api/models', 'config/models.js', 'config/datastores.js'].
transpile: An array of file or folder paths (relative to the project root) to transpile to ES5 before deploying. At this time, Lambda only supports Node 6. Defaults to
['api/controllers', 'api/helpers', 'api/models'].
defaultAuthorizer: The name of an authorizer function to use as the default for any route that doesn't explicitly set an
authorizer option. If left unset, routes will not be authorized by default.
orm: Set to
false if you don't want the deployed Lambda functions to use the Waterline ORM.
This command creates a
serverless.yml file with some sane defaults. If you create a
config/serverless.yml file in your app, it will be used as the basis for the YML file that the
deploy-serverless command creates. This is useful for setting up environment variables, VPCs, AWS Gateway Responses, etc.