I have an RDS instance that I can connect through command prompt as follows:
mysql --host=rds-instance-name.ciplxctxy9hy.us-west-1.rds.amazonaws.com --user=username --password=password database
This works well. When I attempt to eb deploy to the Amazon Web Services elastic beanstalk instance, I get this error:
INFO: Deploying new version to instance(s).
ERROR: [Instance: i-08388abd] Command failed on instance. Return code: 1 Output:
(TRUNCATED)...ash -c 'leader_only bundle exec rake db:migrate' webapp
rake aborted!
Mysql2::Error: Can't connect to MySQL server on 'rds-instance-name.ciplxctxy9hy
.us-west-1.rds.amazonaws.com' (4)
My database.yml file in my ruby instance has the following:
production:
adapter: mysql2
encoding: utf8
database: database
username: username
password: password
host: rds-instance-name.ciplxctxy9hy.us-west-1.rds.amazonaws.com
When I locally start the ruby server, I get no errors:
C:/Development/Ruby/environment-name/bin/rails server -b 0.0.0.0 -p 3000 -e production
What do I need to change to the rds instance or to the database.yml to allow me to deploy?
I would look at the security group on the RDS instance and make sure it's allowing incoming connections from your EC2 instance.
Related
I'm attempting to connect to a local Postgres server running as a docker container from my Lambda function.
I'm using the sam local invoke call to do so.
For some reason, it seems that outgoing connection from SAM's docker container for the function is disabled.
I'm getting this error message:
"errorMessage": "(psycopg2.OperationalError) could not connect to server: Connection refused\n\tIs the server running on host \"localhost\" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432?\ncould not connect to server: Cannot assign requested address\n\tIs the server running on host \"localhost\" (::1) and accepting\n\tTCP/IP connections on port 5432?\n\n(Background on this error at: http://sqlalche.me/e/e3q8)",
Is there a way to enable a Lambda function call to a local docker database?
I have no issues running the connection code outside the Lambda function as standard Python code - so I'm sure my database is up, my code works, etc.
Try running the command with —docker-network TEXT per the AWS SAM CLI documentation.
I had a similar issue attempting to run sam local start-api with a local Docker Postgres database and was getting connection refused errors. I ran sam local start-api —docker-network host and it resolved the issue.
This is a good post which helped me to understand more about Docker networks.
Hope this helps you and any others looking at this.
I resolve this by replacing localhost with host.docker.internal.
For example if you use psycopg2
conn = psycopg2.connect(host="host.docker.internal",port=5432, ...)
I want to connect to an aurora serverless database from my local machine. Because the database is only accessible from within the aws cloud, I have setup an ec2 instance running microsocks:
./microsocks -p 8888
I now want to connect using mysql from my machine:
export ALL_PROXY=socks5h://xx.xx.xx.xx:8888
mysql --user=admin --password=XXXX -h database-XXXX.cluster-XXXX.eu-XXXX.rds.amazonaws.com
ERROR 2003 (HY000): Can't connect to MySQL server on 'database...com' (111)
If I run this command on the ec2 instance it succeeds. So I assume that mysql does not respect my proxy settings. If I run curl on my machine it respects the proxy settings.
Note that this is just for testing purposes and I know that this would not be a solution for production use.
You may use proxychains.
yum install proxychains-ng
edit config file /etc/proxychains.conf, and add this:
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks5 {your proxy.address} {your.proxy.port}
Lastly, you can run mysql like this:
proxychains mysql --user=admin --password=XXXX -h database-XXXX.cluster-XXXX.eu-XXXX.rds.amazonaws.com
I am trying to deploy my Dropwizard project to Heroku.
I have added a Procfile and a Postgres DB to the Heroku app.
My Procfile reads:
web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -Ddw.database.url=$DATABASE_URL -jar target/api-1.0-SNAPSHOT.jar server config.yml
When I try to deploy I receive the following error/crash message in the logs.
org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: HHH000342: Could not obtain connection to query metadata : Driver:org.postgresql.Driver#53d13cd4 returned null for URL:postgres://fdeqzbddzbefaz:138912590e989b1b8fab5d169a1aea291f04b2d3bc040b1bbf6642a9207a5355#ec2-54-235-101-91.compute-1.amazonaws.com:5432/d67crr4pvqrfee
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
State changed from starting to crashed
Process exited with status 1
My config.yml reads
database:
# the name of your JDBC driver
driverClass: org.postgresql.Driver
# the username
user: localusername
# the JDBC URL
url: jdbc:postgresql://localhost/dbname
# use the simple server factory if you only want to run on a single port
# HEROKU NOTE - the port gets be overridden with the Heroku $PORT in the Procfile
server:
type: simple
applicationContextPath: /
#adminContextPath: /admin # If you plan to use an admin path, you'll need to also use non-root app path
connector:
type: http
port: 8080
Does anyone have any trouble shooting ideas?
The DATABASE_URL env var is not directly compatible with the JDBC URL format. See docs. Specifically,
The DATABASE_URL for the Heroku Postgres add-on follows the below convention
postgres://username:password#host:port/dbname
However the Postgres JDBC driver uses the following convention:
jdbc:postgresql://host:port/dbname?user=username&password=password
Instead, try using JDBC_DATABASE_URL as documented here
I am using activerecord-jdbcvertica-adapter connector but have no luck creating a new database and migrating tables to vertica database.
My database yaml file looks like:
development:
adapter: Vertica
database: #####
username: #####
password: ####
host: ####
port: 5433
encoding: UTF8
This throws below error when I do bundle exec rake db:create db:migrate db:seed:
Rake tasks not supported by 'Vertica' adapter
Does anyone know how to use this adapter? Am I doing anything wrong?
How can i connect to heroku postgres from another webapplication running on different cloud service.
I have a heroku postgres. I have another webapplication running on EC2. When my webapp on ec2 is trying to connect to heroku app, it fails.
I tried telnet from ec2 instance to heroku postgres on port 5432, it fails.
Can anyone please provide a pointer?
You can use heroku pg:credentials command to get the credentials for your database. For example:
$ heroku pg:credentials DATABASE_URL
Connection info string:
"dbname=abcdefghijklmn host=ec2-1-2-3-4.compute-1.amazonaws.com port=5432 user=abcdefghijklmn password=abcdefghijklmnopqrstuvwxyz sslmode=require"
Connection URL:
postgres://abcdefghijklmn:abcdefghijklmnopqrstuvwxyz#ec2-1-2-3-4.compute-1.amazonaws.com:5432/abcdefghijklmn
Then, you can use Connection URL or decomposed credentials in your other application. Pay attention to sslmode=require. Connections to Heroku Postgres require you to use SSL, which is an "advanced" option in some of the PostgreSQL clients (e.g. Navicat). For example:
$ psql postgres://abcdefghijklmn:abcdefghijklmnopqrstuvwxyz#ec2-1-2-3-4.compute-1.amazonaws.com:5432/abcdefghijklmn
More information here: https://devcenter.heroku.com/articles/heroku-postgresql#external-connections-ingress