Skip to content
Merged
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is a plugin for the [Serverless Framework](https://serverless.com/). It us

## Requirements

- serverless >= v2.32.0
- The [serverless-offline](https://www.npmjs.com/package/serverless-offline) plugin
- The [serverless-offline-lambda](https://www.npmjs.com/package/serverless-offline-lambda) plugin
- The [serverless-step-functions](https://www.npmjs.com/package/serverless-step-functions) plugin
Expand Down Expand Up @@ -35,7 +36,6 @@ custom:
stepFunctionsLocal:
accountId: 101010101010
region: us-east-1
# location: './' optional field for where to find serverless.yml - primarily used for typescript
```

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`.
Expand Down Expand Up @@ -83,6 +83,7 @@ custom:
eventBridgeEvents:
enabled: true
endpoint: http://localhost:4010
sqsUrl: http://localhost:4566/101010101010/example-queue

functions:
hello:
Expand All @@ -98,6 +99,13 @@ stepFunctions:
FirstState:
Type: Task
Resource: Fn::GetAtt: [hello, Arn]
Next: send_message
send_message:
Type: Task
Resource: arn:aws:states:::sqs:sendMessage
Parameters:
QueueUrl: ${self:custom.sqsUrl}
"MessageBody.$": "$"
Next: wait_using_seconds
wait_using_seconds:
Type: Wait
Expand Down
43 changes: 1 addition & 42 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,7 @@ class ServerlessStepFunctionsLocal {
}

async getStepFunctionsFromConfig() {
const fromYamlFile = (serverlessYmlPath) =>
this.serverless.yamlParser.parse(serverlessYmlPath);

let parsed = {};
let parser = null;

if (!this.serverless.service.stepFunctions) {
let { servicePath } = this.serverless.config;

if (!servicePath) {
throw new Error('service path not found');
}
const serviceFileName =
this.options.config ||
this.serverless.config.serverless.service.serviceFilename ||
'serverless.yml';
if (this.serverless.service.custom &&
this.serverless.service.custom.stepFunctionsLocal &&
this.serverless.service.custom.stepFunctionsLocal.location) {
servicePath = this.serverless.service.custom.stepFunctionsLocal.location
}
const configPath = path.join(servicePath, serviceFileName);
if (['.js', '.json', '.ts'].includes(path.extname(configPath))) {
parser = this.loadFromRequiredFile;
} else {
parser = fromYamlFile;
}
parsed = await parser(configPath);
} else {
parsed = this.serverless.service;
}

const parsed = this.serverless.configurationInput;
this.stateMachines = parsed.stepFunctions.stateMachines;

if (parsed.custom &&
Expand All @@ -126,16 +95,6 @@ class ServerlessStepFunctionsLocal {
}
}

// This function must be ignored since mocking the require system is more
// dangerous than beneficial
loadFromRequiredFile(serverlessYmlPath) {
/* istanbul ignore next */
// eslint-disable-next-line global-require, import/no-dynamic-require
const fileContents = require(serverlessYmlPath);
/* istanbul ignore next */
return Promise.resolve(fileContents);
}

/**
* Replaces Resource properties with values mapped in TaskResourceMapping
*/
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-step-functions-local",
"version": "0.1.9",
"version": "0.2.0",
"description": "Run AWS step functions offline with Serverless",
"main": "index.js",
"scripts": {
Expand All @@ -14,6 +14,9 @@
"stepfunctions-localhost": "^0.2.0",
"tcp-port-used": "^1.0.1"
},
"peerDependencies": {
"serverless": "^2.32.0"
},
"xo": {
"space": true
},
Expand Down