I have a python script that generate pdf participation certificates based on data pulled from Google sheet and send them through Amazon SES to each individual email. I want to run that script in EC2 to benefit from the alway free Amazon SES quota. Is there an easy and quick way to trigger/execute this script remotely from Google sheet after updating the names and emails there?
CodePudding user response:
Rather than 'triggering' the code on the instance (which is difficult because you want to keep your instance secure), I would recommend an alternative architecture:
- The Google Sheet sends a message to an Amazon SQS queue
- The Python code running on your EC2 instance continuously polls the SQS queue to check for messages (use
receive_message(...,WaitTimeSeconds=20)
to reduce the number of calls - If a message is found, then the Python code can process the information (eg send an email) and then delete the message from the queue
This way, your instance can remain secure without needing to open it to the Internet.
Some services that seem to offer the ability to send messages to SQS from Google Sheets:
- AWS - SQS - Send Message with AWS API on New Worksheet (Shared Drive, Instant) from Google Sheets API - Pipedream
- Pricing Plans | Appy Pie Connect
- Or, you might be able to write that functionality yourself
Otherwise, you'd need to run a web server on the EC2 instance and have the Google Sheet 'call' the web server with your request.
Or, if you want to get fancy, you could convert your code into an AWS Lambda function and use API Gateway to 'call' the code. This way, you won't need an Amazon EC2 instance but it is more complex to configure.