Skip to content

Commit

Permalink
Add info: timing out long-running lambda functions
Browse files Browse the repository at this point in the history
There is an information gap regarding long-running lambda functions
invoked synchronously via the AWS CLI under default conditions.
Two possible solutions to address this are included, these are mentioned
[here](aws/aws-cli#2657).
  • Loading branch information
cmoralesmx committed Sep 28, 2022
1 parent cad20e9 commit d4f9047
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc_source/API_Invoke.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ For [synchronous invocation](https://docs.aws.amazon.com/lambda/latest/dg/invoca

When an error occurs, your function may be invoked multiple times\. Retry behavior varies by error type, client, event source, and invocation type\. For example, if you invoke a function asynchronously and it returns an error, Lambda executes the function up to two more times\. For more information, see [Retry Behavior](https://docs.aws.amazon.com/lambda/latest/dg/retries-on-errors.html)\.

Invoking long-running Lambda functions synchonously under default CLI parameters will lead to the functions being retried after the default timeout of 60 seconds is reached regardless of their actual timeout. To prevent this from happening, you could specify the `--cli-read-timeout` option to the number of seconds to wait before timing out or you could query the timeout before invokation issuing, `aws lambda invoke --function-name LAMBDA_NAME --payload PAYLOAD --cli-read-timeout $(aws lambda-timeout LAMBDA_NAME) output.temp`. This query can be done with an alias such as the following,
```
lambda-timeout =
!f() {
aws lambda get-function-configuration --function-name "$1" --query Timeout --output text
}; f
```

For [asynchronous invocation](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html), Lambda adds events to a queue before sending them to your function\. If your function does not have enough capacity to keep up with the queue, events may be lost\. Occasionally, your function may receive the same event multiple times, even if no error occurs\. To retain events that were not processed, configure your function with a [dead\-letter queue](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#dlq)\.

The status code in the API response doesn't reflect function errors\. Error codes are reserved for errors that prevent your function from executing, such as permissions errors, [limit errors](https://docs.aws.amazon.com/lambda/latest/dg/limits.html), or issues with your function's code and configuration\. For example, Lambda returns `TooManyRequestsException` if executing the function would cause you to exceed a concurrency limit at either the account level \(`ConcurrentInvocationLimitExceeded`\) or function level \(`ReservedFunctionConcurrentInvocationLimitExceeded`\)\.
Expand Down
8 changes: 8 additions & 0 deletions doc_source/invocation-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ When you invoke a function synchronously, Lambda runs the function and waits for
aws lambda invoke --function-name my-function --cli-binary-format raw-in-base64-out --payload '{ "key": "value" }' response.json
```

Lambda functions invoked synchronoysly using the AWS CLI under default conditions are subject to the default time out of 60 seconds. For long-running Lambda functions this will lead to them being retried regardless of their actual timeout. To prevent this from happening, you could specify the `--cli-read-timeout` option to the number of seconds to wait before timing out or you could query the timeout before invokation issuing `aws lambda invoke --function-name LAMBDA_NAME --payload PAYLOAD --cli-read-timeout $(aws lambda-timeout LAMBDA_NAME) output.temp`. This query can be done with an alias such as the following,
```
lambda-timeout =
!f() {
aws lambda get-function-configuration --function-name "$1" --query Timeout --output text
}; f
```

The cli\-binary\-format option is required if you are using AWS CLI version 2\. You can also configure this option in your [AWS CLI config file](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam)\.

You should see the following output:
Expand Down

0 comments on commit d4f9047

Please sign in to comment.