aws / aws/aws-sam-cli-app-templates
Throw users a bone? Show how to invoke step function locally USING the ASL file? Show how to see the local logs?
- Dominant language
- Python
- Stars
- 534
- Forks
- 264
- PR merge metrics
- No merged PRs in 30d
Description
Trying the ruby 2.7 Stock Trader "example". (All the AWS guides seems to be pointedly silent on the subject of locally executing a step function as defined in a SAM project). There's a fair number of stackoverflow questions on this topic, none of which explain how to do it.
So a single, complete "how to test stock Trader step function locally" would be a most welcome addition to the docs since it includes multiple lambdas, a DB table and a step function.
I think I might be about half-way there... maybe someone else can help document the incantations needed to make it work locally, and to be able to view log results afterwards.
I did eventually find (by trial and error) that when using `aws stepfunctions create-state-machine` is is possible to specify a _file_ (rather than enter the json on the command line per the online examples, which, let's face it, is a useless example).
And I did find out (again by trial and error) that one (apparently) needs to _manually_ create a NEW json file with all the resource variables in the ASL file de-referenced by 'local' ARNs?
And (once again by trial an error) I found that the edits to that COPY of the ASL file go _something_ like this:
```
${StockCheckerFunctionArn} -> arn:aws:lambda:us-east-1:123456789012:function:StockCheckerFunctionArn
${StockSellerFunctionArn} -> arn:aws:lambda:us-east-1:123456789012:function:StockSellerFunctionArn
${StockBuyerFunctionArn} -> arn:aws:lambda:us-east-1:123456789012:function:StockBuyerFunctionArn
${DDBPutItem} -> arn:aws:lambda:us-east-1:123456789012:transaction_table:DDBPutItem
${DDBTable} -> arn:aws:lambda:us-east-1:123456789012:transaction_table:TransactionTable
```
So if the **edited** ASL file is saved in a new folder in the SAM project, for example as `edata/step1.asl.json`, the step function can _almost_ be tested locally using:
Mac terminal window # 1: `sam local start-lambda`
Mac terminal window # 2: `docker run -p 8083:8083 amazon/aws-stepfunctions-local`
Mac terminal window # 3 (note the use of **file://**): `aws stepfunctions --endpoint http://localhost:8083 create-state-machine --definition file://edata/step1.asl.json --name StockTradingStateMachine --role-arn "arn:aws:iam::012345678901:role/StockTradingStateMachineRole"`
then, to RUN it:
Mac terminal window # 4: `aws stepfunctions --endpoint http://localhost:8083 describe-execution --execution-arn arn:aws:states:us-east-1:123456789012:execution:StockTradingStateMachine:test`
The output of terminal # 4 finally shows something:
```
{
"executionArn": "arn:aws:states:us-east-1:123456789012:execution:StockTradingStateMachine:test",
"stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:StockTradingStateMachine",
"name": "test",
"status": "RUNNING",
"startDate": "2021-04-21T14:55:12.961000-10:00",
"input": "{}",
"inputDetails": {
"included": true
}
}
```
But the output stream in terminal # 2 shows the error:
2021-04-22 00:58:34.179: arn:aws:states:us-east-1:123456789012:execution:StockTradingStateMachine:test : {"Type":"ExecutionFailed","PreviousEventId":20,"ExecutionFailedEventDetails":{"Error":"Lambda.AWSLambdaException","Cause":"The security token included in the request is invalid. (Service: AWSLambda; Status Code: 403; Error Code: UnrecognizedClientException; Request ID: 2cd8222b-5f6e-4b1e-8263-d34438d713c9; Proxy: null)"}}
The examples I've found also fail to show how to provide a test input event to a step function. (The -e flag used when locally invoking Lambdas does not seem to work.)
Contributor guide
Research direction
Start with the Ruby 2.7 Stock Trader example and its SAM project, then reproduce the reported commands using edata/step1.asl.json, sam local start-lambda, and the AWS Step Functions Local container. Document the complete local workflow, including creating and running the state machine, supplying test input, and viewing logs; done means a newcomer can follow it without trial and error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, ruby
- Domain
- cloud, devops, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100