Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: References always converted into strings for Step Functions definition substitutions - Can't use a CF parameter for TimeoutSeconds attribute (Integer) #1616

Closed
alexcasalboni opened this issue Jun 10, 2020 · 11 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... area/step-function stage/pm-review Waiting for review by our Product Manager, please don't work on this yet

Comments

@alexcasalboni
Copy link

Description: when I create a AWS::Serverless::StateMachine resource, I'd like to parametrize the value of my state's TimeoutSeconds attribute using a CloudFormation parameter.

I've defined the parameter as follows:

Parameters: 
  myParameter:
    Type: Number
    Default: 300

and I'm referencing it in my task definition as follows:

myTask:
  Type: Task
  Resource: !GetAtt myfunction.Arn
  End: true
  TimeoutSeconds: !Ref myParameter

Steps to reproduce the issue:

  1. Define a CloudFormation parameter
  2. Define a Step Functions state
  3. Try to reference the parameter in the TimeoutSeconds attribute

Observed result:

The deployment fails with this error message:

Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Expected value of type Integer

Expected result:

I'd expect the deploy to succeed since the parameter type and value are valid.

My understanding is that CloudFormation treats every parameter as a string under the hood, even if you define it as Type: Number. But then how do I get to use this parameter as an Integer, as SAM is expecting? Is this a SAM issue or a Step Functions issue?

@alexcasalboni
Copy link
Author

alexcasalboni commented Jun 10, 2020

Update: I have inspected the changeset to verify how SAM is transforming the state machine definition.

This is the transformed definition (just the snippet corresponding to my task):

"            \"Iterator\": {",
"                \"StartAt\": \"Executor\",",
"                \"States\": {",
"                    \"Executor\": {",
"                        \"End\": true,",
"                        \"Resource\": \"${definition_substitution_2}\",",
"                        \"TimeoutSeconds\": \"${definition_substitution_3}\",",
"                        \"Type\": \"Task\"",
"                    }",
"                }",
"            },",

As you can see, the TimeoutSeconds attribute is being transformed into a string: \"TimeoutSeconds\": \"${definition_substitution_3}\",".

So I think there is something wrong with the SAM transformation, probably somewhere around here: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/model/stepfunctions/generators.py#L254

@alexcasalboni alexcasalboni changed the title Bug: Cannot use a CloudFormation parameter for TimeoutSeconds attribute (Integer) Bug: References always converted into strings for Step Functions definition substitutions - Can't use a CF parameter for TimeoutSeconds attribute (Integer) Jun 10, 2020
@bradduhon
Copy link

Glad this is being addressed already!

I just came over here to also add this is an issue when using Fn::FindInMap for instance when I have different TimeoutSeconds between dev, test & prod.

@bradduhon
Copy link

bradduhon commented Jun 16, 2020

Not sure if this is the place to post this or open a new report.

This is also an issue with the retry fields: MaxAttempts & BackoffRate. I imagine it is also an issue in the IntervalSeconds but I have not yet tested that...

MaxAttempts: !FindInMap: [Integration, !Ref STAGE, statesMaxAttempts]
BackoffRate: !FindInMap: [Integration, !Ref STAGE, statesBackoffRate]

Will convert the Integer stored in the Map to a String and throw an error on deployment. This worked in the normal Non-SAM StepFunctions resources.

@bradduhon
Copy link

Is this still being worked on the branch doesn't seem to have seen activity for a month now.

@awsjeffg awsjeffg added the stage/pm-review Waiting for review by our Product Manager, please don't work on this yet label Aug 20, 2020
@piersf
Copy link

piersf commented Dec 9, 2020

This seems to still be a problem. We basically can't pass any integer values using the DefinitionSubstitutions property to the state machine definition template(in JSON format) residing in a different file. The only solution I've found so far is to hardcode in the state machine definition template all integer values.

@mattshep
Copy link

I encountered this issue today when trying to use the value of a parameter for the MaxAttempts attribute of a Retry block.

Template Snippets:

  FetchMaxRetryAttempts:
    Type: Number
    Description: "Maximum number of retry attempts for Fetch stage (default: 3)"
    Default: 3
    MinValue: 0
    MaxValue: 3
            Retry:
              -
                ErrorEquals:
                  - "States.ALL"
                IntervalSeconds: 600
                MaxAttempts: !Ref FetchMaxRetryAttempts

Error:

Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Expected value of type Integer at /States/Fetch/Retry[0]/MaxAttempts' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: 2c1fb4e0-5a62-432f-91a7-ff5e225dd903; Proxy: null)

@jtheuer
Copy link

jtheuer commented Jul 23, 2021

Should this be fixed for TargetSpotCapacity as well? I still cannot use a substitution here.

@mikebroberts
Copy link

I just hit this for TimeoutSeconds too. Any plan on a fix for this?

@jfuss jfuss added the area/intrinsics Ref, If, Sub, GetAtt, ... label Mar 29, 2022
@hoffa
Copy link
Contributor

hoffa commented Oct 17, 2022

You might be able to get this to work by adding AWS::LanguageExtensions to Transform as such:

Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31

AWS::LanguageExtensions resolves intrinsic functions if the value is known when Transforms are run.

See #2533 for more information.

@hoffa
Copy link
Contributor

hoffa commented Nov 3, 2022

Closing in favor of #2533.

@hoffa hoffa closed this as completed Nov 3, 2022
@anashakt
Copy link

anashakt commented Jun 2, 2024

I just now ran into same situation while trying to pass "TimeoutSeconds" as integer in definitionSubstitutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... area/step-function stage/pm-review Waiting for review by our Product Manager, please don't work on this yet
Projects
None yet
Development

No branches or pull requests