Skip to content

Commit 13963e6

Browse files
committed
enable config via environment variables
1 parent dbc4e92 commit 13963e6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ The easiest way to get started is to install via npm.
1818

1919
## Configuring
2020

21-
There are two ways to configure the plugin, via a JSON file or via `serverless.yml`.
21+
The plugin can be configured via `serverless.yml`, or alternatively via environment variables.
22+
2223
There are two supported methods for configuring the endpoints, globally via the
2324
`host` property, or individually. These properties may be mixed, allowing for
2425
global override support while also override specific endpoints.
2526

26-
A `host` or individual endpoints must be configured or this plugin will be deactivated.
27+
A `host` or individual endpoints must be configured, or this plugin will be deactivated.
2728

2829
### Configuration via serverless.yml
2930

@@ -59,6 +60,12 @@ custom:
5960
...
6061
```
6162

63+
### Configuration via environment variables
64+
65+
The following environment variables can be configured (taking precedence over the values in `serverless.yml`):
66+
* `EDGE_PORT`: LocalStack edge port to connect to (default: `4566`)
67+
* `LOCALSTACK_HOSTNAME`: LocalStack host name to connect to (default: `localhost`)
68+
6269
### Activating the plugin for certain stages
6370

6471
Note the `stages` attribute in the config above. The `serverless-localstack` plugin gets activated if either:
@@ -198,6 +205,7 @@ custom:
198205
199206
## Change Log
200207
208+
* v1.0.1: Add support for Serverless projects with esbuild source config; enable config via environment variables
201209
* v1.0.0: Allow specifying path for mountCode, to point to a relative Lambda mount path
202210
* v0.4.36: Add patch to avoid "TypeError" in AwsDeploy plugin on Serverless v3.4.0+
203211
* v0.4.35: Add config option to connect to additional Docker networks

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-localstack",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Connect Serverless to LocalStack!",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ class LocalstackPlugin {
536536
reconfigureAWS() {
537537
if(this.isActive()) {
538538
this.log('Using serverless-localstack');
539-
const host = this.config.host || 'http://localhost';
539+
const hostname = process.env.LOCALSTACK_HOSTNAME || 'localhost';
540+
const host = this.config.host || `http://${hostname}`;
540541
const edgePort = this.getEdgePort();
541542
const configChanges = {};
542543

@@ -645,7 +646,7 @@ class LocalstackPlugin {
645646
/** Utility functions below **/
646647

647648
getEdgePort() {
648-
return this.config.edgePort || DEFAULT_EDGE_PORT;
649+
return process.env.EDGE_PORT || this.config.edgePort || DEFAULT_EDGE_PORT;
649650
}
650651

651652
getAwsProvider() {

0 commit comments

Comments
 (0)