Click on Create a function to create your first Lambda function on the AWS Lambda page.
On the Create function page, select Author from scratch.
In the Author from scratch window, fill in the following details:
Name: Enter myFirstLambdaFunction.
Runtime: Choose Node.js 6.10. The Runtime window dropdown shows the list of languages that are supported by AWS Lambda and you can author your Lambda function code in any of the listed options. For this activity, we will author our code in Node.js.
Role: Choose Create new role from template(s). In this section, you specify an IAM role.
Role name: Enter lambda_basic_execution.
Policy templates: Select Simple Microservice permissions.
Now click on Create function.
Go to the Function code section.
Use the Edit code inline option, and enter this code:
exports.handler = (event, context, callback) => { // TODO let first_num = 10; let second_num = 40; let avgNumber = (first_num+second_num)/2 let sqrtNum = Math.sqrt(avgNumber) callback(null, sqrtNum); };
Click on the dropdown next to Select a test event in the top-right corner of the screen and select Configure test event.
When the popup appears, click on Create new test event and give it a name. Click on Create and the test event gets created.
Click on the Test button next to test events and you should see the following window upon successful execution of the event:
Note the monthly compute price and compute time provided by the Free Tier.
The monthly compute price is $0.00001667 per GB-s and the Free Tier provides 400,000 GB-s.
Calculate the total compute time in seconds.
Total compute (seconds) = 20M * (1s) = 20,000,000 seconds
Calculate the total compute time in GB-s.
Total compute (GB-s) = 20,000,000 * 512MB/1024 = 10,000,000 GB-s
Calculate the monthly billable compute in GB- s. Here's the formula:
Monthly billable compute (GB- s) = Total compute – Free tier compute
= 10,00,000 GB-s – 400,000 Free Tier GB-s
= 9,600,000 GB-s
Calculate the monthly compute charges in dollars. Here's the formula:
Monthly compute charges = Monthly billable compute (GB-s) * Monthly compute price
= 9,600,000 * $0.00001667
= $160.02
Calculate the monthly billable requests. Here's the formula:
Monthly billable requests = Total requests – Free tier requests
= 20M requests – 1M Free Tier requests
= 19M Monthly billable requests
Calculate the monthly request charges. Here's the formula:
Monthly request charges = Monthly billable requests * Monthly request price
= 19M * $0.2/M
= $3.8
Calculate the total cost. Here's the formula:
Total cost = Monthly compute charge + Monthly request charges
= $160.02 + $3.8
= $163.82