Go back

A few months ago, we received an alert. EventBridge had tried to invoke a Lambda function that was not ready to handle requests, and the invocation had failed.

We had around 20 invocations of the same function, each with different parameters. Only a few failed, but that was enough to leave gaps in the data we were processing.

We attributed the problem to AWS and started investigating.

Looking inside AWS

EventBridge invoked the function through an alias named current, which pointed to the version to run. Our deployment tool updates that alias when publishing a new version.

CloudTrail gave us little context about the error. The information we found indicated that the Lambda service was unavailable, without explaining what had happened to the function.

We suspected SnapStart. When a version is published with SnapStart enabled, Lambda initializes the code and creates a snapshot. The version stays Pending until the snapshot is ready, then becomes Active and can receive invocations. AWS documents this lifecycle.

We used DevOps Agent to investigate. The agent concluded that SnapStart preparation had taken close to 30 minutes, with invocations failing during that period. We took that explanation to AWS Support to ask whether that duration was normal and why it had taken so long.

The support team pointed out that there are no SnapStart optimization-duration metrics to validate the agent’s estimate, so there was no evidence to support the 30 minutes. Their recommendation was simply to enable a dead-letter queue on EventBridge to capture more information if the failure happened again.

What the DLQ captured

A few months later, it happened again. This time, the dead-letter queue contained this error:

ResourceConflictException: The operation cannot be performed at this time. The function is currently in the following state: Pending

The version was still Pending when the invocation reached it. We still could not say how long initialization had taken, but we could now confirm the state that caused the invocation to fail.

That raised a question: “Why was the alias pointing to a version that was not ready?”

We stopped blaming AWS and assumed the problem was in our CI/CD pipeline and started designing a new deployment process:

  1. Deploy new code.
  2. Publish the new version.
  3. Wait for that version to become active.
  4. Update the current alias to point to it.

At this point the sequence looked clear. The remaining question was why the tool was allowing the alias to move before the version was ready.

The missing check

The tool was waiting for LastUpdateStatus: Successful using a GetFunction request without specifying a version. This can work for most functions, and the expectation is that a newly published version is ready. But enabling SnapStart changes something: optimization happens after the new version is published because SnapStart works with immutable artifacts.

This missing check allowed the alias to move while the version was being optimized. We had assumed the tool handled that ordering and spent the investigation looking inside AWS.

The fix was to wait for the specific published version to become active before creating or updating the alias. For an existing deployment, current stays on the previous version during that wait. If activation fails or the wait expires, deployment stops without moving the alias.

With a clear understanding of the root cause, I prepared a PR for the deployment tool, an open-source tool considered a standard choice. The contribution became part of a released fix that uses the AWS SDK’s published-version waiter, with a separate wait limit.

After upgrading the deployment tool, the deployment time went from 14 seconds to more than a minute. The logs showed it waiting for the published version to become active before updating current.

Shortened log excerpt:

03:00:31.528Z [INFO] waiting for function version to be Active [version:195]
03:00:31.681Z [INFO] function version status [version:195] [state:Pending]
03:00:36.849Z [INFO] function version status [version:195] [state:Pending]
...
03:01:39.369Z [INFO] function version status [version:195] [state:Pending]
03:01:47.745Z [INFO] function version status [version:195] [state:Active]
03:01:47.745Z [INFO] updating alias [name:current] [version:195]

In that deployment, the wait alone took about 76 seconds. The longer deployment time included a step the previous flow had skipped: waiting until the version could receive requests.

What we took for granted

As DevOps engineers, we assume things will fail, but we often look for the failure in the same places — the same way developers blame infrastructure, or users blame the application.

A library can be widely used, a standard choice, or one of the few options available. Those are reasonable considerations when choosing it, but they can also make it easier to take for granted that it will work without errors.

A familiar or standard process still needs to meet the conditions our system depends on. When something fails, it is worth checking those conditions in the steps we consider settled, too. In our case, one of those steps was missing a check, and we were able to contribute a fix back to the tool.

Newsletter

Get site updates by email.

From time to time, I’ll share updates when there’s something worth sharing.

Subscriptions are managed through Buttondown. Unsubscribe whenever you want. Buttondown’s privacy policy .


Previous post
Before implementing, understand the problem
Next post
A place to break things while learning AWS