Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eoinsha/step-function-api-example
Example Express Step Function behind a REST API in API Gateway
https://github.com/eoinsha/step-function-api-example
Last synced: 15 days ago
JSON representation
Example Express Step Function behind a REST API in API Gateway
- Host: GitHub
- URL: https://github.com/eoinsha/step-function-api-example
- Owner: eoinsha
- Created: 2024-03-12T13:39:32.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-12T13:43:19.000Z (10 months ago)
- Last Synced: 2024-04-13T16:08:09.114Z (9 months ago)
- Language: TypeScript
- Size: 162 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Step Function Express API Example
This is a simple Step Function (EXPRESS) implementation of an AWS API Gateway REST API.
It uses CDK to construct a sample state machine that is invoked by an API Gateway Proxy Integration.## Step Function Design
The state machine invokes an HTTPS endpoint using an [HTTP Task](https://docs.aws.amazon.com/step-functions/latest/dg/connect-third-party-apis.html) defined by an EventBridge HTTP Connection.
A choice state allows the HTTP invocation to be skipped if the `skip=true` query string is provided in the URL.![Step Function design include a Pass State, a "Skip API" Choice State and an HTTP Endpoint API Invocation](step-function-definition.png)
## Deployment
```sh
npm install
cdk deploy
```
The API Gateway HTTPS endpoint is printed to the screen on successful deployment.## Evaluating
X-Ray tracing is enabled for the API deployment and the Step Function, allowing you to see errors and performance metrics.
Execute the API as follows (using cURL):
```sh
curl -v https://.execute-api.eu-west-1.amazonaws.com/prod
```To skip the API invocation and run the simple `Pass` and `Choice` states of the step function, add the `skip=true` query parameter:
```sh
curl -v "https://.execute-api.eu-west-1.amazonaws.com/prod?skip=true"
```With the HTTP invocation step, this sample shows 404ms end-to-end with 369ms of that for the HTTP invocation.
![AWS X-Ray trace showing the timelines of segments including HTTP invocation](trace-with-api.png)Skipping the HTTP invocation step, the following sample shows 98ms end-to-end, with 13ms for the State Machine execution. The rest of the time appears to be in the Step Function service orchestration.
![AWS X-Ray trace showing the timelines of segments when HTTP invocation is skipped](trace-without-api.png)## Cleaning up
```sh
cdk destroy
```