MongoDB Atlas is a modern Developer Data Platform with a fully managed cloud database at its core. Atlas is the best way to run MongoDB, the leading non-relational database. It provides rich features like flexible schema model, native timeseries collections, geo-spatial data, multi level indexing, RBAC, isolated workloads and many more–all built on top of the MongoDB document model.
MongoDB Atlas App Services help developers build apps, integrate services, and connect to their data without operational overhead utilizing features like hosted Data API and GraphQL API. Atlas Data API allows developers to easily integrate Atlas data into their cloud apps and services over HTTPS with a flexible API. Atlas GraphQL API lets developers access Atlas data from any standard GraphQL client with an API that generates based on your data’s schema.
AWS AppSync is an AWS product that allows developers to build GraphQL and Pub/Sub APIs. With AppSync developers can create APIs that access data from one or many sources enabling real-time interactions in their applications. The resulting APIs are serverless making it possible for the client to query only for the data it needs, in the format it needs, and pay only for the requests and the real-time messages delivered.
Authentication and Authorization through Amazon Cognito Simple, Secured, Easy GraphQL APIs Caching to improve performance End-to-end serverless architecture AutoScaling based on API request volumes Subscriptions to support real-time updates
Developer Tool: VSCode, AWS CLI, Docker, Postman
Please follow the link to setup a free cluster in MongoDB Atlas
Configure the database for network security and access.
create documents for customer and risk . please refer the sample structure for CounterParty and CounterPartyRisk documents.
Create the Data APIs using the link
Copy the API Key and MongoDB Credentials to a local JSON file. Template for the JSON files shown in the link: mycreds.json & myapikey.json
aws secretsmanager create-secret --name <secret_name> \
--description "MongoDB secrets created for AWS AppSync" \
--secret-string file://mycreds.json
aws secretsmanager create-secret --name <secret_name> \
--description "API Keys secret created for AWS AppSync" \
--secret-string file://myapikey.json
aws ecr create-repository \
--repository-name partner_atlas_appsync_int \
--image-scanning-configuration scanOnPush=true \
--region <aws_region>
The code base contain 3 repos: data_api_appsync, driver_appsync (datasource_create & datasource_read). Copy the appropriate code to the VSCode.
Note: AWS ECR repositories and Lambda functions are to be created for each of the 3 repos, viz: data_api_appsync / driver_appsync (read / create)
update the DATA API endpoints and the database credentials appropriate for your requirement.
create the docker image
aws ecr get-login-password --region <aws region> | docker login --username AWS --password-stdin <accountid>.dkr.ecr.<aws region>.amazonaws.com
docker build -t partner_atlas_appsync_int . --platform=linux/amd64
docker tag partner_test:latest <accountid>.dkr.ecr.<aws region>.amazonaws.com/partner_atlas_appsync_int:latest
docker images
docker push <accountid>.dkr.ecr.<aws region>.amazonaws.com/partner_atlas_appsync_int:latest
aws lambda create-function --region <aws region> --function-name partner_atlas_appsync_int \
--package-type Image \
--code ImageUri= <accountid>.dkr.ecr.<aws region>.amazonaws.com/partner_atlas_appsync_int:latest \
--role <Lambda execution role ARN>
pls check the link for reference code
Note: Ensure the lambda function is having adequate permission to read from the secret manager.
- Choose Build from scratch and hit Start, for getting a blank API.
- Add API Name
- Click on Schema form the left navigations
- GraphQL Schema can be built with Queries and Mutations and click Save Schema
- Click on Data Sources from the left navigations and hit Create data source
- Attach Lambda function which contains MongoDB driver code for quering the data (Multiple data sources can be added based on requirements)
- Go to schema and attach resolvers for Mutations and Queries
- Select lambda data source added in previous step, and click save.
Goto Queries and select the query to execute, hit Run button and you should see your query result on the right side.
-
Click on settings and create a curl API as below.
curl --location --request <CRUD OPERATION> <API URL> --header 'Content-Type: application/graphql' \ --header 'x-api-key: <API KEY> \ --data-raw '{"query": <QUERY>}'
- Goto Postman and import the curl command and hit send to get the response.
This solution can be extended to AWS Amplify for building mobile applications.
For any further information, please contact [email protected]