简体   繁体   中英

AWS Lambda Layers: does it have a cold start separated from the main lambda?

I mean, when the main lambda starts, does it awaits the layers start before? What is happening is that my main lambda is presenting errors at the first start(when its cold) while including contents from the layers. At the second execution, everything works fine and the content from the layer is included as expected. Are my suspicious right? Is this behavior something expected? Just to you guys have in mind: the content from these layers aren't heavy, have simple variables with some keys and salts used to encryption functions.

Edit 1:

content from layer: chat_privatekey_salt.php

<?php
$salt='xxxxxxxxxxxxxxxxxxxxxxx/xxxxx+xxx=';
?>

content from main lambda: dowork.php

<?php
require_once('pusher_7.0.2/autoload.php'); //this comes from the current lambda
function fake_trigger($channels,$event,$data){
    require_once('/bref/lib/php/pem_files/chat_privatekey_salt.php'); //comes from layer, error is here
    foreach($channels as $value){
        //do some work using variable $salt 
    }
}
?>

The error is: Notice: Undefined variable: salt in /var/task/assets/libs/dowork.php on line 6

The problem wasn't the lambda layer or the path neither. Actually the problem was the require_once(). After adding some lines of code to log the value of $salt, I noticed that it works properly at the first time of calling function fake_trigger, but the at the next calls it fails due to the behavior of require_once which works as its name explicitly say(lol). So changing it by include() have made de trick.

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