Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Serverless Architectures with AWS

You're reading from  Serverless Architectures with AWS

Product type Book
Published in Dec 2018
Publisher Packt
ISBN-13 9781789805024
Pages 226 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Mohit Gupta Mohit Gupta
Profile icon Mohit Gupta
Toc

Chapter 1: AWS, Lambda, and Serverless Applications


Solution for Activity 1: Creating a New Lambda Function That Finds the Square Root of the Average of Two Input Numbers

  1. Click on Create a function to create your first Lambda function on the AWS Lambda page.

  2. On the Create function page, select Author from scratch.

  3. 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.

  4. Now click on Create function.

  5. Go to the Function code section.

  6. 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);
    };
  7. Click on the dropdown next to Select a test event in the top-right corner of the screen and select Configure test event.

  8. When the popup appears, click on Create new test event and give it a name. Click on Create and the test event gets created.

  9. Click on the Test button next to test events and you should see the following window upon successful execution of the event:

    Figure 1.18: Test successful window

Solution for Activity 2: Calculating the Total Lambda Cost

  1. 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.

  2. Calculate the total compute time in seconds.

    Total compute (seconds) = 20M * (1s) = 20,000,000 seconds

  3. Calculate the total compute time in GB-s.

    Total compute (GB-s) = 20,000,000 * 512MB/1024 = 10,000,000 GB-s

  4. 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

  5. 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

  6. 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

  7. Calculate the monthly request charges. Here's the formula:

    Monthly request charges = Monthly billable requests * Monthly request price

                                                 = 19M * $0.2/M

                                                 = $3.8

  8. Calculate the total cost. Here's the formula:

    Total cost = Monthly compute charge + Monthly request charges

                      = $160.02 + $3.8

                      = $163.82

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime