AWS SAA-CO2 Serverless

Basics

Lambda is compute service to run code as functions. Don't need to set up infrastructure

Lambda doc site

Terms

Concepts

Concurrency

Set a concurrency limit. Default quota of 1000 concurrent for a region for an account
Set reserved concurrency for each function to limit the amount of your account concurrency each function can take

Use provisioned concurrency where initialisation is expensive or low latency required.

Invocation types

Synchronous: wait for the function response before continuing Asynchronous: queue event for function, return immediate response. Lambda handles retries, configure this or use failed queue. Event source queue: Batch invocation, sends multiple events from e.g. DynamoDB queue to Lambda as batch.

Languages

Limits on memory size, layers, payload size, storage etc.

setup

Choose an IAM role

Events: Lambda polls, or services poll lambda

Set memory, allocates CPU proportionately

Set timeout 3s to 15 mins.

If go high memory then goes multi thread

Concurrency: default limit 1000 per account, limit per function

Billed for the duration and memory. Logs: start, end, report

Use cases

EC2 good for custom code or big packages Vendor packages gradually moving to containers. Lambda good for custom code.

EC2 scaling

Horizontal scaling: more machines Vertical scaling: more CPU / mem / disk

Notifications

Push notifications

Pull based

Lambda does the polling of the other services (actually e.g. Dynamo DB)

Example Lambda app image resize

aws lambda create-function --function-name CreateThumbnail --zip-file fileb://function.zip --handler index.handler --runtime nodejs12.x --timeout 10 --memory-size 1024 --role arn:aws:iam::205850140633:role/jb-lambda-S3-role
--cli-binary-format raw-in-base64-out \

aws lambda invoke
--function-name CreateThumbnail
--invocation-type Event
--payload file://inputFile.txt
--cli-binary-format raw-in-base64-out
outputfile.txt

Lambda steps

Layers contain the libraries, custom runtime, dependencies you need to run the code

Function display show the resources it has access to.

Use AWS server application model (SAM) to deploy and manage Lambda functions.

Automate release process using AWS codePipeline and AWS CodeDeploy

AWS x-ray for lambda tracing.

API Gateway

Websocket

Real time 2 way comms e.g. chat apps, streaming dashboards. Persistent connection between client and server.

RESTful APIs

example dynamo db & lambda application

Stream based services: Dynamo FB, Kenesis, SQS: lambda need to poll these services, not respond to events from them.

Look at the dynamo db example