I'm looking to set up an automation script in Python that will check an Outlook mailbox every 5 minutes. The script needs to identify emails with a specific subject, extract the server and service details from the email body, and determine if the server is EC2 or on-premises. Depending on the server type, it should restart a Tomcat service using AWS SSM for EC2 instances or via Paramiko SSH for on-prem servers. After restarting the service, the script should send a confirmation email back. I'm seeking advice on the best architecture, configuration, and deployment strategy to accomplish this without relying on any heavy frameworks, while keeping security, idempotency, and auditability in mind. I have some ideas, like using win32 for accessing Outlook, and for the connection to EC2 and private servers, using SSH with Paramiko. The email volume is pretty low, about 20-50 emails a day, so it seems feasible to implement a lightweight solution with Python, as my manager has provided a server with Python pre-installed.
2 Answers
To get started, you'll want to ensure you have the right permissions set up in IAM for SSM if you're going to manage EC2 instances. Using a clear regex to parse your email can help extract the needed details effectively. You'll also want to catch any exceptions during your operations, like service restart failures, to maintain idempotency.
Are you retrieving outlook emails directly from a client? If that's the case, tools like win32 might be what you're looking for. However, if you're open to suggestions, using Graph API would have made it smoother, but I get that you're restricted on that.
Yeah, it's unfortunate about the API limitation, but I think I can make do with what's available for now.

That's a good point! Also, you should consider logging each operation and sending those logs back in your confirmation email for audit purposes.