Using serverless infra for different AWS Lambda operations
Using serverless you easily create, deploy and test serverless services. Useful docs:
- serverless with AWS
- serverless plugins
- You are running with an administrator AWS account
- Run:
yarn global add serverless
- to install theserverless
cli in your/usr/local/bin
. Use it also with thesls
alias. - FYI: Each directory here is a "service" with a deploy of its own. Useless to say you need to run
yarn install
for every dir withpackage.json
.
- Create new serverless template service:
serverless create --template aws-nodejs --path "my-service"
(See other templates) cd my-service
- To test your function locally no need to deploy it:
serverless invoke local --function my_function --log
. - If this function is an HTTP route which recieves route params- can send them with adding
--data '{ "pathParameters": {"route_param_name": "param_value"}}'
. - If you have
require
in your function, make sure to do locallyyarn add
for it to get a localnode_modules
otherwise you'll haveMODULE_NOT_FOUND
error.
This is the default. Use serverless deploy -v
serverless deploy --stage prod
- It's not mandatory to use serverless.com dashboard and give them any access to your project. If you don't want it than Ignore from the warning
WARNING: Missing "tenant" and "app" properties in serverless.yml.
. If you do than open there and complete here yourapp: my-serverless
,tenant: my-tenant
. - To prevent uploading unneeded directories such as
node_modules
, add it to youryml
withpackage... exclude...
- When making changes only to a specific function it'll be much faster to use
serverless deploy function --function my_function
(replaces only the function and not recreating the whole stack) - To debug a function after it was deployed use:
serverless invoke --function my_function --log
.
Background docs: See this basic guide and this advanced guide
- Prerequisit: Add manually to your
serverless.yml
:plugins: [serverless-domain-manager]
. Do not run theserverless plugin install
because it uses npm, and I install it with yarn by thepackage.json
found here. - As written in the docs, after configuring the domain in the
serverless.yml
, you need to run one timesls create_domain --stage prod
(for every stage env). Then deploy.
Fork, implement, add tests, pull request, get my everlasting thanks and a respectable place here :)
Copyright (c) 2019 Regev Golan. See LICENSE for further details.