aws_lambda - henk52/knowledgesharing GitHub Wiki
AWS Lambdas
Introduction
Purpose
Open questions
- How to handle webhooks, e.g. gitlab webhook on local ubuntu
- how to test lambda code on local ubuntu machine?
- AWS Lambda Runtime Interface Emulator (RIE)
- Moto (for AWS service mocking)
- LocalStack (Full AWS Simulation)
Reference
TODO
- how to deploy lambdas
- what languages are supported by lambdas
Overview
- Supported language
- C#
- Go
- Java
- Node.js
- PowerShell
- Python
- Ruby
- Rust
Writing lambdas
JS Lambda script
-
handler(event, context) - the entry function
- event - a JSON formatted document that contains data for your function to process.
- context - contains information about the function invocation and execution environment.
-
TODO Clean-up https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html#gettingstarted-cleanup
Layers
- TODO look into layers Creating a .zip deployment package with dependencies
- TODO Creating and deleting layers in Lambda
- TODO Adding layers to functions
- TODO Managing Lambda dependencies with layers
- TODO Using AWS SAM with layers
Creating a project
- ?
- cd my_function
- ?
- npm install aws-xray-sdk ?
- Create a directory under node_modules with the name of your module and save your custom written packages there.
- zip -r ../my_deployment_package.zip .
Deploying Lambdas
Deploying lambdas manually
-
.zip
- index.mjs
Deploying lambdas using serverless
-
osls
-
Official Serverless Framework docs β The getting started guide at serverless.com/framework/docs is well-structured and assumes AWS familiarity.
- It walks through creating, deploying, and managing Lambda functions with CloudFormation under the hood, which is great for understanding how the two connect.
-
AWS's own Lambda documentation β Before diving deep into Serverless Framework abstractions, it helps to understand the raw Lambda execution model, cold starts, and IAM role requirements.
- The AWS Lambda Developer Guide covers this well.
-
"Serverless Stack" (sst.dev) β This is a free, comprehensive tutorial that builds a full-stack app step by step. It's particularly good because it explains the CloudFormation concepts as they come up rather than assuming you already know them.
-
Yan Cui's "Production-Ready Serverless" course β Yan is one of the most respected voices in the serverless space.
- His course goes beyond basics into real-world patterns like structured logging, error handling, and performance optimization β things a senior engineer will want to know quickly.
-
"Serverless Architectures on AWS" by Peter Sbarski β A good book for someone who already thinks in infrastructure terms but needs to shift their mental model toward event-driven, function-as-a-service patterns.[3:55 PM]I completely agree with Claude's conclusion
-
For someone with strong AWS experience, I'd suggest starting with the official Serverless Framework docs alongside the Lambda developer guide, then moving to the SST tutorial for hands-on practice.
- The framework essentially generates CloudFormation templates, so as he works through examples, the CloudFormation side will start clicking naturally.
Logs
AWS Console - Cloudwatch logs
Find the logs Directly in Cloudwatch
- Navigate to: AWS Console -> CloudWatch -> Logs -> Log groups
- Find the log group
- Search for: /aws/lambda/pre-production-engineEntityListAlpha
- Or filter by: /aws/lambda/pre-production-
- View logs
- Click on the log group
- Click on any log stream to see the actual logs
- Log streams are organized by date/time
- Alternative: From Lambda Console
- Go to Lambda
Find the logs via the lambda entry
- AWS Console -> Lambda -> Functions
- Find the function
- Search for: pre-production-engineEntityListAlpha
- View logs
- Click on the function
- Go to the Monitor tab
- Click View CloudWatch logs button
- Or click View logs in CloudWatch from the dropdown
Get the logs via aws cli
-
List recent log streams
-
aws logs describe-log-streams --log-group-name /aws/lambda/pre-production-engineEntityListAlpha --order-by LastEventTime --descending --max-items 10
-
or Get the latest logs (last 10 minutes)
- aws logs tail /aws/lambda/pre-production-engineEntityListAlpha --since 10m --follow
Recipes
List all lambdas with a specific env var
- aws lambda list-functions --query "Functions[?Environment.Variables.S3_STATIC_TENANT_ROLE != null].FunctionName" --output text | tr '\t' '\n' | grep -v '^$' | sort