简体   繁体   中英

AWS Lambda for IoT

I am currently using Amazon EC2 Instance for handling communication of our IoT products (development stage). I am not quite experience in scaling the specs of our instance to overcome the increase of the devices in the future. So, I am thinking of using AWS Lambda and move all the business logic from the EC2 instance to lambda. But now, there are a couple of things that I don't understand.

  1. Under advance settings of my lambda function I can set the memory allocation for my Lambda function. If I set a memory of 512mb, will this scale up automatically if my function needs more than 512mb of memory?

  2. Is the memory that I set for the lambda function used per execution? For example, I have 30 requests that needs to be processed concurrently. If my Lambda function will be executed 30 times, does that mean my 30 executions can only used up to 512mb of memory? Or I have 512mb of memory that can be used per execution?

  3. The documentation states that Amazon might reuse instance of function. So If I have 2 requests coming at the same time, and Amazon reuse the existing copy of function, does that mean there will be a chance that an instance of my function will process two request at a time?

  4. There will be a connection to database established every time a request is made. Will this connection be retained? If it is retained, then will the connection be terminated when the function instance is terminated?

  1. If you set the memory setting to 512MB, then each invocation will have exactly 512MB memory available to it. The setting defines the maximum that each invocation of your function will be able to use.

  2. Yes it is per execution (invocation).

  3. It will reuse the same function for subsequent invocations. It will not reuse a function for concurrent invocations. If you have 2 concurrent function executions they will be executed by 2 separate instances of the Lambda function.

  4. If you create the database connection when you initialize your Lambda function, instead of waiting until the handler is called, then you can retain that database connection across multiple invocations of a single instance of your function. However, when your function instance is terminated it won't be able to close the database connection gracefully. I prefer to use a database with a REST API, like DynamoDB, with AWS Lambda functions whenever possible to avoid dealing with the issues of long-lived database connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM