serverless-operations / serverless-operations/serverless-step-functions

Bug - scripts added to the serverless.yml are running twice

Open
#422 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug need more info
Dominant language
JavaScript
Stars
1k
Forks
220
PR merge metrics
No merged PRs in 30d

Description

This is a Bug Report

Description

There are 2 issues after plugin version 1.4.0

  1. use of ${self:} throws error
    ServerlessError: Trying to populate non string value into a string for variable ${self:}. Please make sure the value of the property is a string
    using ${self} works

  2. serverless plugin (version 2.29.0) does the variables.populateService on start which runs the scripts from serverless.yml
    link: https://github.com/serverless/serverless/blob/f5b2b9be395c9c2d3de4c4f91f991276bc22dc33/lib/Serverless.js#L296

also the serverless-step-functions plugin (version 2.30.0) tries to populate the variables before setting up step functions
link: https://github.com/serverless-operations/serverless-step-functions/blob/e0a391d531b2868f5b03fd8eeede3d9073735efa/lib/yamlParser.js#L26

because of this scripts are running twice, which is not expected.

this is a link to a PR after which these issues are coming
https://github.com/serverless-operations/serverless-step-functions/pull/116

sharing a sample example to reproduce the issue

service: test-step-function
provider:
  name: aws
  onStart: ${file(./on_start.js):onStart}

frameworkVersion: '2'

stepFunctions:
  stateMachines:
    hellostepfunc1:
      definition:
        StartAt: HelloWorld1
        States:
          HelloWorld1:
            Type: Task
            Next: ToSqsQueue
            Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello-world"
            End: true
          ToSqsQueue:
            Type: Task
            Resource: arn:aws:states:::sqs:sendMessage
            Parameters:
              QueueUrl: https://sqs.#{AWS::Region}.amazonaws.com/#{AWS::AccountId}/hello-world-queue
              MessageBody.$: "$"
              MessageGroupId: "1"
            End: true

plugins:
  - serverless-step-functions

custom:
  servicename: ${self:} # first issue, ${self:} doesn't work after version 1.4.0, works for ${self}, error is ServerlessError: Trying to populate non string value into a string for variable ${self:}. Please make sure the value of the property is a string
  add_resources: ${file(./resources.js)}
  export:
    statics:
      - service: ${self:custom.servicename}

Additional Data

sample project to reproduce the issues:
step_functions_example.zip

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked sample project and reproduce the duplicate script execution. Read the referenced Serverless.js variable-population call and serverless-step-functions/lib/yamlParser.js, then compare when each populates variables. Done means the sample scripts run once and the reported ${self:} behavior is resolved without breaking step-function setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.