I am new to Amazon cloud. I have deployed a django application on AWS EC2. I started the application but unable to see it from the browser. Which IP address will have the access? I tried both private and public but both are not resolved.
Try to run you app using command python manage.py runserver 0.0.0.0:8000.
Your app will be running publicly. Try to figure out IPv4 Public IP in the Instance section of AWS.
Then move to Security Groups which is listed in left navigation under NETWORK & SECURITY.
Choose the security group which is assigned to your instance. After that click on EDIT button on Inbound rule section and allow port in which the app is running. For example: port 8000.
Type: Custom
Protocol : TCP
Port Range : 8000
Source : Anywhere or My IP
Once added. Click on Save and make sure in Django App settings,allowed host is set to *. So, that you can access your application from anywhere.
ALLOWED_HOSTS = ['*']
The above code is not recommended for production. Good to use for development/testing.
Related
I have an instance setup for a test site using Amazon Web Services listed under EC2.
I then setup an Elastic IP which as i understand is a static IP.
Once logged into this instance of Windows Server i setup a site in IIS which runs locally.
I have set all the bindings in IIS but struggling to figure out how i assign a public name to this instance so i can view the site in an external browser? I tried entering the IP but that doesnt open anything, not even the standard IIS page?
Check your firewall if you have opened the port 80 or whatever the IIS is bonded with
and also check your security group of the EC2 instance and open the port 80 to the world
This tutorial here shows how to start the development server on AWS EC2:
ALLOWED_HOSTS=['EC2_DNS_NAME']
...
python manage.py runserver 0.0.0.0:8000
In a browser, navigate to public DNS of the instance, make sure to append port “8000” at the end and if everything was properly configured, it will show the index page of the application.
For example: www.ec2dnsname.com:8000
My public IPv4 DNS is of this form:
ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com
So, in my settings.py
ALLOWED_HOSTS=['ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com']
And run this in the EC2 terminal:
python manage.py runserver 0.0.0.0:8000
However, when I try to reach this address:
www.ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com:8000
nothing is showing up (The page took too long to respond).
Is this the complete and correct way to just try run a development server on AWS EC2?
Update after #Iam_batman response: Below is the Security Group setting attached to my EC2 instance:
All TCP TCP 0 - 65535 0.0.0.0/0 –
All TCP TCP 0 - 65535 ::/0 –
The Port Range seems to cover everything. I still can't access the index page from the development server.
Also, my AWS account is a workplace account, not a personal account. If I follow #iam_batman setup below, using HTTP and SSH protocol, I get denied the access to port 80 and 22 respectively.
Update: To further test, I run a curl command as following :
curl http://ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com:8000
I get the entire HTML code for the standard Django index page (the one with the spaceship). This implies that the website is already available at that address. But for some reason, it does not render on the browser?
There's two things you should check out.
1. Check if security groups are configured.
Search for "Security Groups" in aws dashboard. Find the 'Create Security Group' Button on the top right and create a security group with inbound and outbound rules that allow http traffic on the port you want to communicate with.
Here's an example where i am using the standard 80 port for http. But, you can use 8000 if you want.
Now, you just need to assign the the security group you created to your ec2 instance. Go to EC2 dashboard and select your instance. Then Actions > Security > Change Security Groups. Select the security group you just created and you are good to go.
2. Maybe you need an application server
I have never actually tried deploying with the django development server ( runserver command ) because its not meant for production. For, deploying python based frameworks like django/flask/fast-api you need to use an appserver like: uwsgi, gunicorn etc. So, do give it a look. You need an appserver atleast. For, more production use cases you might need to have an actual webserver like nginx/apache on top of the app server.
These are my two notes on your issue.
There are many similar questions to this on SO, but none of the solutions I saw really solved my issue completely. I'm doing test runs for a website framework hosted on the Google Cloud Platform.
By default, the website is hosted on http://localhost:2800 And I know the external IP of the instance I'm running it on. How can I access the hosted website through a browser on my local machine? Do I use virtual hosts / port forwarding etc.?
go to your VPC firewall
https://console.cloud.google.com/networking/firewalls
and create a firewall rule to allow traffic on your desired tcp port
Create a Firewall Rule for SQL Server
Configure a firewall rule to allow traffic on port 1433 so other clients can connect to the newly created SQL Server instance over the public internet:
In the Developers Console main menu, go to the Firewall rules section.
OPEN THE FIREWALL RULES
Click the Add firewall rule button.
Name the new firewall rule allow-tcp-1433.
Set Source Filter to IP Ranges.
For Source IP Ranges enter 0.0.0.0/0. This value allows access by all IP addresses.
Warning: This configuration leaves your SQL Server instance open to traffic from everyone, everywhere. It is used only for demonstration purposes. In production environments, restrict access to only those IP addresses that need access.
For Allowed protocols and ports enter tcp:1433.
Click the Create button to create the firewall rule.
Set firewall rules for you google cloud project with following properties:
Target: all instances
Direction: ingress
Source IP ranges: 0.0.0.0/0
Ports and protocols: allow all
Then Depending on your framework, set allowed_host to externalIP or "*" .
For example - In Django, in settings.py set ALLOWED_HOSTS = ["*"]
Now run server on specific 0.0.0.0:[your_port]
For example in django - Python manage.py runserver 0.0.0.0:8000
After this note down you instance external IP address and then in your browser :- goto
[external-IP:[your_port]]
you have to go VPC network, then add firewall to allow your port. then don't forget to select [All intances in the network] (see pic). because, by default its value is [Spesified by tags].
and you can access that instance to its External IP
Try your [externalip]:[port] This worked for me in Amazom ec2.
example: 31.181.171.141:2800
I've created Kubernetes cluster in AWS.
I'm working on guestbook example based on coreos. After creating frontend service I'm able to curl localhost and access guestbook application from minion where application is built but failing to do so through browser or master.
I have tried putting diffrent publicIp in frontend service such as Public IP, Private IP assigned to instance by AWS.
Note:
Checked Security group in AWS and all needed ports are enabled
To check if minion is accessible through browser and other setting are correct, i tested nginx "Welcome to Kubernetes" application, it was successfully accessed through browser.
Running kubectl cluster-info should give you a proxy endpoint on the master which you can hit to access the application. That should give an idea if there is a problem with your app in the first place.
this link helped : https://github.com/GoogleCloudPlatform/kubernetes/issues/6158 see hack solution by kcao3.
Following are the changes :
add redis-master IP in slaves container /etc/hosts file
add redis-slave IP and redis-master IP in frontend containers in /etc/hosts file
checked firewall settings.
NOTE: Its a hack so DNS settings will be the correct solution
I've got a very simple Flask application that I'm hosting on an Amazon EC2 node and for whatever reason I can't see it externally. The flask app is here
from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = False
#app.route('/')
def hello_world():
return 'Hello World!'
#app.route('/p1')
def p1():
return "P1!!!"
if __name__ == '__main__':
app.run(host='0.0.0.0')
When I run the script it looks like the server is running fine, so in my browser (on a different computer) I put the following :5000 (the IP address I pull off of AWS). What's interesting is that it just seems to hang, and eventually produces an error. My guess is that I'm missing some configuration in AWS but I don't know what it is. Any help would be greatly appreciated
EDIT I tried deploying the app on my local machine. And when I try to access it from the browser using localhost:5000, it works. When I replace localhost with my IP address, it fails
Found this question while searching for a solution to the same issue.
edit run.py to enable flask to respond to requests from other than localhost.
this example enables responding to requests from anywhere. good security policies would use something more restrictive.
app.run(host='0.0.0.0')
in the AWS control panel go to EC2: select instance.
the browser should be pointed to the address from 'Public DNS (IPv4)'
(the ip# from IPv4 Public IP might also be useful)
look for 'Security groups': right-click to open the security group on a new page.
check inbound rules.
by default, flask binds to port 5000. add rule permitting incoming TCP traffic on port 5000.
while good security protocol should limit the number of ports left open and the range of IP's permitted to connect, it might be easier to permit 'anywhere' to connect over 'all tcp'.
NB: check if the default port has been changed in the flask config file run.py
ie: line below changes port from the default 5000 to 3000.
app.run(debug=True, port=3000)
Can also check if the flask instance is working locally by ssh'ing to the server and using a local instance of the lynx text browser to verify the port is responding. ie
lynx localhost:5000
Was able to ultimately answer my own question, both really
The problem I was having on AWS was that my inbound for that EC2 was not allowing access through the ports that I would need.
When I tried running it on my local machine at work, firewall settings change the address of localhost (and my IP) so that's why I couldn't access it outside of using localhost:5000
In your EC2 instance, the security group is what restricting your entry to the website.
Go to AWS portal, select your instance
Locate the security group and click the name
in the inbound rule window, select add rule
Not a recommended security practice but to get it running, select All TCP
add '0.0.0.0' in the source
your website will be running
I faced a similar issue in which the Flask app on EC2 instance was not responding. Turns out that I had to modify the inbound rules because:
The default security groups and newly created security groups include default rules that do not enable you to access your instance from the internet.
In order to modify the inbound rules, go to:
Instances dashboard > Security > Security Groups (go to your security group) > Edit Inbound Rules > Add Rule.
Fill the values:
Type -> Custom TCP
Protocol -> TCP
Port range -> 5000 (If your flask app is running on default port)
Source -> Your IP or 0.0.0.0/0 if you want to allow all traffic. You can also select My IP from source dropdown. This will automatically get your IP.
Save and you are good to go!
As you are already using host="0.0.0.0" in your app it should be accessible from anywhere. The only think blocking it is your aws security group inbound rules. Add a All TCP inbound rule for port 0-65535 (your app port should be in this range) with source 0.0.0.0/0 and it should work.