Aws LAMBDA
Aws LAMBDA
HOW TO CREATE BASIC LAMBDA:servce as function we use lambda forb projects such as
cloud optimization
it is primary respones for devops engineer we can triggered lambda functions with
wide range of serveieces like
s3 and cloud watchwe can perform activities which are basically called as event
driven actions.
fundamentals and architexure of lambda and difference of lambda and ec2
LAMBDA:1.compute:aws will automatically create compute foryou defending upon your
requiermentsn and automatically scallup and scale down aplication once task is
done aws scale down the lambda
2.serverless
ec2 instance is pay-as -you go model and we are respons ble for scaling and upgrade
the patches manually and scale down the application manually.but lambdapoint of
there are noserver we are not bothering about servers. once the requierment is
there aws can crestae serecver for you
once requierment don aws can tear down the server for you . it is majer diffrence
of ec2 and lambda
ONEmore thing wehave getting private and public ip address with ec2 instances but
lambda point of view we cant get any ipadress. even we can not knoew it tis lambda
where this created where this availbleinstances and details about lambda
funtions.ec2 version of view we acn control subnets ip adreess and security rules
autoscalling
note: as adevops engineer we cant define serverless or server computing for
applications hosting .majorly the dev team and infrastucure team and architectteam
can decide it.
AS Adevps engineer we are work is crete lambda function or create the infrastucture
only your resons blity.as devos engineer we can use lambda fir cost optimization
like identify the stale resources and delete it or send anotification to teams
in lambda only run event driven not manually so we can configure with cloud watch
and it will trigger the task partiqular time on everyday.
SOME OF THE BEST STGES FOR USING AWS LAMBDA SERVERLESSS FUNCTIONS:
1.COST OPTIMIZATION
2 SECURITY/COMPLIENCE
3.
EBS/TYPES:1.GP2/2.GP3
how to create lambda from ui
author scrach: write from code scratch
use ablue print:this samples is provided by aws its help to developers and devops
engs
trigger alambda function is on aobject is created undervaws s3 bucket t is valid
use case.
ww notified whenever object is created under s3 the we triggerd lambda function.
we can write own code on our personal laptopalso instaed of writing here.we can
crete docker image out of the code and we can use image here
and push image to ecr
primerly supportlanguages:
go
python
ruby
nodejs
java
shell script is not supported
how to crete:
ing lambda_handler
note: default function name lambda_ handler UNTIL WE CUSTOMIZE IT.
we can add files and we can add folders also
we can wright code in terminal also other vise we can also use zip file for up
lodinfg from any where
aws lambda is a excuter taking input and genrate the output it is diffrent from
tradtional ec2 instances.
how to use realtime into lambda
note
WE NEED DEFINE 'IMPORT' FOR PRPRER LIBRRIES WE WANT USE
'LAMBDA_HANDLERS' is mandatery for writing handling function
'return repons' stsus code
zip file: its need librfary defendaries also
FIRST WENEED TO INSTALL PYTON DEFENDERIES
$pip install -r requierments.txt
then compress .py file ,read.md, requierment file make it zip file
and we need go to console of lambda
select upload file : select from local zip file
after that lambda function file name <not change handler name>
AWS LAMBDA VERIABLES ITS IMPORTENT TONUSE IN LAMBDA FUNCTIONS IN AWS LAMBDA
runtime:
archiexrure:
configurestion==>envariables========>edit>add>
KEY VALUE
MY_env_VARIABLE random_VALUE_from_ENV
how to wrte file
import json
import os
def lambda_handler(event,context):
my_var_value=os.environ.get("MY_env_VARIABLE")
# 1000 implement
return{
'statusCode':200,
'body':json.dumps('aws lambda with environment variables='+my_var_value)
}
click on daploy and test
event name: test_event_env_var
private
event json
remove all
put only down symbal
{}
NOTE: we can create more envari
bles in side the lambda and we can pass it inside lambda function
LAMBDA_layers
Layers: lambda1
custom library lambda2
layer as library for your lambda function.layers can act as librery for your
lambda function library we called as alayer it can create one time and we acn use
multiple times with multiple lambdas rthat will sav he time to you and that will
give you
more standrization for lambda function managment.
remember
version
arm
REMEMBER THIS
name of the module//1
name of the file//2
function neme//3
EXAMPLE:
import json
from my_module. my_function import function_from_lambda_layers
1 2 3
result = function_from_lambda_layers
# 1000 implement
return{
'statusCode':200,
'body': json.dumps('hello from Lambad! =' +result)
test
eventname
private
test it