Search code examples
amazon-web-servicesyamlserverless-frameworkaws-step-functionsserverless-plugins

Deploy AWS state machine stage specific


I am new to serverless framework. I want to deploy my state machine for dev env only not for other env. How can I deploy it stage-specific?. I have tried serverless-plugin-ifelse for deployment but it is not working in the case of state machines. My serverless.yml looks like

serverlessIfElse:
    - If: '"${self:custom.currentStage}" == "beta"'
      Exclude:
        - stepFunctions.stateMachines
 stepFunctions:
  stateMachines:
    pruneIndices:
      ${file(./handlers/prune-indexes/prune-indexes.yml)}

Solution

  • If you can provide a name for your state machine, add the stage you are deploying to as a part of that state machine name. I usually name my resources with multiple variables to namespace them better, so for example you could use:

    ${self:service}-myStateMachineName-${opt:stage, 'dev'}

    In this way your statemachine will always be unique per service even if you re-use it on the same account and if you pass a stage during deployment such as serverless deploy --stage mystage it will be unique or default dev if a stage is not specified.