How To Deploy GraphQL API Using AWS Lambda And AWS API Gateway ?
Last Updated :
04 Jan, 2025
GraphQL is known for its flexibility and efficiency. AWS Lambda, on the other hand, provides a serverless computing service that allows developers to run code without managing servers, and we pay for what we use. We can combine the power of GraphQL with the scalability and ease of AWS Lambda to serve our GraphQL application easily with minimal steps & efforts possible.
In this article will take you on a step-by-step guide to deploy your own GraphQL API using AWS Lambda and AWS API Gateway, we'll guide you how to define schema, write resolvers for the queries & mutations, configue urls, and deploying the API, testing.
What Is GraphQL?
GraphQL is a query language and runtime for APIs (Application Programming Interfaces). It provides a more efficient, powerful, and flexible alternative to the traditional REST API (Representational State Transfer), It was developed by Facebook and it's an open-source technology.
What Is AWS Lambda?
AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS). we can create functions and self-contained applications.
With AWS Lambda functions we can perform any kind of computing task, from serving web pages to building backend APIs, and we can integrate lambda with other AWS services as well, here in this article, we are integrating lambda with API Gateway.
AWS API Gateway
Amazon API Gateway is a fully managed service facilitating effortless creation, publication, monitoring, and securing of APIs. Serving as the "front door" for applications, it supports access to backend services via RESTful and WebSocket APIs, providing to real-time communication needs. With features like request management, authorization, and monitoring.
API Gateway provides integration with various services like AWS Lambda, DynamoDB, etc and also you integrate your HTTP endpoint, and you know AWS provides free 1 million API calls per month for 12 months with the AWS Free Tier.
Why We Choose AWS Lambda?
Also, there are several reasons why we choose AWS Lambda over other choices like AWS EC2, Elastic Bean Stalk, etc for deploying our Django application:
- Cost-Effective: AWS Lambda is a cost-effective option when compared to other services we've.
- Integration With Other AWS Services: AWS Lambda has support for various other AWS services, we can integrate them easily such as API Gateway, Event bridge, etc, which makes it easy to deploy.
- No Server Management: With AWS Lambda, we don't have to worry about managing the infrastructure, as AWS takes care of it for us. and we going to use Zappa for deploying our Django application to AWS Lambda.
Deploying GraphQL Using AWS Lambda And AWS API Gateway: A Step-By-Step Guide
There are many ways to deploy GraphQL API, In this article we're going to deploy Django Based GraphQL API using AWS Lamda and API Gateway, as part of this we'll be using third party python packages as well.
Graphene-Django is an open-source library that provides seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The library allows developers to create GraphQL APIs in Django quickly and we can easily integrate this with AWS Lambda without any external dependencies.
Step 1: Install graphene-django
- Run the below command to install graphene-django.
pip install graphene-django

Step 2: Configure Django Settings
- After installing, add 'graphene_django' to your Django project's INSTALLED_APPS list, and also configure the graphql schema path for your app using GRAPHENE variable.
INSTALLED_APPS = [
...
'graphene_django',
]
GRAPHENE = {
'SCHEMA': 'myboringapp.schema.schema'
}
Note: Replace your app name in the place of myboringapp.
Step 3: Configure Urls
- Configure the url path /graphql to access your apis, (the below config is useless without configuring GRAPHENE in django settings)
from django.urls import path
from graphene_django.views import GraphQLView
from . import schema
urlpatterns = [
...
path('graphql/', GraphQLView.as_view(graphiql=True)),
]
Step 4: Define Schema
- In the myboringapp/schema.py, define the schema for your APIs, here is the sample API schema:
Here we've defined a schema with one query get_hello, resolver will return "Hello, GeeksForGeeks" in response for that query, resolvers are responsible for populating the data for each field, here you can consider get_hello as a field for easy understanding, when get_query is triggered via API, the resolver will return the data defined in it or by processsing the business logic.
import graphene
from graphene_django import DjangoObjectType
class Query(graphene.ObjectType):
get_hello = graphene.String(description='A simple greeting')
def resolve_get_hello(self, info):
return 'Hello, GeeksForGeeks!'
schema = graphene.Schema(query=Query)
Step 5: Deploy Application
Note: For more details on Deployment, visit How to Deploy Django Application in AWS Lambda?
- we are all set for deployment, we configured our app with the required things, and now we can deploy our application to AWS Lambda.
- Here the below command will bundle your application along with your project requirements and deploy it in AWS Lambda.
zappa deploy <stage>
- The above command will create a Lambda function with our Django application code and integrates it with API Gateway so that we can invoke the Django API.
-(1)-768.png)
Testing
We can use the below query to test our deployment, the below will ask API to return the response for the `getHello` query as we've defined it as string response with "Hello, GeeksForGeeks!", we'll get that in response.
To test your graphql query, you can use apollo sandbox, just provide your deployed endpoint there, and use the below query and click on GetHelloFromGFG, below is the reference.

Conclusion
We've deployed a Serverless Django GraphQL API using AWS Lambda & API Gateway, we've learnt how to define schema and expose API endpoints using graphene django, you can also try adding more queries, mutations, and deploy a complex APIs as well using this method.
Similar Reads
Build an API Gateway REST API with Lambda Integration
Pre-requisite: AWS Amazon Web Services is a leading cloud provider which provides us with plenty of Paas, and Iaas, and services that we can use to build and deploy our applications. we going to build and Deploy a REST API with API Gateway which is integrated with AWS Lambda and expose GET and POST
4 min read
How To Build Real-Time Chat Application With AWS AppSync And GraphQL
AWS Live Chat is a service provider that provides a serverless, scalable, and secure chat application. AWS Lambda resolves the tasks by performing the necessary data transformations before sending the data to the client. Alternatively, It also gives a reliable query language for APIs that helps in e
10 min read
How to Deploy Django Application in AWS Lambda?
Pre-requisite: AWS , Python Django is a Python web framework that makes it easy to build web applications quickly and securely. It has a large and helpful community that provides support and contributes to its development. AWS Lambda is a serverless computing platform that runs your code in Docker c
7 min read
AWS Lambda - Create a Lambda Function in Python, Integrated with API Gateway
Pre-requisite: AWS We will begin with creating a lambda function in the AWS Lambda console and write our Python code for the same. We will test our function by creating the new event and verifying the response. Next, we will configure the lambda function with the JSON placeholder which is a sample A
3 min read
How to Duplicate an AWS Lambda Function
AWS Lambda is a serverless computing technology made by Amazon Web Services, that allows one to run a piece of code without any need of maintaining a server. This makes it an ideal choice for various applications, from simple task automation to complex backend services. However, there may be a need
4 min read
AWS DynamoDB - Insert Data Using AWS Lambda
In this article, we will look into the process of inserting data into a DynamoDB table using AWS Lambda. Amazon DynamoDB is a completely owned NoSQL proprietary provider that helps key-value and textual statistics systems and is supplied via way of means of Amazon.com as a part of Amazon Web Service
3 min read
Building a Serverless Blog with AWS Lambda and API Gateway
AWS Lambda is a serverless computing service offered by AWS. It enables you to run code in response to events without the need to manage servers. This event-driven service charges you based on actual compute time, making it cost-effective. Lambda supports various programming languages, scales automa
9 min read
How to Integrate and Call a GraphQL API in a Java Spring Boot Application?
GraphQL is a more flexible query language and runtime for APIs that lets clients request exactly the data they need by making data fetching more efficient. Compared to REST, GraphQL allows clients to define the exact structure of the response, making data retrieval smoother and more efficient. Integ
8 min read
How to Use AWS Lambda Function to Access an Amazon RDS Database?
AWS lambda is a managed serverless deployment service of AWS which can be used for implementation of various applications in cloud. AWS RDS is relational database management system that supports various vendors. In this article we will see how we can create and access Amazon RDS database through a l
6 min read
AWS Application Load Balancer Using Terraform
In contemporary cloud infrastructure setups, managing and distributing incoming traffic effectively across various instances is central to ensuring the high accessibility and scalability of applications. Among the bunch of services given by AWS (Amazon Web Services), Elastic Load Balancing (ELB) sta
10 min read