|
1 | 1 | # serverless-step-functions-local |
2 | | -Run AWS step functions offline with Serverless |
| 2 | +Run AWS step functions offline with Serverless! |
| 3 | + |
| 4 | +This is a plugin for the [Serverless Framework](https://serverless.com/). It uses [stepfunctions-localhost](https://www.npmjs.com/package/stepfunctions-localhost) to emulate step functions with AWS' provided tool for local development. |
| 5 | + |
| 6 | +## Requirements |
| 7 | + |
| 8 | +- The [serverless-offline](https://www.npmjs.com/package/serverless-offline) plugin |
| 9 | +- The [serverless-offline-lambda](https://www.npmjs.com/package/serverless-offline-lambda) plugin |
| 10 | +- The [serverless-step-functions](https://www.npmjs.com/package/serverless-step-functions) plugin |
| 11 | +- Java Runtime Engine (JRE) version 6.x or newer |
| 12 | + |
| 13 | +## Install |
| 14 | + |
| 15 | +`npm install serverless-step-functions-local -D` |
| 16 | + |
| 17 | +## Getting Started |
| 18 | + |
| 19 | +You'll need to add this plugin to your `serverless.yml`. The plugins section should look something like this when you're done: |
| 20 | + |
| 21 | +```yaml |
| 22 | +plugins: |
| 23 | + ... |
| 24 | + - serverless-step-functions |
| 25 | + - serverless-step-functions-local |
| 26 | + - serverless-offline-lambda |
| 27 | + - serverless-offline |
| 28 | + ... |
| 29 | +``` |
| 30 | + |
| 31 | +Then, add a new section to `config` with `accountId` and `region` parameters: |
| 32 | + |
| 33 | +```yaml |
| 34 | +custom: |
| 35 | + stepFunctionsLocal: |
| 36 | + accountId: 101010101010 |
| 37 | + region: us-east-1 |
| 38 | +``` |
| 39 | +
|
| 40 | +Although not neccessary, it's strongly recomended to add the folder with the downloaded step function executables to `.gitignore`. By default, this path is `./.step-functions-local`. |
| 41 | + |
| 42 | +## Options |
| 43 | + |
| 44 | +(These go under `custom.stepFunctionsLocal`.) |
| 45 | + |
| 46 | +- `accountId` (required) your AWS account ID |
| 47 | +- `region` (required) your AWS region |
| 48 | +- `lambdaEndpoint` (defaults to `http://localhost:4000`) the endpoint for the lambda service |
| 49 | +- `path` (defaults to `./.step-functions-local`) the path to store the downloaded step function executables |
| 50 | + |
| 51 | +### Full Config Example |
| 52 | + |
| 53 | +```yaml |
| 54 | +service: local-step-function |
| 55 | +
|
| 56 | +plugins: |
| 57 | + - serverless-step-functions |
| 58 | + - serverless-step-functions-local |
| 59 | + - serverless-offline-lambda |
| 60 | + - serverless-offline |
| 61 | +
|
| 62 | +provider: |
| 63 | + name: aws |
| 64 | + runtime: nodejs10.x |
| 65 | +
|
| 66 | +
|
| 67 | +custom: |
| 68 | + stepFunctionsLocal: |
| 69 | + accountId: 101010101010 |
| 70 | + region: us-east-1 |
| 71 | +
|
| 72 | +functions: |
| 73 | + hello: |
| 74 | + handler: handler.hello |
| 75 | +
|
| 76 | +stepFunctions: |
| 77 | + stateMachines: |
| 78 | + WaitMachine: |
| 79 | + definition: |
| 80 | + Comment: "An example of the Amazon States Language using wait states" |
| 81 | + StartAt: FirstState |
| 82 | + States: |
| 83 | + FirstState: |
| 84 | + Type: Task |
| 85 | + Resource: arn:aws:lambda:us-east-1:101010101010:function:hello |
| 86 | + Next: wait_using_seconds |
| 87 | + wait_using_seconds: |
| 88 | + Type: Wait |
| 89 | + Seconds: 10 |
| 90 | + Next: FinalState |
| 91 | + FinalState: |
| 92 | + Type: Task |
| 93 | + Resource: arn:aws:lambda:us-east-1:101010101010:function:hello |
| 94 | + End: true |
| 95 | +``` |
0 commit comments