Connection refused from serverless-offline lambda to host database - mysql

This question is related to serverless-offline plugin, local mysql database connection. The scenarios for my test is as follows.
Using serverless-offline plugin, a lambda function is deployed locally on my machine.
The triggered lambda is not possible to connect with the local database.
Probably, serverless-offline creates a docker image to launch a lambda, and the address is not correct in the docker container and port mapping. However, serverless-offline does not support those docker options. I am stuck here to connect the database from the lambdas deployed locally with serverless-offline.
I used localhost:3306 for the db host, but it does not work. I tried port forwarding to connect the database via public ip address which does not work.
The database connection can be established somehow, but the connection is refused all the time. Any help?

I'll do my best to address several areas of your post in order of their appearance
serverless-offline creates a docker image to launch a lambda
Incorrect. Serverless Framework and its plugins (serverless-offline, etc.) have absolutely nothing to do with Docker, or Docker related technologies.
I used localhost:3306 for the db host, but it does not work
From your post, I am gathering that you simply do not have a MySQL service running on your local machine. Is that what you need? Reply to this post and I'll try to help, or simply google examples of how to install/start/configure a MySQL server.
I tried port forwarding to connect the database via public ip address which does not work.
I assume you're talking about the popular ssh -L trick to connect to a remote database over SSH connection? From your post, I am gathering that you simply are not performing this operation correctly. Do you need help doing that? Reply to this post and I'll try to help, or simply google examples of how to use SSH Port Forwarding to connect to a MySQL database.

Related

node js app deployed on google cloud connection with remote mysql on diffrent server.

I need to connect to remote mysql on different server and my nodejs code is deployed on google cloud. I have tried with host ip, username password of remote mysql, but giving following error:-
{"errorno":"ETIMEDOUT","code":"ETIMEDOUT","syscall":"connect","fatal":true}
ETIMEDOUT is a Node.js networking error. You will need to tinker with you firewall rules to allow the connection.
Probably opening port 3306 will solve the issue. Here's the documentation for setting up a remote access to MySQL [1] and the networking side [2]

Connect localhost Mysql from Docker .net core

I have working WebAPI in .net core in Docker. I want to deploy this API on AWS EC2 instance with local mysql database working with other web app.
How can I reach this Mysql from inside docker?
Locally I can do it by using my private ip addres in
=> optionsBuilder.UseMySql(#"Server=$my_local_ip;database=db_name;uid=user;pwd=pass;");
Ho to determine which $my_local_ip should I use in order to connect to DB?
But while using the private ip on EC2 I got error while sending request that it can't connect to any MYSQL host.
For MySQL server you generally have to specify the port to connect to, as each instance on the same server uses a different port.
Use --network=host flag while starting the Web API container and use the localhost in you connection string as the host name. This will enable the Docker container to access the host network. Hence you can access MySQL Database from the container.
Note: This is an insecure for running containerized workloads. Click Here to learn more

Connect to host postgres db from minishift

Im trying to connect to a postgres database, from a springboot application deployed in minishift.
The postgres server is running on the same host that minishift is running on.
I've tried setting the postgres serve to listen on a specific IP address, and use this same address in the springboot jdbc connection url but I still get org.postgresql.util.PSQLException: Connection to 172.99.0.1:5432 refused
I've also tried using 10.0.2.2
Also tried, in /etc/postgresql/9.5/main/postgresql.conf, setting:
listen_addresses = '*'
How can I connect to a database external to minishift, running on same host?
Besides the answer referenced in my comment, which suggests to make your database listen on the IP address of the Docker bridge, you could make your pod use the network stack of your host. This way you could reach Postgres on the loopback. This works only if can guarantee that the pod will always run on the same host as the database.
The Kubernetes documentation discourages using hostNetwork. If you understand the consequences you can enable it as in this example.
If a pod inside kubernetes can't see the IP address from the host then I guess its an underlying firewall or networking issue. Try opening a shell inside the pod...
kubectl exec -it mypodname bash
Then trying to ping, telnet, curl, wget or whatever to see if you can see the IP address.
It sounds like something's wrong with the networking setup of your minishift. It might be worth raising an issue with minishift: https://github.com/minishift/minishift/issues/new
If you can find an IP address on the host which is accessible from a docker pod you can create a Kubernetes Service and then an Endpoint for the service with the IP address of the database on your host; then you can use the usual DNS discovery of kubernetes services (i.e. using the service name as the DNS name) which will then resolve to the IP address. Over time you could have multiple IP addresses for failover etc.
See: https://kubernetes.io/docs/user-guide/services/#without-selectors
Then you can use Services to talk to all your actual network endpoints with your application code completely decoupled on if the endpoints are implemented inside kubernetes, outside with load balancing baked in!

Connect Amazon EC2 to my Local MySQL Database

Is it possible to do the following?:
I have a local Mac running OS X Lion with a MySQL Server installed which runs different processes regularly and stores data into a local DB.
On the other hand I have an Amazon EC2 instance.
What I would like to do is to use the Amazon instance to perform certain cronjobs (using its own resources) but connecting to the data that is on my localhost (my computer) and performing basic SQL actions like updating the data, inserting, etc.
I don't know if this helps, but I have a static IP. Is there any way I can "open" my IP so the Amazon instance can recognize my home computer as a valid MySQL server?
Thanks for your help, any tip in the right direction will be much appreciated.
If your EC2 instance is connecting to your local db you'll need a static IP locally. Well not need... but if you don't have it anytime you reset your router or loose power etc your ip will change. You can look into Dynamic DNS as well for your local instance.
Your ISP will not block your port on your local instance. This would be a firewall inside your network that is preventing you from connecting to mysql or a configuration with mysql itself. Users can only connect to mysql from certain IP addresses.
You would have to open up the mysql port on your firewall if you are using one, have the mysql client installed on your EC2 instance, and make sure that the user that had proper grantable permissions.
That said why not run cron locally on the mac?
If you can login to your server via SSH then there's no need to open any other port and no static IP is required. You can use SSH port forwarding instead. From your local machine run:
ssh -C -R 5555:127.0.0.1:3306 <your-server-host>
Now you should be able to connect to your Mac's database running on localhost:3306 from the remote server at localhost:5555.

Connecting/Tunneling to remote server to bypass firewall

I want to try out some of the MySQL software, like Workbench, on the MySQL Db I develop on at work. After many failed attempts to make the connection, I finally asked one of the server admins if I was doing something wrong and was informed that the Db is behind firewall. So I can use phpMyAdmin, since it's installed server-side, but not Excel, Workbench, etc (from my machine).
So I would like to know if there is a fairly standard way to make a VPN-like connection to the server. Currently I use an SSH client to connect with no problem. But obviously that's not linking my local apps to the server. So can I make the connection in such a way that my whole system (so to speak) is considered signed on to the server? VPN is the closest analogy I can make, but that's not an option.
And....
Is that considered fairly "black hat" or is just something I don't know how to do but all the cool kids are doing it legitimately?
Thanks
This is simple using SSH tunneling. Simply do something akin to the following:
ssh -f username#your.remote.host -L 4040:your.remote.host:3306 -N
This does the following:
-f - forks SSH into background
username#your.remote.host - the user & host for SSH to connect to
-L 4040:your.remote.host:3306 - Listen for local connections on port 4040, and forward them via SSH to your.remote.host port 3306
-N - tells SSH not to issue a command on the remote host
You would then be able to connect to your mysql server (assuming the above ports are correct) using:
mysql --host=localhost --port=4040 --user=mysqluser -p
SSH tunnelling is excellent and can make life a lot easier.
The advantages are that it is all running over an encrypted port, 22, so the security is better and you can also compress the session, so over a slow network might see a bit of a performance improvement...
If you are using Windows, I would recommend puTTY which is available easily if you google it... Once connected, you can assign a local port which forwards to a port on the remote machine. In puTTY, this is in the Connection->SSH->Tunnels dialog.
I often use this for forwarding VNC - so if you have localport 5900 forwarding to the remote address 5900, you can connect to localhost:5900 as if you were connecting to the remote IP address.
It is also useful if there is a "hop" to a remote network - e.g. you aren't limited to forwarding to the ssh server you are connected to, you can also connect to other servers via the ssh server you are using.
Finally, I don't think that there is anything illegitimate about this option - you are using the ssh connection as intended and have been granted access to the server you are using. If anything, it is increased security...
Admins where I am have an Open-VPN that connect their personnal computer at home to servers at work, but it is used only for maintenance and 'emergency'.
I don't think it is good for security to have "holes" in the firewall, especially to a private place, where there is no firewall to protect your personnal computer.
These kind of practise is possible but has to be retricted to minimum