Giter Club home page Giter Club logo

aws-step-functions-developer-guide's Introduction

aws-step-functions-developer-guide's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-step-functions-developer-guide's Issues

Synchronous Express state machine execution does not work

State machines called sync (EXPRESS), give strange error and modify URL that's used for local:

laptop$ aws stepfunctions --endpoint http://localhost:8083 create-state-machine --type "EXPRESS" --definition "{\
>   \"Comment\": \"A Hello World example of the Amazon States Language using an AWS Lambda Local function\",\
>   \"StartAt\": \"HelloWorld\",\
>   \"States\": {\
>     \"HelloWorld\": {\
>       \"Type\": \"Task\",\
>       \"Resource\": \"arn:aws:lambda:us-east-1:123456789012:function:HelloWorldFunction\",\
>       \"End\": true\
>     }\
>   }\
> }\
> }}" --name "HelloWorld" --role-arn "arn:aws:iam::012345678901:role/DummyRole"
{
    "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld2",
    "creationDate": "2020-12-07T16:12:18.496000-06:00"
}

laptop$ aws stepfunctions --endpoint http://localhost:8083 start-sync-execution --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld2 --name test

Could not connect to the endpoint URL: "http://sync-localhost:8083/"

Clarify intrinsic functions limitaitons

The dedicated intrinsic functions page states that "Intrinsics are constructs that look similar to functions in programming languages", however there are no clear definition of the limitations comparing to the regular programming languages which leads to compile or runtime errors.

Two most important features that I find missing and already spent some time fixing errors are the following:

  1. You cannot pass result of one function as a parameter to another:
    {"date": "States.ArrayGetItem(States.StringSplit('2020-05-27T08:00:00.000Z', 'T'), 0)"}
  2. You cannot access the result of the function instantly within the same call:
    {"date": "States.StringSplit('2020-05-27T08:00:00.000Z', 'T')[0]"}

There are might be other limitations that worth mentioning (or implementing as a feature)

Lambda.TooManyRequestsException even with no concurrent lambdas

Whenever the step function waits for more than 5min, the next lambda in the step function fails with a Lambda.TooManyRequestsException.
I am sure that the number of lambdas called concurrently in my account won't even cross 5. This is very frustrating.

I tried removing my internal multiprocessing logic in the lambda, but the issue still persists.
I think this error is a default error.

Manage a Batch Job (AWS Batch, Amazon SNS) is not working in cn-north-1 region

https://github.com/awsdocs/aws-step-functions-developer-guide/blob/master/doc_source/batch-job-notification.md

when I run the example project, meet error below issue in cloudformation stack. when I change the ec2.amazonaws.com to ec2.amazonaws.com.cn, it fixed.

Invalid principal in policy: "SERVICE":"ec2.amazonaws.com" (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: f3de836d-ae63-4d59-95e1-d162d3031b72)

Workflow Studio documentation - page not found

Looks like the links at the bottom of the Developers Guide are broken or the live state doesn't match the repo. Unfortunately, I seem to be able to find any Workflow Studio documentation on this repo (used GitHub's repository search function too).

https://docs.aws.amazon.com/step-functions/latest/dg/workflow-studio-known-limitations.html leads to https://github.com/awsdocs/aws-step-functions-developer-guide/tree/master/doc_source/workflow-studio-known-limitations.md which throws a 404.

Just wanted to submit a correction for the following:

Some service states are not currently available in Workflow Studio. Instead, after you creat create or edit your state machine in Workflow Studio, you can use code snippets to add the state to your state machine definition. Code snippets can be found in the drop down menu on your state machine's code pane.

Let me know where I can submit an MR. Thank you!

DynamoDB Integration Clarification

Hi ho!

The documentation inside Optimized Integrations > Amazon DynamoDB is somewhat confusing.

There's a callout before listing the API actions that says:

How the optimized DynamoDB integration is different than the DynamoDB AWS SDK integration
There is no optimization for the Request Response integration pattern. The Wait for a Callback with the Task Token integration pattern is not supported. Only [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/ API_GetItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/ API_GetItem.html), [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/ API_PutItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/ API_PutItem.html), and [https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/ API_UpdateItem.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/ API_UpdateItem.html) API actions are available through optimized integration. Other API actions, such as https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html are available using the DynamoDB AWS SDK integration.

But then in the body of the documentation the DeleteItem API is also referenced. Just want to get some clarification on which is correct, I'm happy to submit a PR to update the doc either way once we have that clarification

InputPath and Parameters example syntax errors

The examples on this page InputPath and Parameters has syntax errors:

{
  "comment": "Example for InputPath.",
  "dataset1": {
    "val1": 1,
    "val2": 2,
    "val3": 3,
  },
  "dataset2": {
    "val1": "a",
    "val2": "b",
    "val3": "c"
  }
}

should be:

{
  "comment": "Example for InputPath.",
  "dataset1": {
    "val1": 1,
    "val2": 2,
    "val3": 3
  },
  "dataset2": {
    "val1": "a",
    "val2": "b",
    "val3": "c"
  }
}

In the parameters section

{
  "comment": "Example for Parameters.",
  "product": {
    "details": {
       "color": "blue",
       "size": "small",
       "material": "cotton",
    },
    "availability": "in stock",
    "sku": "2317",
    "cost": "$23"
  }
}

should be:

{
  "comment": "Example for Parameters.",
  "product": {
    "details": {
       "color": "blue",
       "size": "small",
       "material": "cotton"
    },
    "availability": "in stock",
    "sku": "2317",
    "cost": "$23"
  }
}

and

"Parameters": {
        "comment": "Selecting what I care about.",
        "MyDetails": {
          "size.$": "$.product.size",
          "exists.$": "$.availability",
          "StaticValue": "foo"
        }
      },

should be:

"Parameters": {
        "comment": "Selecting what I care about.",
        "MyDetails": {
          "size.$": "$.product.details.size",
          "exists.$": "$.product.availability",
          "StaticValue": "foo"
        }
      },

Unclear documentation regarding nested maps and lists in DDB integration.

On: https://github.com/awsdocs/aws-step-functions-developer-guide/blob/master/doc_source/connect-ddb.md

It's not clear what this statement means:

You cannot pass a map or list to DynamoDB inside a map.

Specifically:

inside a map

Inside a nested map attribute, or a Step Function Map task? Can I pass a map or list as a top-level attribute? Also, explain why ...

A consistent problem I see with AWS docs is that they only show simple cases. The examples should go a bit deeper.

Example using S3 data dump in between steps

Hello I'm trying to understand the whole writing to S3 and reading it from S3 on other steps. Is possible to provide an example, that will show how to use an S3 in step functions thanks.

Recommend posting an example EC2 Activity Worker in Python

Hi Docs Team,

It took me quite awhile to get a Python EC2 Activity Worker going - an example would be very helpful. I can't read Ruby (yet), and luckily I stumbled upon a Java example that got me closer. Here is what I ended up with for a basic (functional) Python example. It could be made way better in many ways, but it does seem to work:

https://stackoverflow.com/questions/52915690/step-functions-activity-worker-best-practice-for-handling-long-polling-timeout/52968269#52968269

What led me astray was how the Boto3 docs reference a null string being returned in the response (when no activities are in the Step Functions Queue). I was looking for a Key: Value pair with no value, but really it seems that the Step Functions response does not include the taskToken key either.

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html#SFN.Client.get_activity_task

"The maximum time the service holds on to the request before responding is 60 seconds. If no task is available within 60 seconds, the poll returns a taskToken with a null string."

Thanks,
Andrew
aetroup@

WAIT_TIME_SCALE is not respected when evaluating TaskState.Retry[].IntervalSeconds

I'm using amazon/aws-stepfunctions-local docker image for testing a following machine simple StateMachine definition:

      Definition:
        StartAt: GetElementCount
        States:
          GetElementCount:
            Type: Task
            Resource: arn:aws:lambda:::function:some-function
            Parameters:
              "stateName.$": "$$.State.Name"
              "collection.$": "$.collection"

            ResultPath: "$.iterator"
            Next: CheckIfFinished
          CheckIfFinished:
            Type: Choice
            Choices:
              -
                Variable: "$.iterator.continue"
                BooleanEquals: true
                Next: ProcessElement
            Default: Done
          ProcessElement:
            Type: Task
            Resource: arn:aws:lambda:::function:some-function
            ResultPath: "$.iterator"
            Parameters:
              "stateName.$": "$$.State.Name"
              "collection.$": "$.collection"
              "iterator.$": "$.iterator"

            Next: WaitABit
            Retry:
              - ErrorEquals:
                  - States.TaskFailed
                IntervalSeconds: 3
                MaxAttempts: 65535
                BackoffRate: 1.5
          WaitABit:
            Type: Wait
            Seconds: 10
            Next: CheckIfFinished
          Done:
            Type: Succeed

I'm running a testcase against a following SFN_MOCK_CONFIG:

{
  "StateMachines": {
    "MySampleStateMachine": {
      "TestCases": {
        "ProcessingFailsAndGetsRetried": {
          "GetElementCount": "InitIteratorState",
          "ProcessElement": "ProcessElementStateOneFailure"
        }
      }
    }
  },
  "MockedResponses": {
    "InitIteratorState": {
      "0": {
        "Return": {
          "continue": true,
          "count": 3,
          "index": 0
        }
      }
    },
    "ProcessElementStateOneFailure": {
      "0": {
        "Throw": {
          "Error":"Lambda.TimeoutException",
          "Cause":"Lambda timed out."
        }
      },
      "1": {
        "Return": {
          "continue": true,
          "count": 3,
          "index": 1
        }
      },
      "2": {
        "Return": {
          "continue": true,
          "count": 3,
          "index": 2
        }
      },
      "3": {
        "Return": {
          "continue": false,
          "count": 3,
          "index": 3
        }
      }
    }

  }
}

I set the envrionment variable WAIT_TIME_SCALE to 0 and I confirm it's respected for WaitABit state.
However when I look at result of aws stepfunctions --endpoint http://172.18.0.2:8083 get-execution-history --execution-arn <ARN>
I can see the following

 ....
       {
            "timestamp": 1650293455.773,
            "type": "LambdaFunctionStarted",
            "id": 11,
            "previousEventId": 10
        },
        {
            "timestamp": 1650293455.773,
            "type": "LambdaFunctionFailed",
            "id": 12,
            "previousEventId": 11,
            "lambdaFunctionFailedEventDetails": {
                "error": "Lambda.TimeoutException",
                "cause": "Lambda timed out."
            }
        },
        {
            "timestamp": 1650293458.775,
            "type": "LambdaFunctionScheduled",
            "id": 13,
            "previousEventId": 12,
            "lambdaFunctionScheduledEventDetails": {
                "resource": "arn:aws:lambda:us-east-1:123456789012:function:some-function",
                "input": "{\"iterator\":{\"continue\":true,\"count\":3,\"index\":0},\"stateName\":\"ProcessElement\",\"collection\":[{\"index\":0},{\"index\":1},{\"index\":2}]}",
                "inputDetails": {
                    "truncated": false
                }
            }
        },
...

Please notice that timestamp goes from 1650293455.773 to 1650293458.775 which is consistent with

     IntervalSeconds: 3

that I have in my definition.

This makes testcases that test retrying slow. Shouldn't retrying work the same way as WaitTask and multply the IntervalSeconds by WAIT_TIME_SCALE ?

Add "best practices" notes around error handling with regards to user input

Yesterday, I was working with Step Functions on a workflow that accepted user input and processed it. In several tasks, some validation activities occur, which can fail (due to user input). I've noticed, though experimentation and searching around, that this isn't really what workflows are meant for:

  1. The Fail state in a definition cannot accept paths ($), only hard-coded strings. This implies that internal errors shouldn't "bubble up" to the end state.
  2. A machine doesn't have an Error output, only individual tasks have that (which requires doing a history lookup).
  3. It's near-impossible to return a "nice" error from a Lambda function. For example, if you're validating that a user entered a valid option, you can't just throw an e.g. ValidationError, as that'll end up with an error state with {error: ValidationError, cause: a-very-long-string-with-a-json-serialized-stack-trace}. (It is possible to do this with an activity worker and manually calling SendTaskFailure -- but that's not a useful option when a task is directly running a function).

These, to me, very strongly suggests that error handling logic in a step functions definition should only be for unexpected errors, not those that can be handled with user input. Expected errors due to user input should (apparently) still result in successful workflows, unless I really missed some big feature somewhere.

If a section in the docs were added to address this, I bet it would save a lot of developers some time: https://docs.aws.amazon.com/step-functions/latest/dg/sfn-best-practices.html

If you'd like, I'm happy to discuss this internally (peddicor@) with doc writers and/or the service team.

Contribute to Best Practices

If you have ideas about best practices topics that I should include in our AWS Step Functions Developer Guide, please let me know! Better yet, submit a topic and I'll see about getting the content into the guide.

https://github.com/awsdocs/aws-step-functions-developer-guide/blob/master/doc_source/sfn-best-practices.md

Submit a pull request as explained in these directions: https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/CONTRIBUTING.md .

I look forward to hearing from you.

Not authorized to assume the provided role

Originally asked at Stack Overflow.

The tutorial does not say clear which policies should be added for the IAM role. I added based on the screenshot. I tried to add one more policy AWSStepFunctionsFullAccess for the step_functions_basic_execution role, but still same.


I am following exact the AWS Step Functions tutorial. The whole state machine process is like this.

enter image description here

I have a role called step_functions_basic_execution with policy AWSLambdaRole. My Step function state machine is using this role.

My step function is

{
  "Comment": "A simple AWS Step Functions state machine that automates a call center support session.",
  "StartAt": "Open Case",
  "States": {
    "Open Case": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-west-2:829495130000:function:OpenCaseFunction",
      "Next": "Assign Case"
    }, 
    ...
}

The corresponding Open Case Lambda function is

exports.handler = (event, context, callback) => {
    // Create a support case using the input as the case ID, then return a confirmation message   
   var myCaseID = event.inputCaseID;
   var myMessage = "Case " + myCaseID + ": opened...";   
   var result = {Case: myCaseID, Message: myMessage};
   callback(null, result);    
};

When I tried to run it, it failed at first step Open Case.

The input is

{
  "inputCaseID": "001"
}

It throws error:

States.TaskFailed

Neither the global service principal states.amazonaws.com, nor the
regional one is authorized to assume the provided role.

Any idea how to fix it? Thanks

Parallel state documentation could be improved

The simplicity of the examples in the Parallel state documentation page led to some confusion among our developers. In particular, they were confused about the statement "A state in one branch of a Parallel state must not have a Next field that targets a field outside of that branch, nor can any other state outside the branch transition into that branch." When looking at the accompanying image, which shows two branches, each with a single state (i.e., not having a Next state) and the Parallel state itself not having a Next state, they interpreted this as Parallel states being dead ends. I believe a more comprehensive example state machine could help clear up this confusion. We extended the documentation example with a few more states to help resolve the confusion, you can see it here. I think it would also be worth including a visual depiction of what state machine logic is not allowed (in that state machine, a connection between PutItem and LookupPhone or LookupName would not be allowed, nor between LookupAddress and LookupName).

Additionally, I believe it would be helpful in these diagrams to draw arrows from the last state in each branch to the Next state after the Parallel state, indicating that the output gets collected and passed; this mirrors the way the input to the parallel state is drawn to the starting state for each branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.