General Flashcards
What is serverless?
No server setup, no iperating system installation, no db install /setup, no hardware updates, no patches, no scale management - serverless abstracts away from us = serverless still use servers but you dont’t have to wory about managing the infrastructure.
How serverless works?
Event driven computing using small, independent, stateless functions, running inside containers in the cloud.
An event trigers initialisation of a container, to which a function is loaded and executed and the c9ntainer shuts down. AWS lambda does all of tje above :).
Hello, World! With lambda & gateway
Manualy create a service with API gateway console.
Sign to the console
Look for api gateway
Create a new api ( name)
Resources screen ( create res and methods)
Create a resource ( name, endpoint)
Add a method ( GET …)
Select a mock response.
Method execution screen
Choose integration (?) response
Mapping Templates (json, put message, save)
Deploy API ( deployment stage, name, cDeploy)
Stages screen ( invoke url)
Missing authentication roken (add endpoint to root)
You can test also from mwthodnexecution screen.
The first lambda function
AWS dashbord (services - lambda)
Create function ( scratch, blueprint, repository)
From scratch ( name, runtime nodejs, role custom- accept default or chamge, cAllow)
cCreateFunction
Scroll down - can see the function
exports.handler = (event, context, callback) …
Define messages array, pick a random string in the handler and return in callback method onside the handler.
cTest ( ru) - confogure test even (empty)
Name event
cTest again.
cLogs - look atbthe latest one
Hook function to API gateway
API gateway console
Integration request:
Integration type - from mock to lambda function
Lambda region( is in the url of the ‘screen’)
Lambda function - name of the first, cSave
Are you sure …? cOk
Give permissions…? cOk
Test, cTest:
plain text - in integration response pick json template { “message”: $input.body)
Test (in method execution).
Actions, deploy
Test in the browser
Can change runtime to 8+, and replace the function woth async
Test, test in the browser.
Key features
No server management ( litle or no at all)
Easy amd efficient scalling
Built in high availability and fault tolerant
Service integration (store, send emails etc.)
No idle capacity - pay for what you use ( running code)
Not a silver buller!
Cons
Vendor lock-ins ( multi provided serverless to the rescue) Public cloud (serverless can be run in private- how? ) Some contoll given to others
AWS core services
AWS lambda (2014 others followed, aws /lambda is the winner now)
Amazon API Gateway
Amazon DynamoDB
AWS Lambda
The most important
Run your code without worying about a server.
Lambda function - each piece of code run in an isolated environment ( container)
You pay for running code only
Fine controll over who can invoke the lambda and which services a lambda can invoke.
Amazon API Gateway
Create and publish APIs,
Tightly integrates with lambdas.
Can handle thousands of concurrent calls
Access controll, version management.
Amazon DynamoDB
Highly scalable, high performance, no sql
Scale on demand, virtually unlimited r/w, response time in a single-digit miliseconds.
With dax(?, cashe) you can have microseconds
AWS additional services
Amazon S3 - web service ( think of it as frontend)
Amazon SNS - simple notifocation service - publish/subscribe
Amazon SQS - multiple publishers and consumers
AWS Step functions - orchestrate lambda functions
Amazon Kinesis ( streaming data on real time)
Amazon Athena ( use standar sql syntax to retrieve)
AWS X-Ray - debug, Amazon CloudWatch - debug amd log
Amazon Cognito - user auth an management, openid ( also custom) etc.
AWS tools and SDKs - JS, Python, Java, go
Serverless most common use cases
Application backends
S3 as frontend
Real-time streaming data processing
CI/CD for serverless
AWS SAM ( lightweight of CloudFormation, AWS SAM Templates).
The Serverless Framework - open source, a bit different syntax, plugins.
AWS CodeCommit
AWS CodeBuild
AWS CodePipeline
Envirotment setup ( IAM etc)
An account Sign to console Set up a new user AWS services, search iam User, cAdd user, name, access type, cNext Permissions
( programatic access will generate keys, no password, you can also check AWS management console access)
Attach existing policies directly (administrative for the learning purpose) cNext, cCreate Download csv Set up environment Key - value for credentials AWS_DEFAULT_REGION
Mac - in console