Skip to content

Commit 6717232

Browse files
committed
feat: do not wait for AWS emulator to start
1 parent af4a0c8 commit 6717232

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ It also adds an environment variable for each created state machine that contain
5050
- `lambdaEndpoint` (defaults to `http://localhost:4000`) the endpoint for the lambda service
5151
- `path` (defaults to `./.step-functions-local`) the path to store the downloaded step function executables
5252
- `TaskResourceMapping` allows for Resource ARNs to be configured differently for local development
53-
- `startStepFunctionsLocalApp` (default: true) starts AWS step function emulator. Set to false if it's running already. It needs to run on port 8083.
54-
53+
- `startStepFunctionsLocalApp` (default: `true`) starts AWS step function emulator. Set to false if it's running already. It needs to run on port 8083.
54+
- `waitToStart` (default: `true`) waits on startup until AWS step function emulator is detected on port 8083
55+
- `true` throws an error and stops serverless if emulator is not detected
56+
- `false` emits an error to console and keeps serverless running if emulator is not detected
5557

5658
### Full Config Example
5759

@@ -76,6 +78,7 @@ custom:
7678
FirstState: arn:aws:lambda:us-east-1:101010101010:function:hello
7779
FinalState: arn:aws:lambda:us-east-1:101010101010:function:hello
7880
startStepFunctionsLocalApp: true
81+
waitToStart: true
7982
8083
functions:
8184
hello:

index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ServerlessStepFunctionsLocal {
3434
this.config.startStepFunctionsLocalApp = true
3535
}
3636

37+
if (this.config.waitToStart === undefined) {
38+
this.config.waitToStart = true
39+
}
40+
3741
this.stepfunctionsServer = new StepFunctionsLocal(this.config);
3842

3943
this.stepfunctionsAPI = new AWS.StepFunctions({endpoint: 'http://localhost:8083', region: this.config.region});
@@ -44,9 +48,19 @@ class ServerlessStepFunctionsLocal {
4448
await this.installStepFunctions();
4549
}
4650

47-
await this.startStepFunctions();
48-
await this.getStepFunctionsFromConfig();
49-
await this.createEndpoints();
51+
const bootstrap = (async () => {
52+
await this.startStepFunctions();
53+
await this.getStepFunctionsFromConfig();
54+
await this.createEndpoints();
55+
})()
56+
57+
if(this.config.waitToStart) {
58+
await bootstrap;
59+
} else {
60+
bootstrap.catch(err => {
61+
console.error(chalk.red('[Serverless Step Functions Local]'), 'Could not detect AWS Step Functions emulator running on port 8083.');
62+
})
63+
}
5064
},
5165
'before:offline:start:end': async () => {
5266
if (this.config.startStepFunctionsLocalApp) {

0 commit comments

Comments
 (0)