AWS lambda HelloWorld!!!

AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of the Amazon Web Services. It is a computing service that runs code in response to events and automatically manages the computing resources required by that code. It was introduced in November 2014.

Function as a Service — FAAS (Server less)

In this tutorial, we are taking an existing blueprint hello world example to explore lambda. 

AWS Lambda provides you with computing power in the cloud by allowing you to execute code without standing up or managing servers.

AWS Lambda is offer service to run code without thinking about the server and pay only for the compute time you consume.

Topics Covered:-

  • Author a Lambda function using Node.js via the aws management console
  • Test a Lambda function via the aws console

Tips

  • Lambda is found under the Compute section on the AWS Management Console.
  • Lambdas have a time limit of 15 minutes.
  • The code you run on AWS Lambda is called a “Lambda function.”
  • Lambda code can be triggered by other AWS services.
  • AWS Lambda supports Java, Go, PowerShell, Node.js, C#/.NET, Python, and Ruby. There is a Runtime API that allows you to use other programming languages to author your functions.
  • Lambda code can be authored via the management console.

Go to Lambda →Click on create function → in search select Runtime and runtime environment is nodejs you can select what you prefer.

Then select the hello-world blueprint.

Steps:-

  1. Create a Lambda Function:- Enter function name. Execution role select “Choose or create an execution role” 

2. Click on create function:- 

3. Click on the Test button to provide some test data:- provide some test data and click on creat button

Once this is done scroll down, you will see code editor and on top of that “Test” button is there click on it and you will see the result on the console.

This is very basic let us do one thing modify the existing function line no 5 with below line of code and save 

body: JSON.stringify('Hello ' + event.key1 + ' from Maheshwar!'),

Scroll down to the “Basic settings” section.

  • For the Description, enter “My Function”.
  • Change the “TimeOut” from 3 seconds to 5 minutes.
  • Click the “Save” button in the upper right-hand corner.

Now Test your code changes and enjoy!!

FireStore now supports IN Queries & array-contains!!

Firestore with new in and array-contains-any queries.

This is the good news for cloud firestore developers, the pain point they are facing unable to use of ‘in’ operator.

Image result for firestore

Cloud FireStore is NoSQL database built for global apps.

Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web apps — at a global scale. Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform.

The importance of ‘in’ is like a pinch of salt in day to day life.

In Query:

With the in query, you can query a specific field for multiple values (up to 10) in a single query. You do this by passing a list containing all the values you want to search in, and Cloud Firestore will match any document whose field equals one of those values.

in queries are the best way to run simple OR queries in Cloud Firestore. For instance, if the database for your E-commerce app had a customer_orders collection and you wanted to find which orders had a “Ready to ship”, “Out for delivery” or “Completed” status, this is now something you can do with a single query, like so:

collection(“orders”)
.where(
“status”, 
“in”, 
[“Ready to ship”, “Out For Delivery”, “Completed”]
)

one more example:-

citiesRef.where('country', 'in', ['India', 'Japan','CostaRica']);

array-contains-any query:

Firestore launched another feature similar to the in query, the array-contains-any query. This feature allows you to perform array-contains queries against multiple values at the same time.

In your e-commerce site has plenty of products with an array of categories that every item belongs in, and you want to fire a query to fetch products with a category such as “Appliances” or “Electronics” then.

collection(“products”).where(
 “category”,
 “array-contains-any”,
 [“Appliances”,”Electronics”]
)

one more example: 

citiesRef.where('regions', 'array-contains-any',
['west_coast', 'east_coast']);

Note:- These queries are also supported in the Firebase console, which gives you the ability to try them out on your dataset before you start modifying your client code.

Remember:

  • As we mentioned earlier, you’re currently limited to a maximum of 10 different values in your queries.
  • You can have only one of these types of operations in a single query. You can combine these with most other query operations, however.

References:-

https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html

https://firebase.google.com/docs/firestore/query-data/queries