This project demonstrates the use of Serverless Framework to create a Node.js Lambda function, and it includes a GitHub Actions workflow for automated deployment into Apollo Studio and AWS.
This Serverless Framework project showcases the implementation of a Node.js Lambda function. Additionally, it includes a GitHub Actions workflow for seamless deployment into Apollo Studio and AWS Lambda.
- Node.js Lambda function
- Serverless Framework configuration
- GitHub Actions deployment workflow
- Integration with Apollo Studio
- Deployment to AWS Lambda
Follow these steps to set up and run the project locally.
Make sure you have the following tools installed:
- Clone the repository:
git clone [email protected]:JordanDabricot/serverless-lamdba-apollo-graphql-boilerplate.git
cd serverless-lamdba-apollo-graphql-boilerplate
- Install and run the project
npm install
docker compose up
Go to http://localhost:10007/graphql
Create a Lambda function using the AWS Lambda service. This function will contain your Node.js code. You can upload your code directly or use an S3 bucket for deployment.
Create an API Gateway to expose an HTTP endpoint that triggers your Lambda function. This is done by creating a new REST API and defining resources, methods, and integration settings.
Create a new REST API. Define a resource (e.g., /items) and create a method (e.g., POST for creating items). Connect the method to the Lambda function as the integration point.
Create a DynamoDB table to store data. This table will be used by your Lambda function to read or write data. Create a new DynamoDB table. Define the primary key(s) for your table. Adjust the read and write capacity based on your expected workload.
Set up IAM roles to grant permissions to your Lambda function and API Gateway to interact with other AWS services.
Create a role for the Lambda function with permissions to log to CloudWatch and read/write to DynamoDB. Create a role for the API Gateway to invoke the Lambda function.
+--------------------------------------+
| |
| Amazon API Gateway |
| |
+------------------+-------------------+
|
| API Gateway URL
v
+--------------+ +-------------+ +----------------------+
| | | | | |
| Router | | API Gateway | | AWS Lambda Function |
| (Apollo) +------------>| Resource +-----------> Node.js Code |
| | Request | / | | |
+--------------+ +-------------+ +-----------+----------+
|
| DynamoDB
v
+----------------------+
| |
| Amazon DynamoDB |
| (UserExampleTable) |
| |
+----------------------+
Explanation:
-
Client (Web Browser): Initiates an HTTP request to the API Gateway URL.
-
Amazon API Gateway: Receives the HTTP request and forwards it to the specified resource (/items). It triggers the associated Lambda function.
-
AWS Lambda Function: The Node.js code in the Lambda function is executed. It processes the data, interacts with DynamoDB (e.g., inserts, updates, retrieves data), and returns a response.
-
Amazon DynamoDB: Stores and retrieves data as needed by the Lambda function.
-
This diagram provides a high-level overview of the flow of data from the client through the API Gateway to the Lambda function and DynamoDB. The specific details, such as the API Gateway configuration, Lambda function code, and DynamoDB table structure, may vary based on your project requirements.