Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Using the Lambda context object to retrieve TypeScript function information

Focus mode
Using the Lambda context object to retrieve TypeScript function information - AWS Lambda

When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment.

To enable type checking for the context object, you must add the @types/aws-lambda package as a development dependency and import the Context type. For more information, see Type definitions for Lambda.

Context methods
  • getRemainingTimeInMillis() – Returns the number of milliseconds left before the execution times out.

Context properties
  • functionName – The name of the Lambda function.

  • functionVersion – The version of the function.

  • invokedFunctionArn – The Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a version number or alias.

  • memoryLimitInMB – The amount of memory that's allocated for the function.

  • awsRequestId – The identifier of the invocation request.

  • logGroupName – The log group for the function.

  • logStreamName – The log stream for the function instance.

  • identity – (mobile apps) Information about the Amazon Cognito identity that authorized the request.

    • cognitoIdentityId – The authenticated Amazon Cognito identity.

    • cognitoIdentityPoolId – The Amazon Cognito identity pool that authorized the invocation.

  • clientContext – (mobile apps) Client context that's provided to Lambda by the client application.

    • client.installation_id

    • client.app_title

    • client.app_version_name

    • client.app_version_code

    • client.app_package_name

    • env.platform_version

    • env.platform

    • env.make

    • env.model

    • env.locale

    • Custom – Custom values that are set by the client application.

  • callbackWaitsForEmptyEventLoop – Set to false to send the response right away when the callback runs, instead of waiting for the event loop to be empty. If this is false, any outstanding events continue to run during the next invocation.

Example index.ts file

The following example function logs context information and returns the location of the logs.

Note

Before using this code in a Lambda function, you must add the @types/aws-lambda package as a development dependency. This package contains the type definitions for Lambda. For more information, see Type definitions for Lambda.

import { Context } from 'aws-lambda'; export const lambdaHandler = async (event: string, context: Context): Promise<string> => { console.log('Remaining time: ', context.getRemainingTimeInMillis()); console.log('Function name: ', context.functionName); return context.logStreamName; };
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.