我公司的Devops要求我测试我可以访问该工具的托管实例,访问堡垒主机,数据和工具部署过程(API和FRONTEND),然后再进行修改。所以我想测试我在本地访问API
本地访问API(在API示例上)
$ ssh -l< local-port>:ec2-user@< stage-or-prod-instance-ip>:< host-port>
ubuntu@< stage-or-bastion-ip>
其中:
-
< local -port>
- 本地端口
-
< stage-或prod-instance-ip>
是EC2实例的IP,其中API(其他服务)被部署。使用使用弹性容器服务中的IP
AWS控制台。
-
< host -port>
是主机端口(动态分配 - 在AWS ECS控制台中检查)
-
< stage-or-bastion-ip>
- stage或prod Bastion ip
eg:
$ ssh -l3000:ha.ha.he.he:32980
从utils/get_token.sh获取JWT令牌(Toke自动导出
作为token env var)
使用卷曲:
将请求发送到API(或其他服务)端点
$ curl -xpost -h“授权:承载$ token”
Localhost:5000/API/DATA/DETACE-METADATA
我设置了隧道为API(其他服务)实例,使用了与Doc的示例相同的,这可能是整个问题,也许此地址不是部署API的一个,但我不知道如何在弹性容器注册表上找到其他。所以我做到了:
ssh -L3000:ha.ha.he.he:32980 [email protected]
使用true ha.ha.he.he.he
和 hi.hi.ho.ho.ho
(我是因为我不是因为我不是,所以请 是敏感
当然
export TOKEN=$(aws secretsmanager get-secret-value \
--secret-id dev/api/token \
--query SecretString \
--output text | jq ".TOKEN" -r)
echo $TOKEN
。
ubuntu@ip-10-0-0-238:~$ curl -XPOST -H "Authorization: Bearer $TOKEN" localhost:5000/api/data/studies-metadata
curl: (7) Failed to connect to localhost port 5000: Connection refused
的
ubuntu@ip-10-0-0-238:~$ sudo netstat -anp | grep -i tcp | grep -i listen
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 251314/systemd-reso
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 658/sshd: /usr/sbin
tcp6 0 0 :::22 :::* LISTEN 658/sshd: /usr/sbin
信息 但是这些看起来都不是我正在寻找的/api/data/stuciess-metadata ...
所以我认为我不在正确的机器上,所以我考虑寻找< Instance-IP>
EC2实例的IP(或其他服务)我使用AWS Console在弹性容器服务中检查IP:
我在实例中进行了此查询我通过SSH连接:
ubuntu@ip-10-0-0-238:~$ aws ec2 describe-instances --query "Reservations[].Instances[].PrivateIpAddress" --output text
10.0.0.238 10.0.1.238
想我与另一个相关的实例?
我
I was asked by the devops of my company to test wether I had access to to the instance where the tool is hosted, access to the bastion host, data, and at the tool deployment process (API and frontend) before modifying it. So I wanted to test wether I had Access API locally
Access API locally (on API example)
$ ssh -L<local-port>:ec2-user@<stage-or-prod-instance-ip>:<host-port>
ubuntu@<stage-or-prod-bastion-ip>
where:
<local-port>
- local port
<stage-or-prod-instance-ip>
is IP of EC2 instance where API (other service) is deployed. Check the IP in Elastic Container Service using
AWS console.
<host-port>
is a Host Port (dynamically assigned - check in AWS ECS console)
<stage-or-prod-bastion-ip>
- stage or prod bastion IP
e.g.:
$ ssh -L3000:ha.ha.he.he:32980 [email protected]
get JWT token from utils/get_token.sh (toke is automatically exported
as TOKEN env var)
send request to API (or other service) endpoint using curl:
$ curl -XPOST -H "Authorization: Bearer $TOKEN"
localhost:5000/api/data/studies-metadata
I set up tunnel to API (other service) instance following using the same as the one given as an example to the doc, and this might be the whole problem, maybe this address is not the one where the API is deployed but I don't know how I can find the others on the Elastic Container Registry. So I did:
ssh -L3000:ha.ha.he.he:32980 [email protected]
With the true ha.ha.he.he
and hi.hi.ho.ho
from the doc (I put this mockup text just because I am not sure it is sensitive information.
Then I got the token with:
export TOKEN=$(aws secretsmanager get-secret-value \
--secret-id dev/api/token \
--query SecretString \
--output text | jq ".TOKEN" -r)
echo $TOKEN
And last I tried on port 5000 of the localhost:
ubuntu@ip-10-0-0-238:~$ curl -XPOST -H "Authorization: Bearer $TOKEN" localhost:5000/api/data/studies-metadata
curl: (7) Failed to connect to localhost port 5000: Connection refused
So I guessed it wasn't the right port? I tried to look at what was going out of this machine :
ubuntu@ip-10-0-0-238:~$ sudo netstat -anp | grep -i tcp | grep -i listen
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 251314/systemd-reso
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 658/sshd: /usr/sbin
tcp6 0 0 :::22 :::* LISTEN 658/sshd: /usr/sbin
Fine, but none of these looks like the /api/data/studies-metadata I was looking for ...
So I am thinking I am not on the right machine so I thought about looking for <stage-or-prod-instance-ip>
the IP of EC2 instance where API (or other services) is deployed. I check the IP in Elastic Container Service using AWS console:

I did this query within the instance I connected to via ssh:
ubuntu@ip-10-0-0-238:~$ aws ec2 describe-instances --query "Reservations[].Instances[].PrivateIpAddress" --output text
10.0.0.238 10.0.1.238
So I guess I connected to the wrong instance? How can I connect to the other one?
I am a true begineer in AWS.
发布评论