# Lambda Handler Wrapper | Sentry for AWS Lambda

On this page you'll learn about the options to configure the `Sentry.wrapHandler` wrapper for your Lambda function.

If you're using the AWS Lambda layer with environment variables (i.e. no Sentry code in your function), skip this guide or switch to the [initializing the SDK in code](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/install/cjs-layer.md#alternative-initialize-the-sdk-in-code).

## [Flush Timeout](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/lambda-wrapper.md#flush-timeout)

Sentry keeps the lambda function thread alive for up to 2 seconds to ensure reported errors are sent. You can change this flush time limit by defining a `flushTimeout` value in the handler options:

`index.js`

```javascript
exports.handler = Sentry.wrapHandler(yourHandler, {

  flushTimeout: 1000,

});
```

## [Timeout Warning](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/lambda-wrapper.md#timeout-warning)

Sentry reports timeout warnings when the Lambda function is within 500ms of the configured Lambda timeout. You can turn off timeout warnings by setting `captureTimeoutWarning` to `false` in the handler options.

`index.js`

```javascript
exports.handler = Sentry.wrapHandler(yourHandler, {

  captureTimeoutWarning: false,

});
```

To change the timeout warning limit, assign a numeric value (in ms) to `timeoutWarningLimit`. This value specifies the time left before the warning is triggered.

`index.js`

```javascript
exports.handler = Sentry.wrapHandler(yourHandler, {

  timeoutWarningLimit: 700, // Warn when within 700ms of timeout

});
```

## [Capture Rejected Promises in `Promise.allSettled`](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/lambda-wrapper.md#capture-rejected-promises-in-promiseallsettled)

By default, Sentry captures errors raised by your handler. However, your handler might return a `Promise.allSettled` result. In this case, even if one of the messages has failed, Sentry won't capture any exception.

The `captureAllSettledReasons` (default: `false`) option captures all promise rejected results

```javascript
exports.handler = Sentry.wrapHandler(
  () => {
    return Promise.allSettled([
      Promise.rejected(new Error("first")),
      Promise.rejected(new Error("second")),
    ]);
  },
  { captureAllSettledReasons: true },
);
// `first` and `second` errors are captured
```
