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
A lambda expression is a short block
of code which takes in parameters
and returns a value. Lambda expressions
are similar to methods, but they do
not need a name and they can be
implemented right in the body of a method.
parameter -> expression
To use more than one parameter, wrap them in parentheses:
(parameter1, parameter2) -> expression
Example
Use a lamba expression in the ArrayList's
forEach() method to print every item in the list:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers.add(5);
numbers.add(9);
numbers.add(8);
numbers.add(1);
numbers.forEach( (n) -> { System.out.println(n); } );
}
}
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.
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
Runnable subTaskWithLambda = () ->
{
System.out.println("SubTaskWithLambda started...");
};
Copied!