question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can't succesfully run a statemachine with local lambdas

See original GitHub issue

Hi,

I’m unable to execute a single ‘hello world’ python lambda with localstack and stepfunctions-local. The lambda is working as expected: aws --endpoint-url=http://localhost:4574 lambda invoke --function-name lambda1 outfile.txt && cat outfile.txt { "StatusCode": 200 } Hello from Lambda

Then created a statemachine that uses the ARN of ‘lambda1’: aws stepfunctions --endpoint http://localhost:4584 create-state-machine --role-arn arn:aws:iam::000000000000:role/service-role/MyRole --name successmachine --definition '{"Comment": "Test Step Function","StartAt": "SuccessLambda","States": {"SuccessLambda": {"Type": "Task","Resource": "arn:aws:lambda:us-east-1:000000000000:function:lambda1","Next": "EndState"},"EndState": {"Type": "Pass","End": true}}}'

But after starting an execution and grabbing the details of the execution-arn:

aws stepfunctions --endpoint http://localhost:4584 get-execution-history --execution-arn arn:aws:states:local:000000000000:execution:successmachine:14410b5c-ff6b-4a6c-a1a6-88c06a1fc39c { "events": [ { "timestamp": 1526997500.206, "executionStartedEventDetails": { "input": {} }, "type": "ExecutionStarted", "id": 1, "previousEventId": 0 }, { "timestamp": 1526997500.208, "type": "TaskStateEntered", "id": 2, "stateEnteredEventDetails": { "input": {}, "name": "SuccessLambda" }, "previousEventId": 1 }, { "timestamp": 1526997500.208, "lambdaFunctionScheduledEventDetails": { "input": {}, "timeoutInSeconds": 99999999 }, "type": "LambdaFunctionScheduled", "id": 3, "previousEventId": 2 }, { "timestamp": 1526997500.209, "type": "LambdaFunctionStarted", "id": 4, "previousEventId": 3 }, { "lambdaFunctionFailedEventDetails": { "cause": "SyntaxError", "error": "Unexpected token H in JSON at position 0" }, "timestamp": 1526997500.247, "type": "LambdaFunctionFailed", "id": 5, "previousEventId": 4 }, { "executionFailedEventDetails": { "cause": "SyntaxError", "error": "Unexpected token H in JSON at position 0" }, "timestamp": 1526997500.248, "type": "ExecutionFailed", "id": 6, "previousEventId": 5 } ] }

I’m not getting the clue of the JSON error. Any help is appreciated!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Azuaroncommented, Aug 14, 2018

I believe I know why the error is happening, since I’m also having this problem:

What’s going into the output.txt file is trying to be parsed as JSON by the state machine. But, what’s going into the output.txt file is:

Hello from Lambda

And the JSON parser’s barfing on the ‘H’. In my case, it was barfing on an S, which was the first character of my output.txt file.

I don’t know enough about State Machines to know if this is a contract I’m breaking on my end, or if stepfunctions-local needs to support plain text in lambda outputs (if someone with more experience could chime in), but at least there’s a why now.

From what I can tell, output.txt is the log of the lambda function, not the return of the lambda function, so I’m not sure why it’s being parsed as JSON.

Edit: It’s println statements. Don’t println in your Lambdas, even for debugging.

0reactions
tristanbeniercommented, Sep 5, 2018

Hi @Azuaron

The output.txt file will contain the result of the lambda, not the logs. At least for NodeJS lambdas. I guess it is the same behaviour for all.

@RutgerBeyen your issue should be solved now. We released a new version last week which I hope solved it. If you have some time to retry, please give us some update.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't succesfully run a statemachine with local lambdas #31
Hi,. I'm unable to execute a single 'hello world' python lambda with localstack and stepfunctions-local. The lambda is working as expected:
Read more >
Creating a Step Functions state machine that uses Lambda
Ensure that your Lambda function is under the same AWS account and AWS Region as your state machine. Open the Lambda console and...
Read more >
step-functions-local: Can't start state machine within state ...
Try something like export STEP_FUNCTIONS_ENDPOINT=http://localhost:8083 && serverless offline start - that should cause step function local ...
Read more >
Testing strategies for Step Functions - Lumigo
Tests that focus on the Lambda functions and runs locally. End-to-end (e2e) tests that execute the state machine for real.
Read more >
AWS Step Functions Local – start testing functions locally
For example, when you define a task that should run some lambda and the state machine reaches that step, it will call the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found