Skip to content
Prompt Words
History

Serverless function

Also called: AWS Lambda, function as a service (FaaS), cloud function.

A small piece of code you upload, and the cloud platform runs it each time an event comes in, such as a file upload or an HTTP request. The platform starts as many copies as there are events at the same time and removes them when work stops. You pay only for the time your code runs, not for idle servers.

Each upload runs the function once. The platform starts instances when uploads come and shuts them down when they stop. You pay for the milliseconds of work, not for a server waiting.

Instances: 0 · PDFs converted: 0 · Billed: 0 ms

No uploads, so no instances run and nothing is billed.

    Scaled to zero

    Say it in a prompt

    Convert uploaded PDFs with a small AWS Lambda function in Node.js: trigger it on s3:ObjectCreated for the uploads/ prefix, 1,024 MB memory, 60-second timeout, and write the result to the converted/ prefix. Cap it at 50 concurrent runs (reserved concurrency) so it can't overload the database, and send failed events to a dead-letter queue.

    Vague vs precise prompt

    Vague prompt

    process the PDFs in the cloud so we don't need a server

    Typical resultWrites one Lambda that lists the whole bucket every few minutes and converts files one by one in a loop, so a busy hour hits the 15-minute timeout and some files are done twice.

    Precise prompt

    One AWS Lambda run per upload, triggered by s3:ObjectCreated on uploads/, writing to converted/; 1,024 MB, 60 s timeout, at most 50 at once, failures to a dead-letter queue.

    Typical resultEach PDF gets its own run as soon as it lands, 50 can run side by side, nothing runs (or costs) when there are no uploads, and a file that fails is kept for a retry.

    Seen on

    • AWS Lambda docs: For each request in flight at the same time, Lambda starts a separate execution environment; when one finishes, it can be reused for the next request instead of starting a new one.
    • AWS Lambda pricing: Duration is billed from when your code starts until it returns, rounded up to the nearest 1 ms; set-up (init) code is billed too, and there is no duration charge while nothing runs.

    You might describe it as

    • run my code without managing a server
    • pay only when the code runs
    • a function that runs when a file is uploaded

    Not to be confused with

    • Cold start

      Serverless means the platform starts copies of your function when events come and removes them when work stops; a cold start is the delay when it has to start a new copy.