This is Hello World of Amazon EC2 with cloud-init.
brew install terraform
brew cask install session-manager-plugin
# provision the resources
terraform init
terraform apply
This example will launch an instance running a background service.
% aws ssm start-session --target i-0935e9832a6391309 --region us-west-2
$ tail -f /tmp/helloworld.log
Thu May 28 11:29:08 UTC 2020
Thu May 28 11:29:09 UTC 2020
Thu May 28 11:29:10 UTC 2020
...