You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I call the same Lambda twice. The cold_start value should be false after the first call. However, it is still true in other calls.
Expected Behavior
cold_start value should be false in subsequent calls.
Current Behavior
cold_start value is still true in subsequent calls.
Possible Solution
Steps to Reproduce
This is the Lambda function code I use.
import{injectLambdaContext,Logger}from"../../src";import{APIGatewayProxyEvent}from"aws-lambda";importmiddyfrom"@middy/core"constpersistentKey=process.env.PERSISTENT_KEY_IN_LOG;constpersistentValue=process.env.PERSISTENT_VALUE_IN_LOG;constlogger=newLogger({persistentLogAttributes: {[persistentKey]: persistentValue,}});consttestFunction=async(event: APIGatewayProxyEvent)=>{// 1. Context data appears in log// 2. LOG_LEVEL works as expected// 3. persistentLogAttributes prop works logger.debug("##### This should not appear");logger.info("This is an INFO log with some context and persistent key");// 4. Can add additional key value in the log methodlogger.info("This is an INFO log with some context",{additionalKey: 'additionalValue'});// 5. Can log error objecttry{thrownewError('you cannot prevent this');}catch(e){logger.error("There was an error",e);}returnformatJSONResponse({message: `E2E testing Lambda function`,
event,});}constformatJSONResponse=(response: Record<string,any>)=>{return{statusCode: 200,body: JSON.stringify(response)}}exportconsthandler=middy(testFunction).use(injectLambdaContext(logger));
I deploy and trigger the Lambda function twice with this code
constsdkProvider=awaitSdkProvider.withAwsCliCompatibleDefaults({profile: process.env.AWS_PROFILE,});constcloudFormation=newCloudFormationDeployments({ sdkProvider });// WHEN lambda function is deployedconstresult=awaitcloudFormation.deployStack({stack: stackArtifact,quiet: true,});logGroupName=result.outputs[STACK_OUTPUT_LOG_GROUP];// and invoked twice (one for cold start, another for warm start)letpromises=[];for(leti=0;i<invocationCount;i++){constinvokePromise=lambdaClient.invoke({FunctionName: functionName,LogType: 'Tail',// Wait until execution completes and return all logs}).promise();}awaitPromise.all(promises);
I check CloudWatch log and found this. Notice that INIT is only in the first call (which indicates cold start)
Environment
Powertools version used:0.3.3
Packaging format (Layers, npm):npm
AWS Lambda function runtime: n/a
Debugging logs: n/a
Related issues, RFCs
n/a
The text was updated successfully, but these errors were encountered:
ijemmy
added
bug
Something isn't working
triage
This item has not been triaged by a maintainer, please wait
labels
Jan 27, 2022
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
dreamorosi
changed the title
(logger): Cold start flag is set to true in subsequent invocations
Bug: cold start flag is set to true in subsequent invocations in Logger
Nov 14, 2022
Bug description
When
logger
capture context information, it addscold_start
key with boolean value into each log.I call the same Lambda twice. The
cold_start
value should befalse
after the first call. However, it is stilltrue
in other calls.Expected Behavior
cold_start
value should befalse
in subsequent calls.Current Behavior
cold_start
value is stilltrue
in subsequent calls.Possible Solution
Steps to Reproduce
INIT
is only in the first call (which indicates cold start)Environment
Related issues, RFCs
n/a
The text was updated successfully, but these errors were encountered: