簡體   English   中英

aws ssm 發送命令 cli 無法創建文件

[英]aws ssm send command cli does not work to create a file

我嘗試在aws ssm send-command下面在 EC2 實例上創建一個文件,但它不起作用。

aws ssm send-command --instance-ids i-XXXXXXXXXX --document-name "AWS-RunShellScript" --parameters commands="touch /home/hadoop/test2.txt" --output text

鍵入命令后,命令立即返回並輸出以下消息。 然后我檢查該 EC2 實例上不存在test2.txt 任何建議將不勝感激。 謝謝。

`命令 AAAAAAAA-ZZZZ-XXXX-YYYY-XXXXXXXXXXXX 0 0 AWS-RunShellScript 0 XXXXXXXXXX.91 50 0 XXXXXXXXXX.91Pending Pending 1 3600 CLOUDWATCHOUTPUTCONFIG False

實例IDS i-XXXXXXXXXX

通知配置

命令 touch /home/hadoop/test2.txt`

我嘗試使用 Amazon Linux 2復制該問題。確實,該命令失敗了。 我發現原因是/home/hadoop/文件夾不存在。 隨后,您無法touch不存在的文件夾中的文件。

解決方案是:

aws ssm send-command \
    --instance-ids i-0788cf54681f8bd52 \
    --document-name "AWS-RunShellScript" \
    --parameters commands='["mkdir -p /home/hadoop/","touch /home/hadoop/test2.txt"]' \
    --output text

根據文檔,如果有人面臨相同的pending問題和使用 ssh 在 EC2 中可執行的命令:

如果命令執行顯示“Pending”或“InProgress”,則再次運行此命令以查看響應數據。

所以你需要運行它來查看結果:

# $sh-command-id is the command-id and you get it from output of aws ssm send-command
aws ssm list-command-invocations \
--command-id $sh-command-id \
--details

更多細節; 請參閱此處獲取帶有響應數據的命令信息部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM