Free preview: EC2 or Lambda: choosing where your code runs

Free preview lesson from AWS Essentials.

Two of the most common ways to run code on AWS are EC2 virtual servers and Lambda functions. Choosing well affects cost, effort and reliability.

EC2

  • A virtual server you control, including the operating system.
  • Suits long-running processes, steady workloads and software that needs a full server.
  • You are responsible for patching, scaling and monitoring the instance.

Lambda

  • Runs your function in response to events, with no server to manage.
  • Suits short, event-driven tasks such as processing uploads or handling API requests.
  • Billed per request and duration; has limits on run time and package size.

A quick rule of thumb

If the work is triggered by events and finishes quickly, start with Lambda. If it runs continuously or needs control of the environment, EC2 or containers usually fit better.

Exercise

List three workloads you might run. For each, note how often it runs, how long it takes and whether it needs a persistent server, then choose EC2 or Lambda and write one sentence explaining why.

Want the rest of the course? See the full AWS Essentials course page.

Educational content only. No income or earnings results are promised, and no certification, licence or credential is awarded.

Editorial & AI Disclosure