Skip to content

Conversation

@danielpoonwj
Copy link
Contributor

@danielpoonwj danielpoonwj commented Oct 3, 2021

Purpose

Allow variable resolution in the step functions config, following this approach: serverless-operations/serverless-step-functions#451.

This allows for variables to be properly resolved instead of appearing as strings as-is. Resource variables can currently be replaced through TaskResourceMapping, but other essential fields like QueueUrl for sqs:sendMessage resources need to be supported. Instead of overloading TaskResourceMapping with custom syntax, allow variable resolution to give users full flexibility to configure however they want.

TaskResourceMapping is still handy, but can consider deprecating it in the future since the functionality is now possible through variables, and there'll be one less thing to maintain.

The example below (and in the README) shows how to reference an arbitrary custom variable.

custom:
  ...
  sqsUrl: http://localhost:4566/101010101010/example-queue

stepFunctions:
  stateMachines:
    WaitMachine:
      definition:
        StartAt: send_message
        States:
          send_message:
            Type: Task
            Resource: arn:aws:states:::sqs:sendMessage
            Parameters:
              QueueUrl: ${self:custom.sqsUrl}
              "MessageBody.$": "$"
            End: true

Notes

  • I'm not 100% sure how the resolver works internally but the source PR did away with the changes applied in Adding support for serverless.[ts,json,js] files #2, so I assume it automagically works with non-yaml configs.
  • This is only supported on Serverless v2.32.0 and above, added peer dependency.
  • Since this is a potentially breaking change, bump minor version

@codetheweb
Copy link
Owner

Sounds good to me, thanks.

(You seem to know your way around Serverless / AWS while I haven't used this in a few years, would be happy to transfer ownership to you if you want.)

@codetheweb codetheweb merged commit 94cfd5a into codetheweb:master Oct 3, 2021
@codetheweb
Copy link
Owner

Published in v0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants