|
| 1 | +# AppSync GraphQL API Acting on DynamoDB |
| 2 | +<!--BEGIN STABILITY BANNER--> |
| 3 | +--- |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +> **This is an experimental example. It may not build out of the box** |
| 8 | +> |
| 9 | +> This examples does is build on Construct Libraries marked "Experimental" and may not be updated for latest breaking changes. |
| 10 | +> |
| 11 | +> If build is unsuccessful, please create an [issue](https://github.com/aws-samples/aws-cdk-examples/issues/new) so that we may debug the problem |
| 12 | +
|
| 13 | +--- |
| 14 | +<!--END STABILITY BANNER--> |
| 15 | + |
| 16 | +This an example of an AppSync GraphQL API, pointing to four resolvers doing CRUD operations with a single DynamoDB table. |
| 17 | + |
| 18 | +## Build |
| 19 | + |
| 20 | +To build this app, you need to be in this example's root folder. Then run the following: |
| 21 | + |
| 22 | +```bash |
| 23 | +$ python3 -m venv .env |
| 24 | +$ source .env/bin/activate |
| 25 | +$ pip install -r requirements.txt |
| 26 | +``` |
| 27 | + |
| 28 | +This will install the necessary CDK, then this example's dependencies, and then build your Python files and your CloudFormation template. |
| 29 | + |
| 30 | +Install the latest version of the AWS CDK CLI: |
| 31 | + |
| 32 | +```shell |
| 33 | +$ npm i -g aws-cdk |
| 34 | +``` |
| 35 | + |
| 36 | +## Deploy |
| 37 | + |
| 38 | +Run `cdk deploy`. This will deploy / redeploy your Stack to your AWS Account. |
| 39 | + |
| 40 | +After the deployment you will see the API's URL, which represents the url you can then use. |
| 41 | + |
| 42 | +## Synthesize Cloudformation Template |
| 43 | + |
| 44 | +To see the Cloudformation template generated by the CDK, run `cdk synth`, then check the output file in the "cdk.out" directory. |
| 45 | + |
| 46 | +## The Component Structure |
| 47 | + |
| 48 | +This Stack contains: |
| 49 | + |
| 50 | +- a __GraphQL API__ with an API Key (Use with caution, each key is only valid for 7 days.) |
| 51 | +- a __GraphQL Schema__ with Queries to get one and all items and two mutations to save and delete an item |
| 52 | +- a __DynamoDB table__ `items` that stores the data with a Pay Per Request Billing Mode |
| 53 | +- an __IAM Role__ that allows AppSync to invoke your DynamoDB table. |
| 54 | +- an __AppSync DataSource__, connecting your API to the DynamoDB table with the previously specified role. |
| 55 | +- a __AppSync Resolver__ for a Query `getOne` to get one item from the DynamoDB table. |
| 56 | +- a __AppSync Resolver__ for a Query `all` to get all items from the DynamoDB table. |
| 57 | +- a __AppSync Resolver__ for a Mutation `save` to put an item into the DynamoDB table (the id is autogenerated, you need only name). |
| 58 | +- a __AppSync Resolver__ for a Mutation `delete` to delete one item from the DynamoDB table. |
0 commit comments