# Would like to run Python scripts once every 50mins (Take around 2mins to run), best way to setup?

**URL:** <https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755>\
**Category:** AWS Compute Discussion\
**Tags:** ec2\
**Created:** [May 11, 2018, 4:18pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755 "2018-05-11T16:18:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 11, 2018, 4:18pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/1 "2018-05-11T16:18:51Z")

</div>

I know they now charge per min, how can I automate once every 50mins I open an instance for a few mins, up to 5mins lets say of EC2, and then it computes my scripts, then closes and repeat.

* * *

**Related discussions:**

- [Reliably identify which EC2/tenant is calling in Lambda](https://awshq.com/t/reliably-identify-which-ec2-tenant-is-calling-in-lambda/21687)
- [Deciding on a System Monitoring Solution: CloudWatch or Prometheus?](https://awshq.com/t/deciding-on-a-system-monitoring-solution-cloudwatch-or-prometheus/17451)
- [AWS Support Problems](https://awshq.com/t/aws-support-problems/21648)
- [Need an optimized sandbox setup for coding agents](https://awshq.com/t/need-an-optimized-sandbox-setup-for-coding-agents/21770)
- [Performance evaluation of the new m9g instance family against previous Graviton generations (m8g, m7g, and m6g)](https://awshq.com/t/performance-evaluation-of-the-new-m9g-instance-family-against-previous-graviton-generations-m8g-m7g-and-m6g/21398)

---

<div class="post-metadata">

**Author:** ![gdbhgvhh](https://awshq.com/letter_avatar_proxy/v4/letter/g/4af34b/32.png) [@gdbhgvhh](https://awshq.com/u/gdbhgvhh)\
**Post date:** [May 11, 2018, 4:36pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/2 "2018-05-11T16:36:20Z")

</div>

Would running on a Lambda solve your problem? Just schedule it for every 50 minutes. Seems like the exact use-case for one.

---

<div class="post-metadata">

**Author:** ![ckuehn](https://awshq.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@ckuehn](https://awshq.com/u/ckuehn)\
**Post date:** [May 11, 2018, 4:37pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/3 "2018-05-11T16:37:54Z")

</div>

This sounds like a use case for Lambda. If you can get your script to work entirely within the Lambda framework, you’ll find it’s extremely inexpensive.

Otherwise, you can still trigger Lambda with a scheduled event (cron) and have a simple script launch your EC2 instance when it’s time. Make your script run at boot, and when it finishes, have it shut down the instance.

---

<div class="post-metadata">

**Author:** ![INVOKECloud](https://awshq.com/letter_avatar_proxy/v4/letter/i/8797f3/32.png) [@INVOKECloud](https://awshq.com/u/INVOKECloud)\
**Post date:** [May 11, 2018, 4:39pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/4 "2018-05-11T16:39:44Z")

</div>

> [@gdbhgvhh](#):
>
> Would running on a Lambda solve your problem? Just schedule it for every 50 minutes. Seems like the exact use-case for one.

This might work for bring up. Shutdown, better go with “resource usage (or) Idle instance” based approach by using CloudWatch Alarms.

---

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 11, 2018, 4:47pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/5 "2018-05-11T16:47:18Z")

</div>

> [@ckuehn](#):
>
> This sounds like a use case for Lambda. If you can get your script to work entirely within the Lambda framework, you’ll find it’s extremely inexpensive. Otherwise, you can still trigger Lambda with a scheduled event …

sure I’ve not done much with AWS other than S3 website hosting.

Is it hard to make script work entirely in lambda framework? Where do I get started learning about this?

---

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 11, 2018, 4:47pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/6 "2018-05-11T16:47:25Z")

</div>

> [@gdbhgvhh](#):
>
> Would running on a Lambda solve your problem? Just schedule it for every 50 minutes. Seems like the exact use-case for one.

Maybe I have no idea I am new to AWS

---

<div class="post-metadata">

**Author:** ![zfo](https://awshq.com/letter_avatar_proxy/v4/letter/z/f14d63/32.png) [@zfo](https://awshq.com/u/zfo)\
**Post date:** [May 11, 2018, 6:27pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/7 "2018-05-11T18:27:38Z")

</div>

> [@TechySpecky](#):
>
> sure I’ve not done much with AWS other than S3 website hosting. Is it hard to make script work entirely in lambda framework? Where do I get started learning about this?

Not sure what you are running but if its simple script, lambda does support python 2.7 so it could be simple to migrate your code.

If you add additional modules to import you can package it via virtualenv

[https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html](https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html)

---

<div class="post-metadata">

**Author:** ![orangebot](https://awshq.com/letter_avatar_proxy/v4/letter/o/ecae2f/32.png) [@orangebot](https://awshq.com/u/orangebot)\
**Post date:** [May 11, 2018, 7:13pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/8 "2018-05-11T19:13:39Z")

</div>

yep. this is exactly what i use lambda for.

---

<div class="post-metadata">

**Author:** ![Amazon-SageMaker](https://awshq.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@Amazon-SageMaker](https://awshq.com/u/Amazon-SageMaker)\
**Post date:** [May 11, 2018, 7:36pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/9 "2018-05-11T19:36:32Z")

</div>

> [@TechySpecky](#):
>
> sure I’ve not done much with AWS other than S3 website hosting. Is it hard to make script work entirely in lambda framework? Where do I get started learning about this?

[https://aws.amazon.com/lambda/](https://aws.amazon.com/lambda/)

I am novice as well and got 3 services tied together with Lambda working in a few hours.

My use case was deploying a SageMaker endpoint which is required to be called from a Lambda function for security. The Lambda outputs JSON and then I exposed the Lambda function to web request with API Gateway.

During my implementation of this I discovered nothing but comments of peoples minds blown at how powerful Lambda could be for replacing various infrastructure including even hosting an entire web app.

---

<div class="post-metadata">

**Author:** ![exvancouverite](https://awshq.com/letter_avatar_proxy/v4/letter/e/4491bb/32.png) [@exvancouverite](https://awshq.com/u/exvancouverite)\
**Post date:** [May 11, 2018, 8:48pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/10 "2018-05-11T20:48:04Z")

</div>

> [@TechySpecky](#):
>
> Maybe I have no idea I am new to AWS

[https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html](https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html)

Link to doc about how to schedule events on Lambda. Ping if you need help 🙂

---

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 11, 2018, 9:11pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/11 "2018-05-11T21:11:19Z")

</div>

> [@zfo](#):
>
> Not sure what you are running but if its simple script, lambda does support python 2.7 so it could be simple to migrate your code. If you add additional modules to import you can package it via virtualenv …

it supports 3.6 now

---

<div class="post-metadata">

**Author:** ![gavin7](https://awshq.com/letter_avatar_proxy/v4/letter/g/e274bd/32.png) [@gavin7](https://awshq.com/u/gavin7)\
**Post date:** [May 11, 2018, 9:19pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/12 "2018-05-11T21:19:00Z")

</div>

> [@INVOKECloud](#):
>
> This might work for bring up. Shutdown, better go with “resource usage (or) Idle instance” based approach by using CloudWatch Alarms.

I think the idea is that a script that takes 2 minutes to run should just be a lambda function and not run on ec2 at all.

---

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 11, 2018, 9:30pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/13 "2018-05-11T21:30:28Z")

</div>

> [@gavin7](#):
>
> I think the idea is that a script that takes 2 minutes to run should just be a lambda function and not run on ec2 at all.

yea and if needed i can strip the function down. on my 50mb line my functions can be done in 1min with 350mb of ram. I could try make them more efficient

---

<div class="post-metadata">

**Author:** ![gavin7](https://awshq.com/letter_avatar_proxy/v4/letter/g/e274bd/32.png) [@gavin7](https://awshq.com/u/gavin7)\
**Post date:** [May 11, 2018, 9:47pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/14 "2018-05-11T21:47:41Z")

</div>

> [@TechySpecky](#):
>
> yea and if needed i can strip the function down. on my 50mb line my functions can be done in 1min with 350mb of ram. I could try make them more efficient

Don’t worry about memory too much as the Lambda performance (CPU and network) is tied to the memory limit you choose on the function. Running once per hour even at a full 5 minutes with 1024mb memory should still be extremely cheap.

---

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 11, 2018, 9:49pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/15 "2018-05-11T21:49:25Z")

</div>

> [@gavin7](#):
>
> Don’t worry about memory too much as the Lambda performance (CPU and network) is tied to the memory limit you choose on the function. Running once per hour even at a full 5 minutes with 1024mb memory should still be …

I’m trying to stay in the free tier if possible haha. but I definitely don’t need a gig of memory it just requests and parses some pages

---

<div class="post-metadata">

**Author:** ![gavin7](https://awshq.com/letter_avatar_proxy/v4/letter/g/e274bd/32.png) [@gavin7](https://awshq.com/u/gavin7)\
**Post date:** [May 11, 2018, 9:50pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/16 "2018-05-11T21:50:13Z")

</div>

> [@TechySpecky](#):
>
> Maybe I have no idea I am new to AWS

There are a lot of tools to make it easier or more efficient to setup/test/use Lambda functions, and I’ve personally used this one (mainly for quick local testing): [https://github.com/nficano/python-lambda](https://github.com/nficano/python-lambda)

---

<div class="post-metadata">

**Author:** ![Skaperen](https://awshq.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@Skaperen](https://awshq.com/u/Skaperen)\
**Post date:** [May 12, 2018, 5:09am UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/17 "2018-05-12T05:09:37Z")

</div>

> [@TechySpecky](#):
>
> Maybe I have no idea I am new to AWS

what does your python script (need to) do? and who does it (need to) do it to?

---

<div class="post-metadata">

**Author:** ![TechySpecky](https://awshq.com/letter_avatar_proxy/v4/letter/t/7ea924/32.png) [@TechySpecky](https://awshq.com/u/TechySpecky)\
**Post date:** [May 12, 2018, 8:16am UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/18 "2018-05-12T08:16:33Z")

</div>

> [@Skaperen](#):
>
> what does your python script (need to) do? and who does it (need to) do it to?

it’s a bot for a text based video game from 2006. it’s an assignment basically.

it uses beautifulsoup, robobrowser, re.

it goes on a site, logs in, goes to a bunch of pages, parses the html, reads it with beautiful soup then a bunch of loops and if statements decide what actions to take.

so it takes around 30 seconds per action on my 50MiB/s internet with 350mb of ram.

there are 2 actions is needs to complete every 50mins.

if you would like to see my code I can send snippets later.

---

<div class="post-metadata">

**Author:** ![Investisseur](https://awshq.com/letter_avatar_proxy/v4/letter/i/ac91a4/32.png) [@Investisseur](https://awshq.com/u/Investisseur)\
**Post date:** [May 12, 2018, 2:13pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/19 "2018-05-12T14:13:42Z")

</div>

Either Lambda as people have suggested or Celery

---

<div class="post-metadata">

**Author:** ![ryankearney](https://awshq.com/letter_avatar_proxy/v4/letter/r/b3f665/32.png) [@ryankearney](https://awshq.com/u/ryankearney)\
**Post date:** [May 13, 2018, 1:15pm UTC](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755/20 "2018-05-13T13:15:48Z")

</div>

> [@TechySpecky](#):
>
> it’s a bot for a text based video game from 2006. it’s an assignment basically. it uses beautifulsoup, robobrowser, re. it goes on a site, logs in, goes to a bunch of pages, parses the html, reads it with beautiful soup …

419.4Mbps? Seems like an odd speed for an ISP to provide.

[Next page](https://awshq.com/t/would-like-to-run-python-scripts-once-every-50mins-take-around-2mins-to-run-best-way-to-setup/5755.md?page=2)
