GithubHelp home page GithubHelp logo

demo-aws-graphql-python's Introduction

Python powered GraphQL in AWS Lambda

This project is a proof of concept to run the Graphene implementation of GraphQL in AWS Lambda.

  • Serverless GraphQL (API-Gateway + Lambda)
  • Uses Graphene-Python implementation
  • Datastore agnostic: Use Graphene-SQLAlchemy for AWS RDS, or custom resolvers for other AWS resources

Local development setup

Install pipenv

$ pip install pipenv

Install dependencies

$ export PIPENV_VENV_IN_PROJECT=true
$ pipenv install --dev --three

Note: We are using the python3.6 lambda execution environment in AWS. Please make sure you're using the same python version during development.

Local Flask development server

To run a local Flask server for development:

pipenv run ./cli.py server

Although we're building serverless applications, I generally find it useful to run a local flask server that quickly mocks out API endpoints to serve mock data. This allows us to develop offline and not wrestle with serverless tools, while keeping mock data out of the frontend codebase.

This demo serves GraphQL queries from an in-memory data storage, together with GraphiQL UI interface for testing queries. Test drive the following query in the local flask server [http://127.0.0.1:5000/]:

{
  user {
    id
    userId
    firstName
    lastName
    email
    avatarUrl
    education
    job
    address
    introduction
    friends {
      pageInfo {
        startCursor
        endCursor
        hasNextPage
        hasPreviousPage
      }
      edges {
        node {
          id
          userId
          firstName
          lastName
          friends {
            edges {
              node {
                id
                userId
                firstName
                lastName
              }
            }
          }
        }
      }
    }
  }
}

Testing out API-Gateway locally

To test API-Gateway locally, you'll need to install AWS SAM Local.

$ sam local start-api

This will serve the Lambda function over a local web server [http://127.0.0.1:3000]

Deploying the serverless application

Remove development dependencies before we build the project.

$ pipenv --rm

Install only runtime dependencies.

$ pipenv install --three

Run the build command. This will create the package in build folder.

$ pipenv run ./cli.py build

Run CloudFormation command to send the package to an S3 bucket. Be sure to have the AWS CLI tools & credentials installed. This will generate a template.deploy.yml which we will deploy with using CloudFormation.

$ aws cloudformation package \
  --template-file template.yml \
  --s3-bucket you-s3-bucket \
  --output-template-file template.deploy.yml

Run CloudFormation deployment.

$ aws cloudformation deploy \
  --template-file template.deploy.yml \
  --parameter-overrides EnvironmentName=my-graphql \
  --capabilities CAPABILITY_IAM \
  --stack-name my-graphql

Cleaning up

Remove local build stuff.

$ pipenv run ./cli.py clean

Remove python virtual environment.

$ pipenv --rm

You can remove the CloudFormation stack in the AWS Console

demo-aws-graphql-python's People

Contributors

ivanchoo avatar

Watchers

Pushkar Varma avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.