![]() It’s not a good idea to leave permissions open to the public internet for security reasons. In the screenshot above, you can see that I added a specific line allowing authentication from another EC2 Instance in AWS. In this specific Linux server, we need to edit **/var/lib/pgsql/data/nf**. Bear in mind that by default, PostgreSQL is only accepting connections from localhost at the moment.Īs I mentioned, at the moment, we can only connect to our DB server from localhost, so if we want to run our application code in a different server, we need to configure the server to listen outside TCP connections. I have edited mine as you can see in the screenshot, I’m not using custom username/passwords, but you can tweak yours as you need. In this specific version of Linux, the file that we need to edit is **/var/lib/pgsql/data/pg_hba.conf**. Client authentication is controlled by a configuration file, which traditionally is named pg_hba.conf and is stored in the database cluster’s data directory. To be able to connect to PostgreSQL, we still have to configure authentication. # To check if the Postgres service is running or not $ sudo yum install postgresql-server postgresql-devel # Install PostgreSQL server and initialize the database $ sudo amazon-linux-extras enable postgresql11 # Enable the repository to install PostgreSQL pem file for SSH authentication to ~/.ssh and assign the right permissions running the following command in your terminal: Once your setup is ready, launch your instance, wait until it is running, so we can connect via SSH. To connect to the DB server from my local laptop, I use SSH TablePlus easily connects to your DB via SSH. But if you’re going to have another EC2 instance with your application code, then I’d suggest opening your DB port (5432) only to your “Web Security Group”. Depending if you are planning to host your application code in this same server or a different one, you will need to open this port or not. Next, I’ll configure the security group to allow SSH access and PostgreSQL access on port 5432. I’ll be using Amazon Linux 2 ARM.įor instance type, I’ll be using t4g.micro, which is free while it’s not generally available until the end of March 2021. Make sure to select the ARM architecture. Log in to the AWS EC2 console and provision a Linux server to host the DB. micro EC2 instance costs about $6 per month. ![]() So if you’re running a side project and only need a simple single host setup, I think this approach is a perfect solution, using a t4g. I’m also using one of the new ARM instances, a similar technology to the new Apple ARM CPUs but running on the server. The main reason is COST this option is roughly half of the RDS price. The first thing you might wonder is why you would want your database in an EC2 instance when you have a managed service (RDS) where you don’t have to bother with maintaining your server, updating it, and having automated daily backups with one click. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |