Skip to content

Instantly share code, notes, and snippets.

@farshidtz
Last active February 26, 2022 14:45
Show Gist options
  • Save farshidtz/5648e6f28eda779e373acc9460919415 to your computer and use it in GitHub Desktop.
Save farshidtz/5648e6f28eda779e373acc9460919415 to your computer and use it in GitHub Desktop.
AWS Amazon Linux 2 Unattended Upgrades with Email Notifications

This guide provides instructions for setting up unattended security upgrades on Amazon Linux 2 with optional Email notifications.

To send notifications by Email, an SMTP server is required; more details below this page.

Yum-cron

For unattended upgraded, use yum-cron as recommended in https://stackoverflow.com/a/46248515/3041544

Configure yum-cron: /etc/yum/yum-cron.conf.

Relevant yum-cron config options are:

update_cmd = security
apply_updates = yes

[emitters]
system_name = example.com
emit_via = stdio,email

[email]
email_from = noreply@example.com
email_to = root
email_host = localhost

Then:

# Enable the service (start on boot)
sudo systemctl enable yum-cron
 
# Start it
sudo systemctl start yum-cron
 
# Check status
sudo systemctl status yum-cron

To see service and update logs:

# service logs
journalctl -u yum-cron
 
# yum logs
sudo tail -n 10 /var/log/yum.log*
 
# cron logs
sudo grep yum /var/log/cron
 
# email logs
sudo tail /var/mail/root

Local SMTP server

Example: https://hub.docker.com/r/namshi/smtp/

There is a limit on AWS accounts preventing a large number of outgoing limits. Need to apply to AWS to remove this limit: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-port-25-throttle/

After setting up the SMTP server, update /etc/yum/yum-cron.conf and set email_to and email_host. Example:

email_to = receiver1@example.com,receiver2@example.com
email_host = smtp.example.com:25

And restart the service:

sudo systemctl restart yum-cron

Amazon SES SMTP server

Amazon Simple Email Service (SES) SMTP config and user creation: https://eu-central-1.console.aws.amazon.com/ses/home?region=eu-central-1#smtp-settings:

Note: Amazon SES requires the verification of the domain or receiver's addresses before being able to send emails.

Setup Postfix: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/postfix.html

Don't skip prerequisites or optional steps.

Postfix will act as a local relay. So, in /etc/yum/yum-cron.conf, set the following:

email_to = receiver1@example.com,receiver2@example.com
email_host = localhost

And restart the service:

sudo systemctl restart yum-cron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment