0

I have my main python program running on an EC2 with celery and a local redis queue running on it. CELERY_BROKER_URL=redis://redis:6379

I have set up my development environment locally on my mac but would still like to connect to that redis queue on my EC2.

Do I need to add the public DNS to the front of the local environment's .env (redis://redis:6379) file so celery knows how to connect to it? I am just not sure the best way to do this.

Thank you.

davidism
  • 121,510
  • 29
  • 395
  • 339
user3324136
  • 415
  • 5
  • 20
  • 1
    As you mention this is for your local dev environment, probably best not to expose redis to the internet, and instead use an ssh tunnel... `ssh -L 6379:localhost:6379 ec2_addr` - while this ssh session is established, localhost:6379 on your dev box, is tunneled to localhost:6379 on the EC2 box. So in your dev config, set `CELERY_BROKER_URL=redis://localhost:6379` – v25 Jan 21 '22 at 23:56
  • Thank you v25. Let me give this a try and get back to you. I need to open port 22 and then check it. Would I need to open the 6379 port as well? The reason I ask is because I get a `Permission denied (publickey,gssapi-keyex,gssapi-with-mic).` I think because I need to open that port. – user3324136 Jan 22 '22 at 00:37
  • This will work if you already have ssh access to the box, see [Connect to your Linux instance using SSH](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html). You may also need to configure security groups for that instance to allow incoming traffic on 22. – v25 Jan 22 '22 at 10:58
  • Thank you, V25. So, here is where I need to get my head around. I can access ssh via the command `ssh -i "xxxx.pem" ec2-user@ec2-xxxxx.amazonaws.com`. If I want to use the `-L` command, I still need to add my `security xxxx.pem` file? Thank you – user3324136 Jan 22 '22 at 15:57
  • 1
    Ok, so after adding in the credentials, I think it worked. `ssh -L 6379:localhost:6379 -i "xxxx.pem" ec2-user@xxxx.amazonaws.com`. Now to see if it reaches the redis host. Thank you – user3324136 Jan 22 '22 at 17:43
  • Ok. One more question. When I run the program, I get the error `channel 3: open failed: connect failed: Connection refused channel 4: open failed: connect failed: Connection refused channel 3: open failed: connect failed: Connection refused channel 3: open failed: connect failed: Connection refused ` Does this mean I need to open the port 6379? I can connect successfully via ssh right now – user3324136 Jan 22 '22 at 21:32
  • 1
    Perhaps see: [this answer](https://stackoverflow.com/a/27879297/2052575). It sounds like the redis server may not be running on localhost:6379 *on the ec2 box*. – v25 Jan 22 '22 at 21:47
  • Thank you v25, I will do a bit more work there. – user3324136 Jan 23 '22 at 02:28

0 Answers0