diff --git a/README.md b/README.md index 5ca85dc..5364b97 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`. @@ -83,6 +83,7 @@ custom: eventBridgeEvents: enabled: true endpoint: http://localhost:4010 + sqsUrl: http://localhost:4566/101010101010/example-queue functions: hello: @@ -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 diff --git a/index.js b/index.js index ecb5019..304aa2c 100644 --- a/index.js +++ b/index.js @@ -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 && @@ -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 */ diff --git a/package-lock.json b/package-lock.json index a1eee83..92bd925 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "serverless-step-functions-local", - "version": "0.1.9", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 413fa43..be7175c 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -14,6 +14,9 @@ "stepfunctions-localhost": "^0.2.0", "tcp-port-used": "^1.0.1" }, + "peerDependencies": { + "serverless": "^2.32.0" + }, "xo": { "space": true },