How to connect Amazon AWS API Gateway to Amazon RDS? - amazon-web-services

I have an Amazon AWS RDS (PostgreSQL) database. I am trying to connect it to Amazon API Gateway as simply as possible (AWS Service WITHOUT Lambda).
I am trying to perform a simple get request. To get all "animals" (table name "animals") from the db.
The question is which Action to select. All actions in the documentation change the db. And I need only to perform a simple GET request.
Also we need to setup the policy and specify the actions for it.
Api Gateway request:
https://i.ibb.co/2hkdVqZ/AWS.png
Api Gateway Policy:
https://i.ibb.co/vk8pLzd/AWS2.png

The AWS API is for creating/changing the DB server itself, as you have mentioned. You can't query the RDS database directly from the AWS API. You have to create a DB connection to the PostgreSQL database using traditional database drivers in order to run queries against the database.
You will need to use a Lambda function to accomplish what you are trying to achieve.

Related

Best practices when connecting to AWS RDS with Lambda + pymysql?

I'm trying to create a setup with AWS where users can hit an API endpoint -> Lambda function connects to Aurora serverless DB.
This guide https://levelup.gitconnected.com/aws-lambda-with-rds-using-pymysql-23ad3cde46c8 is suggesting I put
conn = pymysql.connect(host=rds_host,user=name,passwd=password,db=db_name,...)
at the start of the lambda function. My worry is that every API request will create a new connection to the database, not sure if that is ok? I know that when locally performing operations, there is such a thing as creating a connection pool. Is there a recommendation on how/when this is needed on AWS Lambda?
Please review article below to Demystifying Lambda functionality and how handle the request executions
https://harishkm.in/2020/06/30/demystifying-database-connection-pools-in-aws-lambda-functions/
Also links below explain you how AWS Aurora handles the connection
https://docs.aws.amazon.com/whitepapers/latest/amazon-aurora-mysql-db-admin-handbook/connection-management-and-pooling.html
https://docs.aws.amazon.com/whitepapers/latest/amazon-aurora-mysql-db-admin-handbook/connection-handling-in-aurora-mysql-and-mysql.html
Regarding pymysql, you could use boto3 AWS SDK library instead of pymysql, it provides you better integration with AWS Services like AWS Lambda,AWS IAM and AWS Secret Manager as best practices
import boto3
rds_client = boto3.client('rds-data')
Review link below.
https://aws.amazon.com/blogs/database/using-the-data-api-to-interact-with-an-amazon-aurora-serverless-mysql-database/
Finally if your API traffic will be high, consider use scalable solutions as AWS RDS Proxy to help you to manage your database connection at scale, review links below.
https://aws.amazon.com/blogs/database/scale-modern-serverless-applications-with-amazon-rds-proxy-for-sql-server/

Is it possible/practical to host an SQLite or similar relational DB in AWS S3, accessed from Lambda+api gateway for low-traffic websites?

I am looking for access to a relational database that is "serverless" for use in a low traffic website where the API is via lambda + api gateway.
The objective being creating an end-to-end serverless application.
I have investigated Athena - however all documentation points to avoiding it's usage as a serverless database.
Could one host an SQLite DB in S3 and interact with it via a lambda function?

How to use endpoint for dynamodb table?

I don't need to set up the DAX cluster which already provides an endpoint to connect to. I only need to connect to this dynamodb table from an internal service. But the table doesn't expose a URL to connect to. Can someone help?
You just use AWS SDK's dynamodb interface, e.g. client in boto3. All the endpoints for the dynamodb are already provided by default in the SDKs, so you don't have to explicitly specify it.
The endpoints for dynamodb are listed here.

aws amplify work with documentdb or document type nosql database

So I am relatively new to AWS and AWS Amplify helped me write my backend app a lot. I know AWS Amplify does offer a NoSQL database direct connection, but that's connected to DynamoDB, which is also a NoSQL database, but it's not the type of NoSQL database I want. I want document type BSON NoSQL database. I was wondering is there any easy way to connect to AWS DocumentDB or MongoDB using AWS Amplify or do I need to use aws-sdk or something else for that? Thanks
You can create a GraphQL API for Amazon DocumentDB and use this API as your amplify backend application as explained in this documentation.
To create a GraphQL API for Amazon DocumentDB, you can use Lambda resolvers. Please refer to tutorial on using Lambda Resolvers here.
Amazon DocumentDB connection and related queries will be defined in the lambda function.

Query an AWS RDS Database(Mysql) through AWS API Gateway and Lambda?

So I have a RDS Database server running Mysql engine, Now I need to query into this database through my mobile app based on Flutter.
The solution after some research I came up with was to create a Lambda function and hook it up to RDS and API Gateway Service. The deployed API would be used by the app.
But I need some help on this regarding how to set this up. Any good alternatives, reference materials or videos would be helpful.
Can you help me out?