AWS elastic beanstalk Node.js app is not connecting to Mongodb atlas - node.js

I am trying to connect to MongoDB atlas from elastic beanstalk using a Node.js app. on Mongo atlas, I opened the connection publicly for testing reasons (added 0.0.0.0/0 to the whitelist) and AWS security group allows all traffic.
I still can connect to MongoDB atlas from my localhost but not from AWS EBS.

Even I have faced the same issue and it solves by restart the aws elastic beanstalk instance.
Actually, we open do MongoClient.connect once when your app boots up
and reuse the db object. It's not a singleton connection pool each
.connect creates a new connection pool.
So for that purpose, we have to restart the instance and it will work but for the security purpose, we can try VPC Peering for MongoDB Atlas.
Hope this will help some one else..!!

Related

Connect to AWS RDS Aurora for Postgres from Node JS

I have a Node JS application hosted on EC2 instances that I am trying to connect with an RDS Aurora Postgres cluster. The cluster consists of 1 writer and 2 readers. I have whitelisted the security group attached to the EC2 instances as an ingress rule on the security group associated with the database cluster which allows the EC2 instances to communicate with the database in the cluster.
I am having some issues connecting the application on the EC2 instance to the database. I have read this link, but that discusses using a JDBC driver in order to connect the database. I'm not sure if I can use a JDBC driver to allow a Node JS application to connect to this database cluster. I'm not finding any useful examples to connect a Node app to Aurora Postgres.
Any advice on connecting Node JS to Aurora Postgres DB cluster would be helpful.

Connecting AWS Elastic Beanstalk to MongoDB with a connection string

I have deployed a Node.JS REST API to AWS Elastic Beanstalk which fetches data via HTTP requests from a MongoDB database (using just the connection string for that, not atlas or anything).
When I run it locally it works fine, but when I try to use the AWS address and run it from there I'm getting a 504 Gateway Time-out error. I don't know what causes this issue and would appreciate some help!

How to connect to AWS ElastiCache Cluster from AWS CloudFront using Node.js?

I am new to AWS CloudFront and AWS in general. I have a Next.js (React SSR framework) website which I deployed onto AWS using serverless-nextjs (https://github.com/serverless-nextjs/serverless-next.js). However, I also need some sort of caching for my web app. I decided to use redis ElastiCache from AWS. I created an redis ElastiCache Cluster on the AWS console.
My attempt:
I setup the code for connecting to the redis ElastiCache like this:
import redis from 'redis';
...
export async function getServerSideProps() { // Server side function for Next.js
const cache = redis.createClient(6379, "{PRIMARY-ENDPOINT-URL-AWS}");
}
and I run the website locally on my PC. However, I get a timeout error from redis: Error: connect ETIMEDOUT.
How would I be able to connect to the redis ElastiCache Cluster from CloudFront and on my local PC?
Screenshot of the redis ElastiCache Cluster window:
redis ElastiCache
You can't connect to ES from outside (i.e. your local workstation) of AWS directly. ES domains are designed to be only accessible from within your resources (e.g. instances) in the same VPC as your ES domain. From docs:
Elasticache is a service designed to be used internally to your VPC. External access is discouraged due to the latency of Internet traffic and security concerns. However, if external access to Elasticache is required for test or development purposes, it can be done through a VPN.
The only way to enable connections from outside AWS to your ES is if you establish a VPN connection between home/work network or Direct Connect as explained in AWS docs:
This scenario is also supported providing there is connectivity between the customers’ VPC and the data center either through VPN or Direct Connect.
However, for quick, ad-hock setup you can use ssh tunnel between your local workstation and ES domain. This will require some jump/basion EC2 instance which the tunnel will go through.

Connect MongoDB to NodeJS on GAE

I'm running a NodeJS app on GAE and I want to connect to a mongodb cluster on Atlas.
I have white-listed my IP on atlas and established a connection. All work fine on my local machine.
When deployed my app on GAE it could not connect to Atlas since the IP is not white-listed. When I white-listed all IPs on Atlas I could make a connection and everything worked fine as on my local machine
I cannot assign a static-IP to a standard GAE app, therefore I must allow access from anywhere to my cluster on Atlas, which is probably a bad idea.
What would be best solution to work with mongoDB from a GAE standard app?
Any configuration I can make to Atlas? maybe switching to mLab? or any other ideas?
App Engine applications do not have fixed IP addresses. I'm not very familiar with MongoDB Atlas, but it does look like it offers an option to run on GCP and if that runs on a Compute Engine instance what you might be able to do is use the VPC Connector to enable access between your app and your MongoDB setup.

How to connect to MongoDB hosted on Google Cloud

I just created a MongoDB instance on Google Cloud.
I have been using mLab for my purpose and I was able to connect to that DB using IPAddress: PORT and user/password combination.
How to connect to MongoDB instance using IP Address and port number? Where can I find these details in my VM Instance?
I also want to connect to same DB through my NodeJS app using mongoose. How can I do that?

Resources