An open API service indexing awesome lists of open source software.

https://github.com/garysassano/cdk-aws-appsync-events

CDK app that deploys an AppSync Event API with Lambda and DynamoDB data source integrations
https://github.com/garysassano/cdk-aws-appsync-events

appsync appsync-data-sources appsync-event-api appsync-events aws-appsync aws-cdk aws-lambda ddb dynamodb

Last synced: 9 months ago
JSON representation

CDK app that deploys an AppSync Event API with Lambda and DynamoDB data source integrations

Awesome Lists containing this project

README

          

# cdk-aws-appsync-events

CDK app that deploys an AppSync Event API with Lambda and DynamoDB data source integrations.

## Prerequisites

- **_AWS:_**
- Must have authenticated with [Default Credentials](https://docs.aws.amazon.com/cdk/v2/guide/cli.html#cli_auth) in your local environment.
- Must have completed the [CDK bootstrapping](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) for the target AWS environment.
- **_Node.js + npm:_**
- Must be [installed](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) in your system.

## Installation

```sh
npx projen install
```

## Deployment

```sh
npx projen deploy
```

## Usage

1. Once deployed, test sending messages and subscribing to events in both namespaces:
- In AWS Console, `AppSync` ➜ `sample-api` ➜ `Pub/Sub Editor`.
- To **send a message**:
1. Select a namespace.
2. Provide a channel name (e.g., `/ch1`).
3. Leave the default JSON payload or provide a custom one.
4. Click `Publish`.
- To **subscribe to messages**:
1. Select a namespace.
2. Provide a channel name (e.g., `/ch1`) or leave the default (`/*`) to subscribe to all channels.
3. Click `Subscribe`.
2. For the `foo` namespace:
- You should see that the messages received by subscribers are transformed.
- Optionally, to see the logs generated by the Lambda function:
- In AWS Console, `CloudWatch` ➜ `Log groups` ➜ `/aws/lambda/sample-function`.
3. For the `bar` namespace:
- To see the messages stored in the table:
- In AWS Console, `DynamoDB` ➜ `Tables` ➜ `sample-table`.

## Cleanup

```sh
npx projen destroy
```

## Application Details

- `foo`
- An AppSync namespace with a Lambda data source integration.
- It uses a `Direct` handler for all events.
- Logs `onPublish` and `onSubscribe` events, while transforming `onPublish` messages.
- `bar`
- An AppSync namespace with a DynamoDB data source integration.
- It uses an `AppSyncJS` handler for all events.
- Stores `onPublish` messages and `onSubscribe` events in a DynamoDB table.

## Architecture Diagram

![Architecture Diagram](./src/assets/arch-diagram.svg)