Skip to content

Commit be9a1f8

Browse files
committed
chore: update README and keywords
1 parent 6a72e6b commit be9a1f8

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

.projenrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const project = new awscdk.AwsCdkConstructLibrary({
1818
minNodeVersion: '18.12.1',
1919
packageManager: 'yarn',
2020
npmAccess: NpmAccess.PUBLIC,
21+
keywords: [
22+
'appsync',
23+
'stepfunctions',
24+
'Serverless',
25+
'State Machine',
26+
],
2127
githubOptions: {
2228
projenCredentials: GithubCredentials.fromApp(),
2329
},

README.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,101 @@
1-
# cdk-appsync-data-source-sfn-express
1+
[![npm version](https://badge.fury.io/js/@opsbr%2Fcdk-appsync-data-source-sfn-express.svg)](https://badge.fury.io/js/@opsbr%2Fcdk-appsync-data-source-sfn-express) [![release](https://github.com/opsbr/cdk-appsync-data-source-sfn-express/actions/workflows/release.yml/badge.svg)](https://github.com/opsbr/cdk-appsync-data-source-sfn-express/actions/workflows/release.yml)
2+
3+
# cdk-appsync-data-source-sfn-express
4+
5+
A CDK construct to create an AWS AppSync data source to call AWS Step Functions express workflows.
6+
7+
[![View on Construct Hub](https://constructs.dev/badge?package=%40opsbr%2Fcdk-appsync-data-source-sfn-express)](https://constructs.dev/packages/@opsbr/cdk-appsync-data-source-sfn-express)
8+
## What is this?
9+
10+
This construct provides an HTTP data source for AWS AppSync that uses IAM authentication and
11+
calls AWS Step Functions API - `StartSyncExecution`. This is a stop-gap solution until AWS
12+
provides a native integration with this API like they have for AWS Lambda or Amazon DynamoDB.
13+
14+
Then, the construct can easily create a resolver to call this API, which means you can build
15+
AppSync GraphQL API by running a Step Functions state machine synchronously just like Amazon
16+
API Gateway already has, too.
17+
18+
Also, this is a showcase for how to use HTTP data source for non-RESTful AWS endpoints.
19+
20+
## Usage
21+
22+
```typescript
23+
declare const api: appsync.CfnGraphQLApi;
24+
declare const stateMachine: stepfunctions.StateMachine;
25+
26+
const schema = new appsync.CfnGraphQLSchema(stack, 'Schema', {
27+
apiId: api.attrApiId,
28+
definition: `
29+
type Query {
30+
getPost(id: Int): Post
31+
}
32+
type Post {
33+
id: Int
34+
title: String
35+
}
36+
`,
37+
});
38+
39+
const sfnExpressDataSource = new AppSyncDataSourceStepFunctionsExpress(stack, 'SfnExpressDataSource', {
40+
apiId: api.attrApiId,
41+
});
42+
43+
sfnExpressDataSource.createStateMachineResolver('SumResolver', {
44+
stateMachine: sumStateMachine,
45+
schema,
46+
typeName: 'Query',
47+
fieldName: 'getPost',
48+
});
49+
```
50+
51+
When queried, the specified state machine receives input as the arguments of `getPost()` e.g.:
52+
53+
```graphql
54+
query MyQuery {
55+
getPost(id: 1)
56+
}
57+
```
58+
59+
is transformed to:
60+
61+
```json
62+
{
63+
"id": 1
64+
}
65+
```
66+
67+
And the state machine should return the output like below:
68+
69+
```json
70+
{
71+
"id": 1,
72+
"title": "Hello world!"
73+
}
74+
```
75+
76+
Then, AppSync returns the output as the return type of the query:
77+
78+
```graphql
79+
{
80+
"data": {
81+
"getPost": {
82+
"id": 1,
83+
"title": "Hello world!"
84+
}
85+
}
86+
}
87+
```
88+
89+
## Notes
90+
91+
- The state machine must be EXPRESS type. See [Step Functions document](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-standard-vs-express.html) for more details.
92+
- Currently, this construct doesn't have a good error handling on the response mapping.
93+
- We need to handle the case when the workflow fails because `StartSyncExecution` returns 200. See [Step Functions document](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartSyncExecution.html).
94+
95+
## Authors
96+
97+
OpsBR Software Technology Inc. Visit our website: [https://opsbr.com](https://opsbr.com)
98+
99+
## License
100+
101+
Apache 2.0

package.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)