AWS Cloudwatchにログを送る

CloudWatch エージェントで使用する IAM ロールおよびユーザーを作成する - Amazon CloudWatch

Amazon CloudWatch

↓古い

クイックスタート: 実行中の EC2 Linux インスタンスに CloudWatch Logs エージェントをインストールして設定する - Amazon CloudWatch Logs

https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/logs/EC2NewInstanceCWL.html

Systemd

Forward systemd service logs to AWS Cloudwatch · GitHub

SyslogIdentifier= を指定して journald - rsyslog 経由でファイルを出力すると
StandardOutput= を使わずに済む。

rsyslogとjournaldのこと – NorthPage

I think there's a more elegant way to solve the problem: send the stdout/stderr to syslog with an identifier and instruct your syslog manager to split its output by program name.

Use the following properties in your systemd service unit file:

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=<your program identifier> # without any quote

Then, assuming your distribution is using rsyslog to manage syslogs, create a file in /etc/rsyslog.d/.conf with the following content:

if $programname == '<your program identifier>' then /path/to/log/file.log
& stop

Now make the log file writable by syslog:

# ls -alth /var/log/syslog 
-rw-r----- 1 syslog adm 439K Mar  5 19:35 /var/log/syslog
# chown syslog:adm /path/to/log/file.log

Restart rsyslog (sudo systemctl restart rsyslog) and enjoy! Your program stdout/stderr will still be available through journalctl (sudo journalctl -u ) but they will also be available in your file of choice.

https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file

【systemd】StandardOutput=fileはログをファイルに出力できるけど追記されない | 純規の暇人趣味ブログ