Serverless Plugin to support running against Localstack.
This plugin allows Serverless applications to be deployed and tested on your local machine. Any requests to AWS to be redirected to a running LocalStack instance.
Pre-requisites:
The easiest way to get started is to install via npm.
npm install -g serverless
npm install --save-dev serverless-localstack
There are two ways to configure the plugin, via a JSON file or via serverless.yml
.There are two supported methods for configuring the endpoints, globally via thehost
property, or individually. These properties may be mixed, allowing forglobal override support while also override specific endpoints.
A host
or individual endpoints must be configured or this plugin will be deactivated.
Please refer to the example configuration template below. (Please note that most configurationsin the sample are optional and need not be specified.)
service: myService
plugins:
- serverless-localstack
custom:
localstack:
stages:
# list of stages for which the plugin should be enabled
- local
host: http://localhost # optional - LocalStack host to connect to
edgePort: 4566 # optional - LocalStack edge port to connect to
autostart: true # optional - Start LocalStack in Docker on Serverless deploy
networks: #optional - attaches the list of networks to the localstack docker container after startup
- host
- overlay
- my_custom_network
lambda:
# Enable this flag to improve performance
mountCode: True
docker:
# Enable this flag to run "docker ..." commands as sudo
sudo: False
stages:
local:
...
Note the stages
attribute in the config above. The serverless-localstack
plugin gets activated if either:
stages
config; or--stage
flag (default stage "dev") and no stages
config is providedNote that the localstack.lambda.mountCode
flag above will mount the local directoryinto the Docker container that runs the Lambda code in LocalStack. If you remove thisflag, your Lambda code is deployed in the traditional way which is more in line withhow things work in AWS, but also comes with a performance penalty: packaging the code,uploading it to the local S3 service, downloading it in the local Lambda API, extractingit, and finally copying/mounting it into a Docker container to run the Lambda. Mounting codefrom multiple projects is not supported with simple configuration, and you must use theautostart
feature, as your code will be mounted in docker at start up. If you do need tomount code from multiple serverless projects, manually launchlocalstack with volumes specified. For example:
localstack start --docker -d \
-v /path/to/project-a:/path/to/project-a \
-v /path/to/project-b:/path/to/project-b
If you use either serverless-webpack
or serverless-plugin-typescript
, serverless-localstack
will detect it and modify the mount paths to point to your output directory. You will need to invokethe build command in order for the mounted code to be updated. (eg: serverless webpack
). There is no--watch
support for this out of the box, but could be accomplished using nodemon:
npm i --save-dev nodemon
package.json
:
"scripts": {
"build": "serverless webpack --stage local",
"deploy": "serverless deploy --stage local",
"watch": "nodemon -w src -e '.*' -x 'npm run build'",
"start": "npm run deploy && npm run watch"
},
npm run start
serverless-webpack
is supported, with code mounting. However, there are some assumptionsand configuration requirements. First, your output directory must be .webpack
. Second, you must retainyour output directory contents. You can do this by modifying the custom > webpack
portion of yourserverless configuration file.
custom:
webpack:
webpackConfig: webpack.config.js
includeModules: true
keepOutputDirectory: true
localstack:
stages:
- local
lambda:
mountCode: true
autostart: true
LAMBDA_MOUNT_CWD
: Allow users to define a custom working directory for Lambda mounts.For example, when deploying a Serverless app in a Linux VM (that runs Docker) on aWindows host where the -v <local_dir>:<cont_dir>
flag to docker run
requires usto specify a local_dir
relative to the Windows host file system that is mountedinto the VM (e.g., "c:/users/guest/..."
).LAMBDA_EXECUTOR
: Executor type to use for running Lambda functions (default docker
) -see LocalStack repoLAMBDA_REMOTE_DOCKER
: Whether to assume that we're running Lambda containers againsta remote Docker daemon (default false
) - see LocalStack reposerverless deploy --stage local
would deploy to LocalStack.serverless deploy --stage production
would deploy to aws.service: myService
plugins:
- serverless-localstack
custom:
localstack:
stages:
- local
- dev
endpointFile: path/to/file.json
For full documentation, please refer to https://github.com/localstack/localstack
Setting up a development environment is easy using Serverless' plugin framework.
git clone https://github.com/localstack/serverless-localstack
cd /path/to/serverless-localstack
npm link
cd myproject
npm link serverless-localstack
An optional debug flag is supported via serverless.yml
that will enable additional debug logs.
custom:
localstack:
debug: true
serverless-plugin-typescript
when mountCode
is enabledLAMBDA_EXECUTOR
/LAMBDA_REMOTE_DOCKER
configurations from environment$START_WEB
mountCode:false
LAMBDA_MOUNT_CWD
configuration for customizing Lambda mount dir云原生应用开发 回顾过去二十年,应用开发有以下几个显著的特点: 以应用服务器为中心,典型应用服务器包括 tomcat,JBoss,WebLogic,WebSphere,应用服务器提供了丰富的技术堆栈和系统构建范式,对应用开发人员友好 JavaEE/Spring,JavaEE/Spring 是应用开发的基本技能,这项技能有广泛的开发者基础,过去二十年中 JavaEE/Spring 的技术发展/版本的
The Serverless Framework (无服务器架构)允许你自动扩展、按执行付费、将事件驱动的功能部署到任何云。 目前支持 AWS Lambda、Apache OpenWhisk、Microsoft Azure,并且正在扩展以支持其他云提供商。 Serverless 降低了维护应用程序的总成本,能够更快地构建更多逻辑。它是一个命令行工具,提供脚手架、工作流自动化和开发部署无服务器架构的最佳实践。它也可以通过插件完全扩展。
Serverless Prisma [Archived] — New projects should consider using Prisma2 Minimal Serverless + Prisma Project Template Getting Started Be sure to have Docker and Make installed on your machine. Docker
Serverless Webpack A Serverless v1.x & v2.x plugin to build your lambda functions with Webpack. This plugin is for you if you want to use the latest Javascript version with Babel;use custom resource l
serverless-bundle serverless-bundle is a Serverless Framework plugin that optimally packages your ES6 or TypeScript Node.js Lambda functions with sensible defaults so you don't have to maintain your o
Serverless Express by Vendia Run REST APIs and other web applications using your existing Node.js application framework (Express, Koa, Hapi, Sails, etc.), on top of AWS Lambda and Amazon API Gateway.