How can i fetch the real-time terminal results of AWS - EC2 executed using SSM

369 views Asked by At

I have a scenario where I'm executing the commands on EC2 via AWS-SSM(Systems Manager). These are ML training commands. So if I want to show the epochs loss and accuracy information in real-time onto the frontend, I can only show after the AWS-AnsiblePlaybook has executed the task, where the task is logged to CloudWatch and I can stream.

But if i want to show it realtime, How can I show it? Is it possible at all ?

1

There are 1 answers

1
Shawn On BEST ANSWER

Will this work for your use case? In a bash script, you can add a line like this for user data:

exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

That will cause the user-data logs to be send to the console, where they will be viewable from the EC2 console by selecting the instance and choosing Instance settings - Get System Log. So if you take wherever you are logging your commands and redirect it similarly to the console, that should give you access to the real-time logs.

Or will using S3 work, like outlined at https://aws.amazon.com/blogs/mt/streaming-aws-systems-manager-run-command-output-to-amazon-cloudwatch-logs/ ?