Skip to content

Commit 456bb1d

Browse files
committed
docs: add example for separate files
1 parent 30a8ab5 commit 456bb1d

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,78 @@ plugins:
10201020
- serverless-step-functions
10211021
```
10221022

1023+
### How to split up state machines into files
1024+
1025+
When you have a large serverless project with lots of state machines
1026+
your serverless.yml file can grow to a point where it is unmaintainable.
1027+
1028+
You can split step functions into external files and import them
1029+
into your serverless.yml file.
1030+
1031+
There are two ways you can do this:
1032+
1033+
#### Single external file
1034+
1035+
You can define the entire `stateMachines` block in a separate file
1036+
and import it in its entirety.
1037+
1038+
includes/state-machines.yml:
1039+
1040+
```yml
1041+
stateMachines:
1042+
hellostepfunc1:
1043+
name: myStateMachine1
1044+
definition:
1045+
<your definition>
1046+
hellostepfunc2:
1047+
name: myStateMachine2
1048+
definition:
1049+
<your definition>
1050+
```
1051+
1052+
serverless.yml:
1053+
1054+
```yml
1055+
stepFunctions:
1056+
${file(includes/state-machines.yml)}
1057+
1058+
plugins:
1059+
- serverless-step-functions
1060+
```
1061+
1062+
#### Separate Files
1063+
1064+
You can split up the `stateMachines` block into separate files.
1065+
1066+
includes/state-machine-1.yml:
1067+
1068+
```yml
1069+
name: myStateMachine1
1070+
definition:
1071+
<your definition>
1072+
```
1073+
1074+
includes/state-machine-2.yml:
1075+
1076+
```yml
1077+
name: myStateMachine2
1078+
definition:
1079+
<your definition>
1080+
```
1081+
1082+
serverless.yml:
1083+
1084+
```yml
1085+
stepFunctions:
1086+
hellostepfunc1:
1087+
${file(includes/state-machine-1.yml)}
1088+
hellostepfunc2:
1089+
${file(includes/state-machine-2.yml)}
1090+
1091+
plugins:
1092+
- serverless-step-functions
1093+
```
1094+
10231095
## Sample statemachines setting in serverless.yml
10241096

10251097
### Wait State

0 commit comments

Comments
 (0)