AcademySky-High Systems: The AWS OdysseySector 5: Ghost in the Cloud (Lambda)

Module 5: AWS Lambda (Serverless)

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume.

Why Serverless?

Imagine you only pay for a car when you're actually driving it. That's Lambda! No idling servers, no maintenance.

Mission: The Instant API

You need to deploy a small piece of code that says "Hello" whenever it is called.

Step 1: The Permission Slip

Lambda needs a Role to run. Let's create one. Run: aws iam create-role --role-name lambda-ex --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'

Step 2: Deploy the Code

We'll create a simple JavaScript file, zip it, and upload it as a function. Run: echo 'exports.handler = async (event) => { return "Hello from CloudShell Academy!"; };' > index.js && zip function.zip index.js && aws lambda create-function --function-name hello-world --zip-file fileb://function.zip --handler index.handler --runtime nodejs18.x --role arn:aws:iam::000000000000:role/lambda-ex

booting...

Mission Control

Create an IAM Role for Lambda

Expected Command

aws iam create-role --role-name lambda-ex --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'

Deploy a Lambda Function