Kind: Interface
Source: src/adapter/aws-lambda/types.ts
Part of: Adapter
Handler context parameter. See ://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation.
LambdaContext models the context parameter passed to an AWS Lambda handler. It contains invocation metadata, runtime settings, optional Cognito identity and client context data, and a method for checking the remaining execution time.
Properties
| Property | Type |
|---|---|
callbackWaitsForEmptyEventLoop | boolean |
functionName | string |
functionVersion | string |
invokedFunctionArn | string |
memoryLimitInMB | string |
awsRequestId | string |
logGroupName | string |
logStreamName | string |
identity | `CognitoIdentity |
clientContext | `ClientContext |
Diagram
mermaidgraph LR Handler["Lambda handler"] --> Context["LambdaContext"] Context --> Invocation["Invocation metadata"] Context --> Runtime["Runtime settings"] Context --> Identity["CognitoIdentity | undefined"] Context --> Client["ClientContext | undefined"] Context --> Remaining["getRemainingTimeInMillis()"]
Usage
tsimport type { LambdaContext } from './types';
export async function handler(
event: { action?: string },
context: LambdaContext,
) {
console.log({
requestId: context.awsRequestId,
functionName: context.functionName,
invokedFunctionArn: context.invokedFunctionArn,
remainingTime: context.getRemainingTimeInMillis(),
});
if (context.getRemainingTimeInMillis() <= 0) {
throw new Error('Lambda execution time has expired.');
}
context.callbackWaitsForEmptyEventLoop = false;
return {
requestId: context.awsRequestId,
action: event.action,
};
}
AI Coding Instructions
- Accept
LambdaContextas the handler context parameter when adapter code needs AWS Lambda invocation metadata. - Call
getRemainingTimeInMillis()before work that may exceed the Lambda execution limit. - Treat
identityandclientContextas optional values and check forundefinedbefore reading their properties. - Set
callbackWaitsForEmptyEventLooponly when the handler should return before the Node.js event loop is empty. - Keep AWS-specific context handling inside the Lambda adapter boundary.
Was this page helpful?