Not able to access the EC2 instance added to ECS cluster - amazon-web-services

I have created the ECS cluster, which as of now contains only one EC2 instance.
I have deployed my node application using docker.
I tried accessing my application running on 3000 port on this EC2 instance using its public IP address. But somehow I am not getting response.
I tried to ping this IP, I get the response back. Same docker container is working fine on other instance.

You must map the container port to your ec2 instance port. first open the port number you want to access with public address by ec2 security group
First, open ec2 instance port:
in EC2 console > click in your instance > security groups
Then open a port in inbound and outbound settings.
Next, map this port with your container port (3000):
ECS > Task Definitions > your task > your container > mapping ports
Set host port: port opened, container port: 3000, protocol: tcp

Okay, it's hard to tell, but since this is probably access issue, you can try the followings.
Check if port 3000 is open in the Security Group that tied to to the ECS instance.
SSH into the EC2 instance, and check if your node app can be access via port 3000. You need to enable the SSH in the Security Group for the EC2 for this.
The new ECS support dynamic port mapping, so make sure your task definition is configured to use port 3000.
That should help you narrow down where the real issue is.

Related

Accessing docker container in the AWS EC2 public IP

I have an architecture as shown below:
sorry for the mess with all the ports
So, the EC2 instance it is running and I am able to access the instance via SSH (port 22). I am also able to access the contents of the container which is running in the EC2 instance if I forward the ports via SSH. BUT, I am not able to access this same content if I try to connect via public IP of the EC2.
As you can see the security group is created and the ports allowed.
When I run in the EC2: sudo firewall-cmd --list-all I can see that the ports: 80/tcp 8080/tcp 8071/tcp 8063/tcp are allowed.
I am pretty new in AWS/Docker and cannot figure it out how to access container via public IP
I have tried updating security groups and also allowing ports in EC2 thinking that maybe firewall might block the communication but still the access was not possible

Unable to SSH to my EC2 instance despite adding my IP in the security group route table

I have tried all that I could have done.
Deleted the previous EC2 instances
Used a new key pair
Used putty to connect with new pair
Used chrome extension secure shell app to connect to EC2 instance with new key pair
I added my IP address in my security group inbound table but not able to access the EC2 instances.
Attached are the images of my issues.
Cause of the problem:
The port number for SSH is 22.
However, the screenshot for the ssh error shows that the connection is being attempted on port 80.
Suggested fix:
The problem can be fixed by specifying the port number as '22' in the SSH client connection settings.
To access the EC2 instance via SSH, check:
The instance has been launched in a public subnet (defined as having a Route Table that routes traffic to an Internet Gateway)
The Security Group should be permitting inbound traffic on port 22 from your IP address (or a wider range, such as 0.0.0.0/0)
Don't change the NACLs from default
Make sure the instance is running Linux
For EC2 Instance Connect, make sure it is using Amazon Linux 2 or Ubuntu 16.04 or later
Make sure you are connecting to the public IP address of the instance (based on your pictures, you are doing this)
Simple hint: If the connection takes a long time to fail (or hangs), then there is no network connectivity to the instance. Check Security Groups and VPC configurations. If an error comes back immediately, then network connectivity is okay and the connection is simply being refused by the instance.

Expose port of AWS EC2 instance to entire network

I have an app which is deployed via Docker on one of our legacy servers and want to deploy it on AWS. All instances reside on the company's private network. Private IP addresses:
My local machine: 10.0.2.15
EC2 instance: 10.110.208.142
If I run nmap 10.110.208.142 from within the Docker container, I see port 443 is open as intended. But I if run that command from another computer on the network, e.g. from my local machine, I see that port is closed.
How do I open that port to the rest of the network? In the EC2 instance, I've tried:
sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
and it does not resolve the issue. I've also allowed the appropriate inbound connections on port 443 in my AWS security groups (screenshot below):
Thanks,
You cannot access EC2 instances in your AWS VPC network from your network outside of AWS using private IP addresses of the EC2 instances using the public Internet. This is why EC2 instances can have two types of IP addresses: Public and Private.
If you setup a VPN from your corporate network to your VPC then you will be able to access EC2 instances using private IP addresses. Your network and the AWS VPC network cannot have overlapping networks (at least not without fancier configurations).
You can also assign a public IP address (which can change on stop / restart) or add an Elastic IP address to your EC2 instances and then access them over the public Internet.
In either solution you will also need to configure your security groups to allow access over the desired ports.
Found the issue. I'm using nginx and nginx failed to start, which explains why port 443 appeared to be closed.
In my particular case, nginx failed because I was missing the proper ssl certificate.

Permissions for EC2 created by Elastic Beanstalk connecting to external RDS

I am quite new to Elastic Beanstalk and not very proficient with server administration, but I need to set up a Django project on Elastic Beanstalk connecting to external RDS MySQL database.
I have created a separate RDS MySQL database and I can connect to it using Sequel Pro on my computer without problems. Then I have my Django project which I try to put to Elastic Beanstalk, but unfortunately without luck. If I run the local Django server from my computer, the project is browsable and Amazon RDS MySQL is accessible. However, when I run
eb deploy
I get
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server
on 'myapp-staging.xxx.eu-west-1.rds.amazonaws.com' (110)")
(ElasticBeanstalk::ExternalInvocationError)
If I login to the EC2 server via SSH
eb ssh
and then check the open ports with
netstat -lntu
I don't see MySQL's port 3306 there, so I guess it is blocked by firewall.
This is what I tried regarding permissions:
I went to RDS Dashboard -> Security Groups and created myapp-mysql-security-group with EC2 Security Group connection type pointing to EC2 security group used by Elastic Beanstalk EC2 instance “awseb-e-...”.
I went to EC2 -> Security Groups and for “awseb-e-...” I set the Inbound MySQL port with source 0.0.0.0/0
I went to VPC Dashboard -> Security Groups and created myapp-mysql-security-group with Inbound Rules of MySQL port with source 0.0.0.0/0.
Then I tried to redeploy, restart servers and even rebuild environment, but nothing helped. The MySQL port 3306 is still not open in the EC2 instances created by Elastic Beanstalk.
What am I doing wrong or what is missing?
MySQL port 3306 is only opened at the RDS instance (not in your EC2 instance). So, if you check on your EC2 instance, it should not listen on port 3306.
Things those you can do to check RDS is working:
Check your EC2 instance connection to RDS.
SSH to your instance (eb ssh) and run telnet myapp-staging.xxx.eu-west-1.rds.amazonaws.com 3306. You might need to install telnet first (yum install telnet).
If it's success, check your app.
If it's failed, check on next point.
Make sure your RDS and EC2 placement is correct:
For private only access RDS:
Make sure they are in same VPC and allow incoming connection in RDS from VPC's IP to 3306. For better performance, use IP address instead of Security Group name.
If they are on different VPC, you can create VPC Peering.
For public access RDS:
Same as above, allow incoming connection from VPC's IP.
Make sure EC2 instances are allowed to make outgoing connection to port 3306 in EC2 security group.
Make sure your EC2 host doesn't have denied 3306 rule in iptables.
If your EC2 and RDS in different VPC and you use private IP for your EC2, check the NAT server. Make sure you allow port 3306 to be proxified.

How can I connect to Amazon Elastic Beanstalk through IP and port?

I want to connect to my Python app on Elastic Beanstalk via TCP socket by using IP and port. Where can I get those information? I tried using Elastic IPs in EC2 but I can't connect to it. Do I have to set something to make it works?
If you are using a Single Instance Environment type then you'll be able to use a IP however if you're using the Load balancing, autoscaling Environment type then you'll need to you CNAMES.
Secondly you'll need to open the port you want to connect to by either manually opening in the EC2 security groups or using .ebextensions because by default only certain ports are open.
Log into your machine and telnet to the localhost and the port of your Phyton application, if you connect then; find the IP of your machine, open the port in the EC2 security group assigned to that instance and try the telnet again which will tell you if you port listening or not.