简体   繁体   English

有没有办法获取ecs实例元数据?

[英]Are there any way to get ecs instance metadata?

From the running aws ecs instances, can I get the detail about its cluster name and container instance ID?从正在运行的 aws ecs 实例中,我可以获得有关其集群名称和容器实例 ID 的详细信息吗?

In EC2, I can run below curl command to get its instance id, do I have similar command in ECS?在 EC2 中,我可以在 curl 命令下运行以获取其实例 ID,我在 ECS 中有类似的命令吗?

curl http://169.254.169.254/latest/meta-data/instance-id

Answer my own question, in AWS ECS cluster, a daemon is running, you can queue its metadata by below commands回答我自己的问题,在 AWS ECS 集群中,一个守护进程正在运行,您可以通过以下命令对其元数据进行排队

$ curl http://localhost:51678/v1/tasks | python -mjson.tool


$ curl -s http://localhost:51678/v1/metadata | python -mjson.tool

{
    "Cluster": "application-1",
    "ContainerInstanceArn": "arn:aws:ecs:us-east-2:1234567890:container-instance/ee4d3451d-2de3-4180-b1c6-023ed6e8c343",
    "Version": "Amazon ECS Agent - v1.14.1 (467c3d7)"
}

This will be useful if you need to deregister itself from ECS cluster, for example, you use spot instance in ecs cluster.如果您需要从 ECS 集群中注销自己,这将非常有用,例如,您在 ecs 集群中使用 Spot 实例。

Refer:参考:

ecs agent introspection ecs代理自省

只是为了回应@per-cederberg在他的评论中的内容,以免被埋没(以及一些免费的甜蜜业力😝),正在运行的容器可以调用http://172.17.0.1:51678/v1/metadata以获得相同的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM