简体   繁体   中英

What is the easiest way to execute python script in EC2 server remotely?

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?

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM