Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ jobs:
fi

- name: Start LocalStack
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
pip install localstack awscli-local[ver1]
docker pull localstack/localstack
localstack start -d
pip install localstack
docker pull localstack/localstack-pro
localstack auth set-token $LOCALSTACK_AUTH_TOKEN
localstack start -d
localstack wait -t 30

- name: Run Lint and Test
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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:
* LocalStack
* LocalStack Pro (requires `LOCALSTACK_AUTH_TOKEN` environment variable)

## Installation

Expand Down Expand Up @@ -56,6 +56,7 @@ custom:
# Enable this flag to run "docker ..." commands as sudo
sudo: False
compose_file: /home/localstack_compose.yml # optional to use docker compose instead of docker or localstack cli
image: localstack/localstack-pro # Docker image to use
stages:
local:
...
Expand All @@ -64,6 +65,7 @@ custom:
### Configuration via environment variables

The following environment variables can be configured (taking precedence over the values in `serverless.yml`):
* `LOCALSTACK_AUTH_TOKEN`: **Required.** Your LocalStack auth token for LocalStack Pro. Obtain one from [LocalStack](https://app.localstack.cloud/).
* `AWS_ENDPOINT_URL`: LocalStack endpoint URL to connect to (default: `http://localhost:4566`). This is the recommended configuration, and replaces the deprecated config options (`EDGE_PORT`/`LOCALSTACK_HOSTNAME`/`USE_SSL`) below.
* `EDGE_PORT`: LocalStack edge port to connect to (deprecated; default: `4566`)
* `LOCALSTACK_HOSTNAME`: LocalStack host name to connect to (deprecated; default: `localhost`)
Expand Down Expand Up @@ -208,6 +210,7 @@ custom:
```

## Change Log
* v1.4.0: Use LocalStack Pro image (`localstack/localstack-pro`) by default, require `LOCALSTACK_AUTH_TOKEN`. Addition of `image` config var
* v1.3.1: prevent the mounting of code if the Lambda uses an ECR Image
* v1.3.0: add support for built-in Esbuild in Serverless Framework v4 #267
* v1.2.1: Fix custom-resource bucket compatibility with serverless >3.39.0, continue improving support for `AWS_ENDPOINT_URL`
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ version: "3.8"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/localstack
image: localstack/localstack-pro
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?LOCALSTACK_AUTH_TOKEN must be set}
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-localstack",
"version": "1.3.1",
"version": "1.4.0",
"description": "Connect Serverless to LocalStack!",
"main": "src/index.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const TYPESCRIPT_PLUGIN_BUILD_DIR_BUILTIN_ESBUILD = '.serverless/build'; //TODO
// Default AWS endpoint URL
const DEFAULT_AWS_ENDPOINT_URL = 'http://localhost:4566';

// Default LocalStack Image
const LOCALSTACK_PRO_IMAGE = 'localstack/localstack-pro';

// Cache hostname to avoid unnecessary connection checks
let resolvedHostname = undefined;

Expand Down Expand Up @@ -425,6 +428,10 @@ class LocalstackPlugin {
shouldRunDockerSudo() {
return (this.config.docker || {}).sudo;
}

getLocalstackImage(){
return (this.config.image || process.env.IMAGE_NAME || LOCALSTACK_PRO_IMAGE);
}

getStageVariable() {
const customConfig = this.serverless.service.custom || {};
Expand Down Expand Up @@ -531,10 +538,17 @@ class LocalstackPlugin {
env.LAMBDA_REMOTE_DOCKER = env.LAMBDA_REMOTE_DOCKER || '0';
env.DOCKER_FLAGS = (env.DOCKER_FLAGS || '') + ` -v ${cwd}:${cwd}`;
env.START_WEB = env.START_WEB || '0';
if (!env.LOCALSTACK_AUTH_TOKEN) {
this.log('Warning: LOCALSTACK_AUTH_TOKEN is not set. LocalStack Pro requires an auth token.');
}
const maxBuffer = +env.EXEC_MAXBUFFER || 50 * 1000 * 1000; // 50mb buffer to handle output
if (this.shouldRunDockerSudo()) {
env.DOCKER_CMD = 'sudo docker';
}


env.IMAGE_NAME = this.getLocalstackImage();

const options = { env: env, maxBuffer };
return exec('localstack start -d', options)
.then(getContainer)
Expand Down