The Lambda runtime is fully managed by AWS. Once a function is uploaded and configured, Lambda is responsible for managing the resources required to run the code.
Developers are free from the traditional overhead of configuring and maintaining server instances.
Lambda will immediately scale to meet spikes in demand.
Lambda is cost-effective as you only pay for the computational resources used. This is, of course, true for other AWS compute services, but the cost model for Lambda is more granular than EC2 for example, with resources being charged per 100 milliseconds.
Lambdas event-driven model means you can integrate nicely with a range of AWS services, but still ensure loose coupling.
It’s very low cost. The first 1 million requests are free and you have to pay 0.20 per 1 million requests thereafter!!
xxxxxxxxxx
Many people consider AWS Lambda to be a little confusing, but it is not.
It is just a simple four-step process that begins with uploading code to AWS Lambda.
The next step is to set up your code to trigger from other AWS services, HTTP endpoints, or mobile apps.
AWS Lambda will only run a code when it is triggered and will only use the computing resources needed to run it.
xxxxxxxxxx
# The lambda keyword in Python provides a
# shortcut for declaring small and
# anonymous functions:
add = lambda x, y: x + y
print(add(5, 3))
# Output
# 8
# You could declare the same add()
# function with the def keyword:
def add(x, y):
return x + y
print(add(5, 3))
# Output
# 8
# So what's the big fuss about?
# Lambdas are *function expressions*:
print((lambda x, y: x + y)(5, 3))
# Output
# 8
# • Lambda functions are single-expression
# functions that are not necessarily bound
# to a name (they can be anonymous).
# • Lambda functions can't use regular
# Python statements and always include an
# implicit `return` statement.
xxxxxxxxxx
fn = lambda_.Function(self, "MyFunction",
runtime=lambda_.Runtime.NODEJS_16_X,
handler="index.handler",
code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler"))
)
xxxxxxxxxx
Facilitates functional programming - Lambda Expression facilitates functional programming and simplifies the development a lot.
To provide the implementation of the Java 8 Functional Interface.
Reduced Lines of Code - One of the clear benefits of using lambda expression is that the amount of code is reduced, we have already seen that how easily we can create instances of a functional interface using lambda expression rather than using an anonymous class.
Passing Behaviors into methods - Lambda Expressions enable you to encapsulate a single unit of behavior and pass it to other code.
For example, to other methods or constructors.
xxxxxxxxxx
import boto3
from azure.identity import DefaultAzureCredential
from azure.graphrbac import GraphRbacManagementClient
def lambda_handler(event, context):
# Configure Azure AD authentication
credential = DefaultAzureCredential()
tenant_id = '<your-azure-ad-tenant-id>'
subscription_id = '<your-azure-subscription-id>'
graph_client = GraphRbacManagementClient(credential, tenant_id)
# Retrieve user information from Azure AD
user_id = event['user_id'] # Assuming the user ID is passed in the Lambda event
user = graph_client.users.get(user_id)
organization = graph_client.organizational_hierarchies.get(user.user_principal_name)
# Transform and map hierarchy data
agent_hierarchy = transform_hierarchy(organization)
# Update Amazon Connect agent hierarchy
connect_client = boto3.client('connect')
update_agent_hierarchy(connect_client, agent_hierarchy)
return {
'statusCode': 200,
'body': 'Agent hierarchy updated successfully.'
}
def transform_hierarchy(organization):
# Transform and map the Azure AD organization hierarchy to Amazon Connect agent hierarchy
# Implement your logic here based on your specific mapping requirements
# Return the transformed hierarchy structure
pass
def update_agent_hierarchy(connect_client, agent_hierarchy):
# Update the Amazon Connect agent hierarchy using the provided agent_hierarchy
# Implement the necessary logic to create or update queues, routing profiles, etc.
# using the connect_client
pass
The evolution or timeline of Lambda looks something like this:
On-Prem DataCenter –> IAAS –> PaaS –> containerization/Docker –> Serverless
Lambda is a compute service where you can upload your code and create a Lambda function. AWS Lambda takes care of provisioning and managing the servers that you use to run the code. You do not have to worry about operating systems, patching, scaling etc.
It is essentially described as an event-driven compute service where AWS Lambda runs your code in response to events. These events could be changes to the data in an Amazon S3 bucket or an Amazon Dynamo DB table.
Lambda events can trigger other Lambda events or call other AWS services like SQS or SNS.
xxxxxxxxxx
Runnable subTaskWithLambda = () ->
{
System.out.println("SubTaskWithLambda started...");
};
Copied!