Reputation: 687
I try below aws ssm send-command
to create a file on the EC2-instance but it does not work.
aws ssm send-command --instance-ids i-XXXXXXXXXX --document-name "AWS-RunShellScript" --parameters commands="touch /home/hadoop/test2.txt" --output text
After I type the command, the command immediately return and output below message. I then check the test2.txt
does not exist on that EC2 instance. Any suggestion would be appreciated. Thanks.
`COMMAND AAAAAAAA-ZZZZ-XXXX-YYYY-XXXXXXXXXXXX 0 0 AWS-RunShellScript 0 XXXXXXXXXX.91 50 0 XXXXXXXXXX.91Pending Pending 1 3600 CLOUDWATCHOUTPUTCONFIG False
INSTANCEIDS i-XXXXXXXXXX
NOTIFICATIONCONFIG
COMMANDS touch /home/hadoop/test2.txt`
Upvotes: 2
Views: 2163
Reputation: 3545
In case someone faces the same pending
problem and the command executable in the EC2 using ssh, according to the docs:
If the command execution shows "Pending" or "InProgress" you run this command again to see the response data.
so you need to run this to see the result:
# $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
for more details; see section Get command information with response data here
Upvotes: 1
Reputation: 238081
I tried to replicate the issue using Amazon Linux 2. Indeed, the command fails. I found that the cause was that the /home/hadoop/
folder did not exist. Subsequently, you can't touch
a file in a folder that does not exist.
The solution was:
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
Upvotes: 2