Automatically Running a Python Script in AWS Cloud for Facebook Ad Management

0

Hello everyone!

I'm completely new to the AWS world and this is my first time navigating through this platform. I have a script written in Python that connects to the Facebook API to manage ads - it turns off ads that are too expensive, monitors expenditures, and adjusts the budget for campaigns and ad sets. I'd like this script to run automatically in the AWS cloud without my intervention.

Up to this point, I haven't taken any steps towards implementing this solution in AWS because I'm unsure where to start. Could someone recommend relevant tutorials or help articles that would guide me step by step in deploying these scripts in the cloud?

Additionally, I'm concerned about how to securely manage keys and other sensitive information within AWS. Any advice or best practices on this would be greatly appreciated.

Thank you in advance for any assistance!

Tags: []

2 Answers
0

In general there are two main options to solve your issue:

AWS Lambda: This is a serverless compute service that runs your code in response to events and automatically manages the compute resources for you. If you're new to AWS Lambda, this Getting Started Guide will be helpful.

Amazon EC2: A virtual server where you can run applications on the AWS cloud. EC2 requires more manual setup compared to Lambda but offers more flexibility. Here's a guide on how to launch an EC2 instance.

For most periodic tasks like yours, Lambda is generally more cost-effective and easier to manage.

You can start by checking these workshops and tutorials on AWS Lambda: Workshops & Tutorials

Regarding managing keys and sensitive information:
AWS offers Secrets Manager and Parameter Store (part of Systems Manager) for storing sensitive data:

AWS Secrets Manager: Helps you protect access to your applications, services, and IT resources without the upfront investment. Here's a tutorial.

Systems Manager Parameter Store: Provides secure, hierarchical storage for configuration data management and secrets management. Here's a guide to help you.

You can also find a lot of hands-on labs and tutorials from here: https://github.com/Brain2life/aws-exams-preparation-guide/tree/main/labs

Choose based on your needs; for secrets like API keys, both work well, but Secrets Manager offers more features around rotation and integration with other AWS services.

profile picture
answered 6 months ago
0

Hi,

Based on your requirement, I suggest you to go for ECS deployment of Python script.

  1. Dockerize the python application. Follow the blog: https://dev.to/francescoxx/dockerize-a-python-application-1olg
  2. Upload it to Amazon Private ECR(Elastic Container Registry).
  3. Create ECS(Elastic Container Service) Cluster which runs on AWS Fargate(Serverless) supports tiny to batch workloads, zero maintenance overhead. Follow this tutorial: https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorial-ecs-deployment.html
  4. Configure an Application Load Balancer to expose the traffic.
  5. To store the sensitive information, use AWS Secret Manager to store and retrieve the keys & secrets to ECS Cluster. Follow this tutorial: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-tutorial.html

Hope this explanation helps, comment here if any thing is needed. Happy to help.!

Bhuvan

profile picture
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions