Tuesday, September 12, 2017

6 Simple steps to get start with AWS Lambda with in 10 minutes

How to start with Lambda in AWS is quite simple. Here i will show you how to  Run Lamba without using any Servers"Hello, World!"with AWS Lambda
you will learn the basics of running code on AWS Lambda without provisioning or managing servers. Here we will walk through how to create a Hello World Lambda function using the AWS Lambda console. And will then show you how to manually invoke the Lambda function using sample event data and review your output metrics.
Step 1: Enter the Lambda Console
When you click here, the AWS Management Console will open in a new browser window, so you can keep this step-by-step guide open.  Find Lambda under Compute and click to open the AWS Lambda Console.

Step 2: Select a Lambda Blueprint
Blueprints provide example code to do some minimal processing. Most blueprints process events from specific event sources, such as Amazon S3, DynamoDB, or a custom application.

a. In the AWS Lambda console, select Get Started Now.

If you already have Lambda functions, select Create a Lambda function.
b.  In the Filter box, type in hello-world-python and select the hello-world-python blueprint.

Step 3: Configure and Create Your Lambda Function
A Lambda function consists of code you provide, associated dependencies, and configuration. The configuration information you provide includes the compute resources you want to allocate (for example, memory), execution timeout, and an IAM role that AWS Lambda can assume to execute your Lambda function on your behalf.
a. You will now configure your Lambda function.  The list below explains the configurations and provides example values.

Configure Function:
Name: You can name your lambda function here. For this tutorial, enter hello-world-python.
Description: You can enter a short description of your function here. This is pre-populated with A starter AWS Lambda Function. 
Runtime: Currently, you can author your Lambda function code in Java, Node.js, or Python 2.7. For this tutorial, leave this on Python 2.7 as the runtime.
Lambda function code:

In this section, you can review the example code authored in Python.
Lambda function handler and role:

Handler: You can specify a handler (a method/function in your code) where AWS Lambda can begin executing your code. AWS Lambda provides event data as input to this handler, which processes the event. In this example, Lambda identifies this from the code sample and this should be pre-populated with lambda_function.lambda_handler.
Role: Click the dropdown and select Basic Execution Role.

b.  You will create an IAM role (referred as the execution role) with the necessary permissions that AWS Lambda can assume to invoke your Lambda function on your behalf. Click Allow.

You will be taken back to the Configure function page and lambda_basic_execution will be selected. 

c.  In the Advanced settings section, you can configure your memory, timeout, and VPC settings.  For this tutorial, leave the default Lambda function configuration values and click Next.

d. Review the Lambda function and click Create Function. The console saves the code into a file and then zips the file, which is the deployment package. The console then uploads the deployment package to AWS Lambda creating your Lambda function.

Step 4: Invoke Lambda Function and Verify Results
The console shows the hello-world-python Lambda function - you can now test the function, verify results, and review the logs.
a. Click Test.

b. The editor pops up to enter an event to test your function.  

Choose Hello World from the Sample event template list from the Input test event page. 
You can change the values in the sample JSON, but don’t change the event structure. For this tutorial, replace value1 with hello, world!.
Click Save and test. AWS Lambda will now execute your function on your behalf.

c.  Upon successful execution, view the results in the console:

The Execution results section verifies that the execution succeeded.
The Summary section shows the key information reported in the Log output.
The Log output section will show the logs generated by the Lambda function execution. 

Step 5: Monitor Your Metrics
AWS Lambda automatically monitors Lambda functions and reports metrics through Amazon CloudWatch. To help you monitor your code as it executes, Lambda automatically tracks the number of requests, the latency per request, and the number of requests resulting in an error and publishes the associated metrics. 
a. Invoke the Lambda function a few more times by repeatedly clicking the Test button.  This will generate the metrics that can be viewed in the next step.

b.  Choose the Monitoring tab to view the metrics for your Lambda function.  Lambda metrics are reported through Amazon CloudWatch. You can leverage these metrics to set custom alarms. For more information about CloudWatch, see the Amazon CloudWatch Developer Guide.

The Monitoring tab will show four CloudWatch metrics: invocation count, invocation duration, invocation errors, and throttled invocations.

With AWS Lambda, you pay for what you use. After you hit your AWS Lambda free tier limit, you are charged based on the number of requests for your functions (invocation count) and the time your code executes (invocation duration).  For more information, see AWS Lambda Pricing.

Step 6: Delete the Lambda Function
While you will not get charged for keeping your Lambda function, you can easily delete it from the AWS Lambda console.  

a.  Select the Actions button and click Delete Function.

b. You will be asked to confirm your termination - select Yes, Terminate.

You have created your first AWS Lambda function. This is your first step in learning how to run applications without needing to provision or manage servers. Lambda automatically scales your applications by running your code in response to each trigger, scaling precisely with the size of your workloads.