【问题标题】:aws ssm send command cli does not work to create a fileaws ssm 发送命令 cli 无法创建文件
【发布时间】:2021-03-23 05:54:10
【问题描述】:

我尝试在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。任何建议将不胜感激。谢谢。

`命令 AAAAAAA-ZZZZ-XXXX-YYYY-XXXXXXXXXXXX 0 0 AWS-RunShellScript 0 XXXXXXXXXX.91 50 0 XXXXXXXXXX.91Pending 待定 1 3600 CLOUDWATCHOUTPUTCONFIG 错误

INSTANCEIDS i-XXXXXXXXXX

通知配置

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

【问题讨论】:

    标签: amazon-web-services aws-ssm


    【解决方案1】:

    我尝试使用 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
    

    【讨论】:

      【解决方案2】:

      如果有人面临同样的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
      

      了解更多详情;见Get command information with response data here部分

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-02
        • 1970-01-01
        • 2018-10-29
        相关资源
        最近更新 更多