setting up a basic mqtt broker on aws ec2

2,815 views
Skip to first unread message

andrew stillie

unread,
Apr 19, 2016, 5:01:53 PM4/19/16
to MQTT
Hi 

I have previously set up an mqtt server on my home network using mosquito on a ubuntu machine.

I used an mutt client on my smart phone to publish and subscribe to topics.  It all worked well.


Now I would like to expand my system a little and have the mosquito broker on my was ec2 instance.

Is this possible? If so can someone offer some advice or point me at a tutorial?

regards
Andy

Karl Palsson

unread,
Apr 20, 2016, 7:02:44 AM4/20/16
to mq...@googlegroups.com
Remember that EC2 is just another computer, it just happens to be
one that's not plugged in in your home. So, if you have already
setup mosquitto on ubuntu at home, it's exactly the same for
setting up mosquitto on ubuntu on ec2.

Cheers,
Karl P
signature.asc

andrew stillie

unread,
Apr 20, 2016, 8:03:04 AM4/20/16
to mq...@googlegroups.com

Thanks for replying Karl.

My mqtt android app expects a url username and password.   Which details should I supply here ?

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to a topic in the Google Groups "MQTT" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mqtt/7MyoQlvIdbg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at https://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Hans Jespersen

unread,
Apr 20, 2016, 4:42:35 PM4/20/16
to MQTT
Except for elastic IPs (which you will need or your IP address with change after each reboot), and security groups (which you need to setup or hackers will spam your MQTT ports), and that storage is ephemeral (unless you also provision EBS), and that you will need a SSH key to login and administer the machine to even start. Also, we warned that Amazon charges for output bandwidth so if you do a lot of subscribing from an EC2 hosted instance you can run up bandwidth charges far greater than your EC2 cpu/hour charges.

-hans 

andrew stillie

unread,
Apr 20, 2016, 4:51:29 PM4/20/16
to mq...@googlegroups.com
I am only trying to do this for educational purposes.  My bandwidth will be very low initially.  I switched to free AWS as I could not get port forwarding to work reliably from my home router.  Maybe I need to invest in a better router.

I would like to get this working on the AWS if possible.

Anyone got an example tutorial I could have a look at.

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to a topic in the Google Groups "MQTT" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mqtt/7MyoQlvIdbg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at https://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.



--
Regards,

Andrew Stillie


Hans Jespersen

unread,
Apr 20, 2016, 5:44:55 PM4/20/16
to MQTT
What is not working today? I don't know of a tutorial but if you have specific issues I might be able to help. I have successfully setup another MQTT broker in AWS (not mosquitto) and apart from the issues I listed, it's straight forward. Do you have an Amazon Linux AMI running with a security key provisioned and SSH access to a shell on the virtual machine?

-hans

Paul Fremantle

unread,
Apr 21, 2016, 1:53:01 AM4/21/16
to mq...@googlegroups.com
I use a userdata.sh script to install and run mosquitto. (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html)

Here is the script I use, which is also installing a simple python program that reads data from a website and publishes it to a topic.
This is doing more than you need, but you can get the idea. For example you could check out a mosquitto.conf from git and then move it to the right place.

Paul
#!/bin/bash
sudo apt-get update
sudo apt-get install python2.7
sudo apt-get install python2.7-dev
sudo apt-get install mosquitto -y
sudo apt-get install python-setuptools -y
sudo easy_install pip
sudo pip install mosquitto
sudo apt-get install git -y
sudo pip install httplib2
git clone https://github.com/pzfreo/auto-deploy-node-js.git
cd auto-deploy-node-js/tfl
python tflrepub.py

You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.

To post to this group, send email to mq...@googlegroups.com.
Visit this group at https://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.



--
Paul Fremantle
Part-time PhD student - School of Computing
twitter: pzfreo / skype: paulfremantle / blog: http://pzf.fremantle.org
Co-Founder, WSO2
Apache Member and Committer
07740 199 729

andrew stillie

unread,
Apr 23, 2016, 3:01:50 AM4/23/16
to mq...@googlegroups.com

Hi Hans,

I would like to know how to configure the mosquitto on my ec2 so that I can publish and subscribe to topics from my mqtt android app.

When I ssh to my ec2 and type mosquitto I get a message reporting mosquitto is already running.

I understand that I will need security to prevent spam, but initially I need to learn with something simple.

Thank you
Andy

Hans Jespersen

unread,
Apr 23, 2016, 3:08:24 AM4/23/16
to MQTT
Have you setup a aws security group that allows external IP addresses to connect on port 1883 to your ec2 instance that is running mosquitto?

andrew stillie

unread,
Apr 23, 2016, 3:22:31 AM4/23/16
to mq...@googlegroups.com

No. I have done something similar to open ports 8080 for my node server I am playing with.

On 23 Apr 2016 08:08, "Hans Jespersen" <hans.je...@gmail.com> wrote:
Have you setup a aws security group that allows external IP addresses to connect on port 1883 to your ec2 instance that is running mosquitto?

Reply all
Reply to author
Forward
0 new messages