Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add python/appsync-graphql-dynamodb/README.md #124

Merged
merged 3 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ $ cdk destroy
|---------|-------------|
| [api-cors-lambda](https://github.com/aws-samples/aws-cdk-examples/tree/master/python/api-cors-lambda/) | Shows creation of Rest API (GW) with an /example GET endpoint, with CORS enabled |
| [application-load-balancer](https://github.com/aws-samples/aws-cdk-examples/tree/master/python/application-load-balancer/) | Using an AutoScalingGroup with an Application Load Balancer |
| [appsync-graphql-dynamodb](https://github.com/aws-samples/aws-cdk-examples/tree/master/python/appsync-graphql-dynamodb/) | Creating a single GraphQL API with an API Key, and four Resolvers doing CRUD operations over a single DynamoDB |
| [classic-load-balancer](https://github.com/aws-samples/aws-cdk-examples/tree/master/python/classic-load-balancer/) | Using an AutoScalingGroup with a Classic Load Balancer |
| [custom-resource](https://github.com/aws-samples/aws-cdk-examples/tree/master/python/custom-resource/) | Shows adding a Custom Resource to your CDK app |
| [ecs-cluster](https://github.com/aws-samples/aws-cdk-examples/tree/master/python/ecs/cluster/) | Provision an ECS Cluster with custom Autoscaling Group configuration |
Expand Down
58 changes: 58 additions & 0 deletions python/appsync-graphql-dynamodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# AppSync GraphQL API Acting on DynamoDB
<!--BEGIN STABILITY BANNER-->
---

![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge)

> **This is an experimental example. It may not build out of the box**
>
> This examples does is build on Construct Libraries marked "Experimental" and may not be updated for latest breaking changes.
>
> 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

---
<!--END STABILITY BANNER-->

This an example of an AppSync GraphQL API, pointing to four resolvers doing CRUD operations with a single DynamoDB table.

## Build

To build this app, you need to be in this example's root folder. Then run the following:

```bash
$ python3 -m venv .env
$ source .env/bin/activate
$ pip install -r requirements.txt
```

This will install the necessary CDK, then this example's dependencies, and then build your Python files and your CloudFormation template.

Install the latest version of the AWS CDK CLI:

```shell
$ npm i -g aws-cdk
```

## Deploy

Run `cdk deploy`. This will deploy / redeploy your Stack to your AWS Account.

After the deployment you will see the API's URL, which represents the url you can then use.

## Synthesize Cloudformation Template

To see the Cloudformation template generated by the CDK, run `cdk synth`, then check the output file in the "cdk.out" directory.

## The Component Structure

This Stack contains:

- a __GraphQL API__ with an API Key (Use with caution, each key is only valid for 7 days.)
- a __GraphQL Schema__ with Queries to get one and all items and two mutations to save and delete an item
- a __DynamoDB table__ `items` that stores the data with a Pay Per Request Billing Mode
- an __IAM Role__ that allows AppSync to invoke your DynamoDB table.
- an __AppSync DataSource__, connecting your API to the DynamoDB table with the previously specified role.
- a __AppSync Resolver__ for a Query `getOne` to get one item from the DynamoDB table.
- a __AppSync Resolver__ for a Query `all` to get all items from the DynamoDB table.
- a __AppSync Resolver__ for a Mutation `save` to put an item into the DynamoDB table (the id is autogenerated, you need only name).
- a __AppSync Resolver__ for a Mutation `delete` to delete one item from the DynamoDB table.