Reference no: EM133883403
Cloud Database & Serverless Function using Lambda
Part 1: DynamoDB
Objective
How to work on tables in DynamoDB using AWS DynamoDB GUI management console
Creating a new table:
In the aws management console click "services" and then click "dynamodb"
Click create table
In the table name box type "Music"
For primary key, type "Artist" and select "String"
Select "Add Sort Key" and in the new field type "SongTitle" and leave string selected
In the table setting page leave "Use Default Setting" selected and click "Create Table"
Adding and modifying data
In the next page, for the "Artist" attribute, enter "No One You Know" in the value field
For the "Song Title" attribute (also of type STRING), enter "Call Me Today" in the value field
Create and additional attribute by clicking the tab Add New Attribute.
In the drop down list select "String" type and a new attribute row will be added.
For the new attribute enter below values In the "Field" box enter "AlbumTitle" In the "Value" box enter "Somewhat Famous"
Create another new attribute again
In the drop down list select "Number" and a new attribute will be added
For the new attribute enter the following values In the "Field" box enter "Year"
In the "value" box enter "2015"
Click Create Item to store the new item with its four attributes. If you click the
Item you just have created, you will find something like the following screenshot:
Now create second and third item as per below
After creating two more items as above, you will see as below:
Modify an existing item in the Table
Click "Tables" from the left navigation menu to return to the list of tables
Click radio button next to the "Music" table to select it
Click the "Explore Items" tab and select the item with "Year" having a value of "2014"
click the "Actions" drop-down, and select "Edit"
For "Year" attribute value, change 2014 to 2013 as below
Querying the table
Click "Tables" from the left navigation menu to return to the list of tables
Check "Music" table to select it
Click the "Explore Items" tab from the "Action" drop-down menu
Click the drop-down labeled "Scan [Table] Music: Artist, SongTitle" and on the revealed panel, change selection from"Scan" to "Query"
Part 2: Create a HelloWorld serverless function with AWS Lambda
Objective
In this tutorial, you will learn the basics of running code on AWS Lambda without provisioning or managing servers. We will walk through how to create a Hello World Lambda function using the AWS Lambda console. We will then show you how to manually invoke the Lambda function using sample event data and review your output metrics. Get online assignment help services Now!
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.
In the AWS Lambda console, select Create a Function.
Note:
The console shows this page only if you do not have any Lambda functions created. If you have created functions already, you will see the Lambda > Functions page. On the list page, choose Create a function to go to the Create function page.
Select Blueprints.
Select hello-world-python from the Blueprint drop-down menu
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.
Basic Information:
Name: You can name your Lambda function here. For this tutorial, enter helloworld-python.
Role: 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. Select Create a new role from AWS policy templates.
Role name: type lambda_basic_execution Lambda Function Code:
In this section, you can review the example code authored in Python.
Go to the bottom of the page and select Create Function.
Runtime: Currently, you can author your Lambda function code in Java, Node.js, C#, Go or Python. For this tutorial, leave this on Python 3.10 as the runtime.
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 prepopulated with
lambda_function.lambda_handler.
Scroll down to configure your memory, timeout, and VPC settings. For this tutorial, leave the default Lambda function configuration values.
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.
Select Configure Test Event from the drop-down menu called "Test".
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.
Type in an event name like HelloWorldEvent.
You can change the values in the sample JSON, but don't change the event structure. For this tutorial, replace value1 with hello, world!.
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.
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.
Select Monitoring to view the results.
Scroll down to view the metrics for your Lambda function. Lambda metrics are reported through Amazon CloudWatch. You can leverage these metrics to set custom alarms.
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.
Select the Actions button and click Delete Function.
You will be asked to confirm your termination - select Delete.