---
# System prepended metadata

title: AWS ECS execute

---

# 透過AWS ECS Command進入ECS容器內部


**可以透過下面的command, 看到Task有沒有enable-exeucte-command**

aws ecs describe-tasks --cluster uat-live --tasks arn:aws:ecs:ap-northeast-1:283732428191:task/uat-live/63a4b4309f1e473fbbe7b8d11a5a7e4a

![image](https://hackmd.io/_uploads/BkNBEyiDp.png)


**下面的指令，等於docker exec -it xxxx，可以進入容器內部**

aws ecs execute-command --cluster uat-live --task arn:aws:ecs:ap-northeast-1:283732428191:task/uat-live/63a4b4309f1e473fbbe7b8d11a5a7e4a --container uat-live-bo-api --interactive    --command "/bin/bash"

![image](https://hackmd.io/_uploads/Sk2OEJiPT.png)

進container裡了
![image](https://hackmd.io/_uploads/H11o41swp.png)


**注意事項**
1. 任務角色和執行角色要給permission...我給到ecsfullaccess才連的進去
2. 要安裝Session Manager plugin
3. update service時要把enabled-execute-command打開
![image](https://hackmd.io/_uploads/S1MpzJoDT.png)
我透過 aws cli都不work…後來是透過wofy的python透過sdk更新才行
4. ECS Task Id 可以參考下圖
![image](https://hackmd.io/_uploads/ryTyr1sD6.png)




細節可以參考這一篇
https://www.ernestchiang.com/zh/posts/2021/using-amazon-ecs-exec/

不過他說的iam，我assign完還是不work