Skip to content

deeheber/note-service-next-generation

Repository files navigation

Note Service (Next Generation)

Rewriting note-service using CDK, TypeScript, and GraphQL. It's a CRUD app for storing notes.

Getting Started

Prerequisite Setup

  1. Sign up for an AWS account.
  2. Follow the instructions to install and configure the AWS CLI on your computer.
  3. Bootstrap your AWS account ("environment") with the CDK.
  4. Install NodeJS on your computer. We recommend the version specified in the .nvmrc file in the root of this project.

Run the Application

  1. Clone this repo and run npm install from the project root.
  2. From the project root run npm run deploy. This will build and deploy this application using the cdk to your bootstrapped AWS account/region. Note: the first time running this command might result in an error...if that happens run npm run build first. 2a. If using a non-default AWS profile, you can npm run build to build the TypeScript and then run npm run cdk deploy -- --profile <your-profile-name-here>
  3. Get the apiId and apiURL from the output in your console. You will need these values later to make requets to the API.
  4. Send requests to the application using a third party client or login to the AWS AppSync console and make requests from Queries. I personally like to use Postman, but here's some other suggestions if you don't have a preferred way to send requests to an API.

Authorization

Currently this application is using the API key authorization setting. You can obtain the API key by logging into the AWS AppSync console after a successful deploy. Alternatively, you can run this command using the AWS CLI and the apiId that printed out to your console after a successfuly deploy to obtain your key:

aws appsync list-api-keys --api-id <api id here>

The key is good for 30 days after deploy. After that you'll need to generate a new one.

If you're using Postman or making API calls through a client make sure to set a header x-api-key to the value of your API key.

Available Queries

  1. List notes
query ListNotes {
  listNotes {
    items {
      author
      content
      createdAt
      updatedAt
      id
    }
    total
  }
}
  1. Get note by id
query GetNote($id: ID = "Note id goes here") {
  getNote(id: $id) {
    author
    content
    createdAt
    id
    updatedAt
  }
}

Available Mutations

  1. Create note
mutation CreateNote($author: String = "Author goes here", $content: String = "Content goes here") {
  createNote(note: {author: $author, content: $content}) {
    author
    content
    createdAt
    id
    updatedAt
  }
}
  1. Delete note
mutation DeleteNote($id: ID = "ID to delete goes here") {
  deleteNote(id: $id)
}
  1. Update note
mutation UpdateNote($content: String = "add note content here") {
  updateNote(content: $content, id: "add note id here") {
    updatedAt
    id
    createdAt
    content
    author
  }
}

Clean up (optional but good for your wallet)

To remote the CloudFormation stack and created resources run npm run destroy and confirm on the command line from the project root.

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run deploy run typescript compiler then deploy to your default AWS account/region via the cdk
  • npm install installs all dependencies including the postinstall script
  • npm run test perform the jest unit tests
  • npm run cdk diff compare deployed stack with current state
  • npm run cdk synth emits the synthesized CloudFormation template

The cdk.json file tells the CDK Toolkit how to execute the app.

Contributing

See CONTRIBUTING.md for more info on our guildelines.

About

A graphQL CRUD API built using AWS AppSync, Lambda, DynamoDB, CDK, Typescript.

Topics

Resources

Stars

Watchers

Forks