Docs Menu
Docs Home
/
Atlas
/ /

Manage Data on Your Atlas Cluster Using AWS AppSync Lambda Resolvers

You can manage data on your Atlas cluster using AWS AppSync Direct Lambda Resolvers. The Lambda function, serving as a resolver for the AWS AppSync GraphQL API, enables seamless CRUD operations on your data in your Atlas cluster. Integrating Atlas with AWS AppSync offers a powerful, flexible solution for building scalable, serverless GraphQL APIs.

This integration not only reduces the complexity of managing multiple data sources, but also enhances the development experience by providing a unified and flexible platform for modern application architectures. Whether you're handling CRUD operations or optimizing payloads, this integration enables you to build scalable, efficient, and cost-effective APIs.

This page walks you through the following steps:

  1. Deploy the CloudFormation stack that contains the Serverless Lambda function and an AWS-managed AppSync GraphQL API.

  2. Test the AppSync API by running queries from the AWS AppSync API console or Postman.

Before you begin, you must do the following:

  • Deploy an Atlas cluster

  • Configure the database for network security and access

  • Set up an AWS account with access to the AWS Management Console

1
  1. Log in to the AWS Management Console and navigate to Applications, which is located on the left sidebar within the AWS Lambda console.

  2. Click Create application and then select the Serverless application tab.

  3. Type MongoDB-AppSync-App in the search bar and then select the checkbox to show apps that create custom IAM roles or resource policies.

  4. Click the MongoDB-AppSync-App App in the search results.

  5. Paste the Atlas connection string in the AtlasConnectionString field under Application settings.

  6. Select the checkbox to create IAM roles and click Deploy to deploy the CloudFormation stack.

    The CloudFormation stack initiates the creation of:

    • A Lambda function containing the essential logic required to resolve queries from the AppSync API.

    • An AppSync GraphQL API containing a schema that defines Queries and Mutations. These Queries and Mutations are linked to the Lambda function established by the CloudFormation stack.

    When the deployment completes, copy the following in the Outputs section of the CloudFormation stack:

    • GraphQLApiKey, which is the AppSync API Key

    • GraphQLAPIURL, which is the AppSync API URL

    • LambdaFunction, which is the ARN of the Lambda Function

2

You can use the AWS AppSync console or Postman to test the AppSync API.

The API request and response payloads must be in the MongoDB Atlas Data API (v1) format. Each query must include the necessary request query and body parameters. To learn more about the Data API syntax, see MongoDB Atlas Data API (v1):

  1. Log in to the AWS Management Console and navigate to the AWS AppSync page.

  2. Click the link to the MongoDB-AppSync-SAM_API.

  3. Click Queries in the left navigation under MongoDB-AppSync-SAM_API.

  4. Select the Explorer (third icon) under Queries.

  5. Select the type of query and enter the query.

    You can run any of the following types of query:

    • aggregate

    • find and findOne

    • insertOne and insertMany

    • updateOne and updateMany

    • deleteOne and deleteMany

    If you type the query in the input field, the escape characters are automatically added to your query.

  6. Click the play button to run the query.

    The output contains escape sequence characters. We recommend implementing a logic in your application to convert the escape sequence into JSON.

  1. Download the Postman collection named postman.json from GitHub.

  2. Open Postman and click Import.

  3. Complete the steps to import the downloaded postman.json file.

  4. To query, do the following:

    • Send POST request to the GraphQLAPIURL.

    • Authenticate with GraphQLApiKey.

  5. Click Try to run the query.

Back

Verified HashiCorp Terraform Example

On this page