How can I access application deployed on localhost of AWS remote server? - amazon-web-services

I have developed a set of apis on my AWS server.
When I do npm start , application is started on a particular port of aws localhost.
I am able to hit the apis using curl command from my terminal window.
eg:
curl -s -X GET \
"http://localhost:6001/getAssetDetails?assetId=1"\
-H "content-type: application/json"
How to access the apis from my host system using postman installed on my host machine?
How to access localhost applications of AWS server from web browser of windows host? What URL should I hit from my host machine?

You have to add Inbound rules in Access control list (ACL) of your EC2 instance. Ports are blocked by default in aws server. This might help aws-doc

Related

Accessing a dev server when doing remote / cloud development

I'm attempting to find a completely remote / cloud-based development workflow.
I've created an aws free-tier ec2 instance and on that box I've been developing a gatsby site (the framework doesn't matter, the solution I'm looking for should be framework agnostic). Since the code is on another box, I can't run the dev server and then from the local computer hit localhost as I would normally.
So,
What do I need to do so that I can run gatsby develop and hit my dev server that's hosted on the ec2 box?
How do I provide public access to that endpoint?
Is it possible to provide temporary access so that when I log off of the box, it's no longer accessible?
Is there some mechanism I can put into place so that I'm the only one that can hit that endpoint?
Are there other features that I should be taking advantage to secure that endpoint?
Thanks.
I can't run the dev server and then from the local computer hit localhost as I would normally
You can. You can use ssh to tunnel your remote port to your localhost, and access the server from your localhost.
What do I need to do so that I can run gatsby develop and hit my dev server that's hosted on the ec2 box?
ssh into the dev server, run gatsby develop and either access it on localhost through ssh tunnel or make it public to access through its public IP address.
Use sshfs to mount a development folder on the dev server onto your localhost.
Alternatively, you can setup vncserver on the dev server, tunnel vnc connection using ssh, and access the dev server using through a remove desktop. Something liteweight would be good, e.g. fluxbox as a desktop environment for vnc.
Is it possible to provide temporary access so that when I log off of the box, it's no longer accessible?
yes. through ssh tunnel. You close tunnel and the access is finished.
Is there some mechanism I can put into place so that I'm the only one that can hit that endpoint?
ssh tunnel along with security group to allow ssh for your IP address only.
Are there other features that I should be taking advantage to secure that endpoint?
Security groups and ssh tunneling would be primary choices to ensure secure access to the dev server.
You can also make the endpoint public, but set security group of your dev server to allow internet access only from your IP.
You could also put the dev server in a private subnet for full separation from the internet. Use bastion host to access it or setup double ssh tunnel to your localhost.
Other way is to do all development on localhost, push code to CodeCommit and have CodePipeline manage deployment of your code to your dev server using CodeDeploy.
You can also partially eliminate ssh by using SSM Session Manager.
Hope this helps.

Cloud Foundry: How to remap an exposed port in Docker image?

I would like to run RabbitMQ service using my organization's Cloud Foundry Service. I checked the RabbitMQ docker image and saw that the following ports are exposed:
"ExposedPorts": {
"25672/tcp": {},
"4369/tcp": {},
"5671/tcp": {},
"5672/tcp": {}
},
I start the app by installing it in Cloud Foundry as follows: cf push -o rabbitmq RabbitMQ -u process.
The app gets installed and gets started. However, it is listening on port 5672. The CF service only allows me to have ports between 10000 and 10999. So I go into the CF portal, remove the HTTP route, and create a new TCP route on port 10123 for the rabbitmq app.
How do I go about mapping the port 10123 (external facing) to the port 5672 (RabbitMQ, internal facing) using the CF CLI?
There is functionality to map a route with specific external ports to specific internal app ports. It is described in the docs here.
https://docs.cloudfoundry.org/devguide/custom-ports.html#procedure
At the moment, the functionality isn't directly supported by the cf cli, so you need to use cf curl to manually send a few requests.
The general flow is this.
Get your app's guid.
Configure a list of ports for your app, cf curl /v2/apps/APP-GUID -X PUT -d '{"ports": [25672, 4369, 5671, 5672]}'
Map a TCP route to your app with cf map-route my-app example.com --port 10123.
Get the route guid of your TCP routee. Run cf curl /v2/routes?q=host:example.com.
Update the route mapping with cf curl /v2/route_mappings -X POST -d '{"app_guid": "APP-GUID from #1", "route_guid": "ROUTE-GUID from #4", "app_port": 5672}'
Optionally repeat 3-5 for additional ports.

Docker - springboot on AWS EC2

Just spun an EC2 ubunto on AWS. Installed Docker. Pulled my test springboot image and run it on the host. Can't access the app via browser. When I curl on the host, it does respond with valid http response. Is there a network or firewall that I should be looking at?
ubuntu#ip-172-31-4-157:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ea9879c1b38c parikshit123/docker-spring-boot:firsttry "java -jar docker-sp…" 20 minutes ago Up 20 minutes 0.0.0.0:8085->8085/tcp frosty_sammet
ubuntu#ip-172-31-4-157:~$ curl localhost:8085/test/hello
Hello from Mitalubuntu#ip-172-31-4-157:~$
Just figured out.
By default, AWS Ec2 instances have ALL TCP tranffic (inbound and outbound) blocked. I learned that it has to be g opened. I added security group and it worked. Now I can access the endpoint via browser. Bingo!

EC2 Multi App Instance - Some Ports not Reachable

I have started an AWS EC2 (UBUNTU 18 AMI) instance running three apps:
Web server on port 80
REST API on port 8786
DB on port X
I am able to
SSH into the instance
Reach the website via browser on port 80.
Reach the REST API from within the SSH session.
I am unable to
Reach the REST API via AJAX from the browser (tried postman as well).
I have
Configured the Security Group to receive inbound connections from all sources on 8786
verified that iptable is not loaded
Tried reaching the website from a mobile network - to no avail.
Swapped the ports between the Web Server and the REST API - which resulted in being able to access the API via the browser and postman.
Verified that the API is bound to 0.0.0.0 - not to localhost.
This smells like an EC2 issue, but I have no idea what to do.
Help would be much appreaciated.
As it turns out, 8786 is a reserved port, and should not be used. Issues were resolved when I changed to 8080, which I should have done in the very beginning.

Airflow integration with AWS development machine to access admin UI

I am trying to use Airflow for workflow management on my development machine on aws. I have multiple virtual environments setup and have installed airflow.
I am listening to port 8080 in my nginx conf as:
listen private.ip:8080;
I have allowed inbound connection to port 8080 on my AWS machine.
I am unable to access my airflow console as well as admin page from my public ip / website address.
You can just create a tunnel for viewing UI locally.
ssh -N -L 8080:ec2-machineip-compute-x.amazonaws.com:8080 YOUR_USERNAME_FOR_MACHINE#ec2-machineip-compute-x.amazonaws.com:8080
ssh -N -L 8080:ec2-machineip-compute-x.amazonaws.com:8080 YOUR_USERNAME_FOR_MACHINE#ec2-machineip-compute-x.amazonaws.com:8080
localhost:8080 for viewing airflow 8080 UI