Reputation: 3836
I created an Amazon Aurora Postgres DB on my AWS account, and am now trying to connect to it using PgAdmin. I enter in the db name, username, password, and host, and port. When I try to connect I get this issue.
Unable to connect to server:
could not connect to server: Operation timed out
Is the server running on host "host_name.us-east-2.rds.amazonaws.com" (IP Address) and accepting
TCP/IP connections on port 5432?
I'm new to Amazon Aurora, and am not sure what my next step has to be to connect. I read the documentation, but can't find what I'm looking for. I'm also getting the same error when I try to connect to it with my production server that houses my Django application.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbname',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'hostname.us-east-2.rds.amazonaws.com',
'PORT': '5432'
}
}
And I'm getting a similar issue
django.db.utils.OperationalError: could not connect to server: Connection timed out
Is the server running on host "hostname.us-east-2.rds.amazonaws.com" (IP Address) and accepting
TCP/IP connections on port 5432?
Upvotes: 1
Views: 4636
Reputation: 126
One thing to keep in mind with aws RDS is that if you using capacity type(mean role) as the serverless type which means AWS RDS will manage to compute the capacity of the DB instance to match your application's usage. There will be other things also in serverless. And this makes your server not public accessible(same as ElasticCache) but can connect using Data API or put your EC2 instance/lambda function inside the same VPC in which this database lies.
Upvotes: 1
Reputation: 136
I posted this answer to a similar question about PostgreSQL here, and thought this may be helpful even with Aurora: django cannot connect to RDS postgresql
When you're trying to use an existing RDS database with Django on EC2 or EB, you'll have to adjust the security groups, and then get the proper parameters and set them as environment variables (RDS_*)
1) Create RDS, and match these up:
Environment variables - RDS console label
RDS_HOSTNAME - Endpoint (this is the hostname)
RDS_PORT - Port
RDS_DB_NAME – DB Name
RDS_USERNAME – Username
RDS_PASSWORD – Password you set for your DB
2) Set those using, for example, eb setenv
3) Go to your EC2/ EB instance and get the security group for that e.g. awseb-z-afsafdsaf-stack-AWSEBSecurityGroup-asfdsadfasdf
and for the load balancer: awseb-e-adsfadsf-stack-AWSEBLoadBalancerSecurityGroup-asdfadsf
4) Go to the panel for your RDS instance, scroll down to Security Groups and take note of which security group it has. e.g. rds-launch-wizard-1 (ab-sdjfalkajsdf39)
5) Click modify for the RDS instance, and in the Security Groups setting in the middle, add the load balancer security group you found above. It should have suggestions.
6) Go to the EC2 Dashboard and choose security groups from the menu on the left.
7) Select the load balancer security group, and add an Outbound rule. Type should be your RDS type (PostgreSQL) and the destination should be custom & the RDS instance's security group. Save.
8) Do the same for Inbound, use the same RDS type & Destination
9) Select the RDS security group, and add an Inbound rule, similar to 8, but using the EC2 or EB instance that you got in step 2.
10) Save, you're done. They should be able to work together now.
I'm not 100% certain all these steps are necessary, one or two might not be, but this got the job done for me.
Upvotes: 0
Reputation: 3800
You should add the IP you are trying to connect from under Security Groups in EC2 to your RDS' security group as incoming mysql connection
Upvotes: 3