0

Would it be possible to use AWS Lambda to run unsafe user scripts? It should be:

  • should have memory limit (seems like AWS Lambda has it).
  • should have execution timeout (seems like AWS Lambda also has it). Additionally it should be impossible to setup something like setInterval(consumeLittleCpu, 500).
  • (would be nice to have) different scripts should be isolated.

Would it be efficient? Like for example you have let's say 5000 different scripts and every one of it get executed once for every 1-30 sec?

How much more would it cost compared to do the same using usual AWS instance? Order of magnitude precision would be fine, like saying "it will cost you no more than 10x same on usual AWS instance" would be good enough.

1 Answer 1

2

It doesn't sound like a very good use case to me.

Lambda containers get reused. Generally you can use all functionality your programming language offers including timers. They will get freezed between executions, but would probably resume on reuse. Some languages might allow you to limit the scripts content. I remember that with PHP servers could prohibit the calling of certain functions, but I assume that you couldn't configure that using Lambda. If you would want real isolation you will have to setup one Lambda Function for each script. This could be done automatically, but still sounds like a mess to me. If you isolate each script, you have to take into account the time needed for the first execution which could be slow and the time required if the Lambda function hasn't been called for a while.

Lambda has some limits of which some can be increased some cannot. You could hit the increase-able concurrent executions.

Somehow you would have to trigger your Lambdas. You could use Cloudwatch for it.

As you already figured out you can limit memory and execution time. Price-wise you only pay what you actually use, which is usually much cheaper than having instances running half idle most of the time. If you fully utilize the EC2/Elastic Beanstalk instances they would be cheaper.

Updated: Pricing is $0.00001667 per GB-second billed in 100 ms blocks plus a request fee of $0.20 per 1 million requests after a generous free tier.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Can you please tell me how the cost-time is calculated in case of freshly-started or restart-from-the-scratch container? Will I pay for all time container-startup+nodejs-startup+execution or nodejs-startup+execution or just for the execution execution time?
I.e. let's say there are two cases: "script will be ran 10 times, once per every hour and container will be killed and restarted from the scratch every time" and "same script will be ran same 10 times, but now once per second so container will be reused" - will the cost be the same or different?
I cannot tell you on Node.js times, Java takes quite a while for the first request. Node.js is supposed to start much faster. You cannot directly influence the Lambda reuse unless you update/delete it every time. With 10 times an hour you can more or less ignore the startup/warmup time when reusing a function. That is already frequent. Best thing for you would be to try one of the templates and use the non expiring free tier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.