boundless-dawn-94219
07/31/2024, 3:49 AMconsole.log('Loading function');
var count = 0;
export const handler = async (event, context) => {
console.log('Received event:', JSON.stringify(event, null, 2));
console.log('count =', count++);
return event.key1;
};
count
is a module scoped variable and preserves its counter between invocations, until the lambda is torn down after being idle.
Try this with Pulumi:
export const apiLambda = createLambda({
name: 'my-lambda',
callback: handler,
});
var count: number = 0;
async function handler(event: any, context: any) {
console.log('EVENT: \n' + JSON.stringify(event, null, 2) + ` COUNT ${count++}`);
return context.logStreamName;
}
and no such luck, count
is always 0.
I guess this has something to do with how Pulumi transpiles the code.little-cartoon-10569
07/31/2024, 4:04 AMboundless-dawn-94219
07/31/2024, 4:08 AMlittle-cartoon-10569
07/31/2024, 4:09 AMlittle-cartoon-10569
07/31/2024, 4:10 AMclever-sunset-76585
07/31/2024, 4:10 AMlittle-cartoon-10569
07/31/2024, 4:11 AMboundless-dawn-94219
07/31/2024, 4:12 AMlittle-cartoon-10569
07/31/2024, 4:13 AMboundless-dawn-94219
07/31/2024, 4:13 AMboundless-dawn-94219
07/31/2024, 4:13 AMboundless-dawn-94219
07/31/2024, 4:14 AMclever-sunset-76585
07/31/2024, 4:15 AMboundless-dawn-94219
07/31/2024, 4:17 AMboundless-dawn-94219
07/31/2024, 9:49 PMlittle-cartoon-10569
07/31/2024, 9:54 PMboundless-dawn-94219
07/31/2024, 9:55 PMglamorous-spring-30202
08/02/2024, 4:53 AM<path>/index.js/ts
, for example) and that resource calls esbuild to build/bundle the lambda code and all its imports and create the FileArchive. It doesn't mix runtime/deployment code and it helps me organizing my repo.little-cartoon-10569
08/02/2024, 4:56 AMglamorous-spring-30202
08/02/2024, 4:57 AMlittle-cartoon-10569
08/02/2024, 6:33 AM