My broken Lambda release passed CodePipeline's alarm check

My broken Lambda release passed CodePipeline's alarm check

Nine setups, three AWS runs: no traffic let broken code through, and the same rollback scenario showed Failed in all three runs, even after the good code was back.

I used AWS CodePipeline to release a Lambda function that failed every time it was called. The pipeline had an error alarm and was set to roll back if the check failed. The release still passed, and the broken code stayed live. Nobody had called the function, so there were no errors for the alarm to catch.
Then I sent five test calls to the broken version. This time, the alarm caught it and CodePipeline rolled back. The rollback shows  Failed , but the good code was already live again. The  live  alias pointed to code with the same hash as before the release, and my final call worked. The rollback failed because it checked the same alarm, which was still in  ALARM  after the broken version's errors.
A Lambda check that called the new code directly didn't have this problem. It caught the broken release, and its rollback succeeded.
AWS documents the no-traffic result. For On Success conditions,  its docs say  "OK and INSUFFICIENT_DATA meet the criteria." So this isn't a new discovery. I wanted to know which fixes work, and what happens when the check itself breaks.
I tested nine setups on real AWS in us-west-2 on November 30, 2026. I ran the same test code three times. Each setup gave the same result every time, apart from small differences in timing.
Setup
Good release
Broken release
Code live at the end
Missing data set to  missing  or  ignore 
Passed
Passed
Broken
Missing data set to  notBreaching 
Passed
Passed
Broken
Alarm already  OK  after real calls
Passed
Passed
Broken
Missing data set to  breaching 
Failed
Failed, no rollback
Broken
 AlarmStates  includes  INSUFFICIENT_DATA 
Failed
Failed, no rollback
Broken
Five test calls and a 4-minute wait
Passed
Failed and rolled back, but the rollback shows  Failed 
Good
Lambda check that calls the new code
Passed
Failed, and the rollback succeeded
Good
The ninth setup tests what happens when the Lambda check crashes. It didn't use a broken release, so it has its own section below.

Step 1: build a small pipeline

Each setup has its own function and pipeline:
Source (S3) -> Deploy (Lambda, alias "live") -> On Success check
The deploy action uses  AllAtOnce . It publishes a new version and moves all of the  live  alias's traffic to it straight away. The On Success check runs after that, so the new code is already live while the check runs. It isn't a test before release. If the check fails, the pipeline is set to roll back.
Here's the alarm check in CloudFormation:
OnSuccess:
Conditions:
- Result: ROLLBACK
Rules:
- Name: ErrorAlarm
RuleTypeId: {Category: Rule, Owner: AWS, Provider: CloudWatchAlarm, Version: "1"}
Configuration:
AlarmName: !Sub "${Name}-missing"
WaitTime: "1"
My test script builds the same settings as JSON. The alarm uses the Lambda  Errors  metric for the  live  alias. It goes into  ALARM  if there's at least one error in a 60-second period.
There are two versions of the app. The good one returns a 200 status code. This is the broken one:
def handler(event, context):
raise RuntimeError("broken release")

A permission that isn't obvious

My first trial wasn't valid. The alarm check failed with  PermissionError  for both the good and broken releases, so it never checked the alarm. A failed broken release could easily have looked like the check was working.
CloudTrail showed CodePipeline calling  cloudwatch:DescribeAlarms  on  alarm:* , but my role only allowed one alarm. I changed that one read permission:
- Effect: Allow
Action: cloudwatch:DescribeAlarms
Resource: !Sub "arn:${AWS::Partition}:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:*"
This is the policy that worked in my stack. I didn't find it in the CodePipeline pages I read, so I can't say that every setup needs it. Test your check with a good release too. If both releases fail, the check itself may be the problem.

Step 2: make sure the results mean something

For all the setups except the crashing check, the script does this:
  1. Release the good code.
  1. Release the broken code. In the alarm setups, only the five-call test calls it before step 4. The Lambda check makes its own calls.
  1. Save the release status, check results, alarm state and any rollback.
  1. Call  live  once at the end. This saves the version that ran and whether Lambda reported a function error. It doesn't check what the app returned.
Three details matter here:
  • I counted calls from the Lambda logs. Each call writes a  START  line. For the setups without calls, "no calls" means the log had no  START  lines when the script read it after the release finished. An empty  Invocations  metric doesn't prove there were no calls. In my second trial, it was still empty after I called the function.
  • I compared code hashes, not version numbers. The good code was version 2 and the broken code was version 3. After a rollback, the good code was live as version 4, not version 2. If your script waits for the old version number, it could miss a rollback that worked.
  • I matched each rollback to the release that started it. CodePipeline records the failed release's ID in the rollback's trigger. A rollback can run its own check, so I saved that result too.
Each run has its own stack and random ID. Cleanup deletes that stack and the run's log groups, then checks for leftovers. If anything remains, the run fails.

The runs I'm reporting

After the invalid first trial, a second trial showed the main behavior. My first full run then saved eight of the nine setups. The crashing-check setup reached my script's 25-minute limit, so it had no result.
I raised the limit to 60 minutes and saved more evidence. Then I ran the new code three times. The tables and timings come from those three runs. The eight results from the first full run agree with them, but I kept that run separate because its code was different.

Step 3: release broken code with no traffic

CloudWatch lets you choose  how an alarm treats missing data . Here's what happened with three of the settings:
Missing-data setting
Alarm state during the check
Broken release
 missing 
 INSUFFICIENT_DATA 
Passed
 ignore 
 INSUFFICIENT_DATA 
Passed
 notBreaching 
 OK 
Passed
The logs had no recorded Lambda starts when the script read them after the release finished, before my final test. That final call reached version 3, the broken release, and failed.
 ignore  keeps the alarm's current state. These were new alarms that started in  INSUFFICIENT_DATA , so they stayed there. An older alarm could be in a different state.
Summary of the alarm setups where the broken release passed

A summary of three saved AWS runs. The script stops if a run is incomplete, or if the code or results differ. Timings can vary.

An alarm that was already working

A new alarm with no data might be a special case. So in another setup, I made three successful calls to the good version and waited for its alarm to reach  OK . Then I released the broken code without calling it.
The saved state shows the alarm was  OK  before the broken release in all three runs.
That matters, because the script I used had a gap. If the alarm hadn't reached  OK  in seven minutes, the script would have saved its state and released the broken code anyway. This didn't happen in these runs. In v1.0.0, the script stops that case before the broken release, and the summary rejects any run where the alarm wasn't  OK . I tested this offline, but haven't rerun it on AWS.
The check still saw  OK , and the broken release passed. That  OK  came from calls to the old code. It didn't say anything about the new code.
The check also took 62 to 63 seconds, even though the alarm was  OK  beforehand. AWS's console steps say an  OK  alarm makes the check pass immediately, but  those steps  are for Entry conditions. My On Success check waited for about the  WaitTime  of one minute. Waiting doesn't create traffic.

Step 4: treat missing data as a failure

There are two obvious ways to do this. Both caused a different problem.
Set missing data to  breaching . With no data, the alarm was in  ALARM . The check failed in one or two seconds.
Add  INSUFFICIENT_DATA  to  AlarmStates :
Configuration:
AlarmName: !Sub "${Name}-states"
AlarmStates: ALARM,INSUFFICIENT_DATA
WaitTime: "1"
That check also failed in one or two seconds.  WaitTime: "1"  didn't give the alarm a minute to change state first.
Both setups stopped the broken release from passing, but they blocked the good release too. There was no rollback in either setup, so the broken code was still live at the end.
That's an important difference: a failed release doesn't always mean the old code is back. The deploy had already moved  live .
Why was there no rollback? AWS says you can only roll back to  a release that succeeded in that stage . In these two setups, the good release had failed too, and so had the automatic first run. That may be the reason, but I haven't proved it. I didn't test these settings on a pipeline that already had a successful release.
CloudWatch's docs say you might use  breaching  for a rollback alarm when its metric reports data continuously. That isn't the case here, because the function had no calls. For metrics that only report when there's an error, the docs suggest  notBreaching . But in my test, that let the broken release through.

Step 5: send test traffic

Next, I set  WaitTime  to 4. As soon as  live  moved to the broken version, the script called it five times.
All five calls failed, and the alarm went into  ALARM . The check failed after 62 to 94 seconds, and CodePipeline started a rollback. The good code was live again, and my final call worked. But the rollback was marked  Failed .
I found the reason in the rollback's own check results. After the rollback restored the good code, CodePipeline checked the same alarm again. It was still in  ALARM  because of the broken version's errors, so the rollback's check failed within one or two seconds.
So there are two separate questions:
  • Which code is live? The good code.
  • What does the pipeline show? Both the release and the rollback failed.
If your on-call team only looks at the pipeline status, they could think the broken code is still live. Check the alias and its code before you change anything.
Test traffic also adds a timing problem. The requests have to reach the new code, and the alarm needs time to react. A good release has to wait too: in this setup, its check took about four minutes.

Step 6: call the new code directly

An error alarm asks, "Did anyone see a problem?" I wanted to ask, "Does the new code work?"
CodePipeline's  LambdaInvoke rule  can run a function as the check. Mine calls the app's  live  alias and looks at the response:
def check():
r = boto3.client("lambda").invoke(
FunctionName=os.environ["TARGET"], Qualifier="live", Payload=b"{}")
body = r["Payload"].read().decode()
return (r.get("FunctionError") is None
and json.loads(body).get("statusCode") == 200)
This is a shortened version. The full one also logs the result and the version it called.
If you adapt it, there are two things to check:
  • Your app's response, not just  FunctionError . Lambda only sets  FunctionError  when the function itself fails. An app can return a 500 response without setting it. That's why my check also looks for a 200. Check something that shows your app really works.
  • The version that answered. If another release or a person can move  live , the check could test the wrong version. Lambda returns the version it ran as  ExecutedVersion , so compare it with the one you expect. During a rollback, the expected version changes too. My check only logs this version, and nothing else could move  live  in my test. I haven't tested this comparison.

Returning normally isn't enough

At first, my check returned normally for a good response and raised an error for a bad one. The good release failed too. After about 20.5 minutes, CodePipeline said the function had failed to return a result and told me to check its call to  PutJobSuccessResult .
The check has to send its result to CodePipeline:
job = event["CodePipeline.job"]["id"]
cp = boto3.client("codepipeline")
if check():
cp.put_job_success_result(jobId=job)
else:
cp.put_job_failure_result(jobId=job, failureDetails={
"type": "JobFailed",
"message": "the live version gave a bad response"})
AWS explains these calls for  Lambda actions . The LambdaInvoke rule page doesn't mention them, but my rule needed them.
The check's role needs permission to call the app. It also needs this:
- Effect: Allow
Action:
- codepipeline:PutJobSuccessResult
- codepipeline:PutJobFailureResult
Resource: "*"
AWS's example policy for Lambda actions also uses  *  for these two permissions. In my stack, they're the only ones with  Resource: "*" . The pipeline role also needs  lambda:InvokeFunction  for the check function.
Don't log the whole event. It can contain temporary credentials in  artifactCredentials , and AWS warns against logging it. My check only logs field names, never their values.

Results

  • Good release: the check passed in about 32 seconds.
  • Broken release: the check failed in about 32 seconds. CodePipeline started a rollback, and the rollback succeeded.
  • After the rollback: the check ran again and passed. The good code was live as version 4, and my final call worked.
This check tests the code that's live now, not errors from the version before it. That's why it could pass during the rollback, when the alarm was still failing.
Summary of the stricter alarm settings, test traffic and Lambda checks

The other five setups, from the same three saved runs. In  checkcrash , both releases contain good code.

Step 7: break the check itself

What if the check crashes before it can report a result? I released the good code with a working check. Then I made the check crash and released the same good code again.
Step
Result
Second good release
Failed after 1,201 to 1,229 seconds
Rollback
Started automatically
Rollback's own check
Failed after about 1,230 seconds
Final call to  live 
Worked
In each run, the two waits added up to about 40 minutes. The log shows six crashed attempts in total, so Lambda probably retried the check after each error. The log alone doesn't prove that. The rollback was also marked  Failed , because it used the same broken check.
Both releases had the same code. So the matching code hash doesn't show which release it came from. I can only say that a rollback ran,  live  moved to version 4 and the code worked.
AWS says a Lambda action times out if the function doesn't reply  for 20 minutes . In my tests, the Lambda rule also waited about 20 minutes. I only measured this setup, and I didn't find AWS's docs saying that the action's limit applies to rules.
The crashed check caused the pipeline execution to fail after the alias had already moved. Failing is the right result here, but a small bug in a check can block good releases and slow down a rollback. Handle expected errors and report them as failures:
try:
ok = check()
except Exception as e:
cp.put_job_failure_result(jobId=job, failureDetails={
"type": "JobFailed", "message": f"check error: {type(e).__name__}"})
else:
... # report success or failure, as before
I haven't tested this change on AWS. It also can't help if the function times out, can't start or doesn't have permission to report its result. Keep the check small, and test it separately before changing it.
CodePipeline's API has a   timeoutInMinutes  setting for rules , but  CloudFormation's rule page  didn't list it when I checked on December 1, 2026. cfn-lint 1.61.0 also rejected  TimeoutInMinutes , so I removed it before deploying. I haven't tested the API setting.

What I'd use

For a Lambda function that might not get traffic right after a release, I'd use a Lambda check that calls the new code and reports its result. In my tests, it was the only setup that passed the good release, caught the broken one and finished with a successful rollback.
I'd still keep the error alarm. One test request can't cover everything real users do, and the alarm can catch problems after traffic arrives. It just can't tell you that code nobody has called is working.
Make the test request safe to repeat. The check can run during both the release and the rollback, and Lambda may retry it after an error. Don't let it charge a customer, send an email or change real data.
If real users can reach  live , they could still use the broken version before the rollback finishes. To reduce that risk, test the new version before  live  moves to it, or move traffic gradually. I haven't tested either option here.

Check your own pipeline

  1. Find alarm checks that run after a deploy. For each one, ask what happens if nobody uses the new version.
  1. Check the missing-data setting:
aws cloudwatch describe-alarms --alarm-names YOUR_ALARM \
--query 'MetricAlarms[].{state:StateValue,missing:TreatMissingData}'
  1. In a test pipeline, release good code first. Make sure it succeeds, so there's a release to roll back to.
  1. Then release code that always fails, and don't call it. Did the check catch it?
  1. After a rollback, check the live code as well as the pipeline status:
aws lambda get-function-configuration --function-name YOUR_FUNCTION \
--qualifier live --query '{version:Version,code:CodeSha256}'
  1. Look at the rollback's own check. It can fail even when the good code is back.
  1. Break the check on purpose. Find out how long the release and rollback wait, and make sure your team knows.
I used boto3 for my tests and haven't run these two CLI commands. Try them in a test account first.

Check the saved results yourself

These commands don't need an AWS account. From the repo's main folder:
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python -m pytest -v
.venv/bin/python -m report.summarize alarms results/public/full-{2,3,4}.json
.venv/bin/python -m report.summarize fixes results/public/full-{2,3,4}.json
The saved files only include the fields the summary needs. The original files contain an AWS account ID, so they aren't in the repo. I ran the AWS tests with the code in commit   bc84dfe  , which matches the code hashes in the saved files. v1.0.0 adds the stricter  OK  check and its tests. The pipeline template and the other setups are the same.
All 42 offline tests pass

All 42 offline tests pass. They cover the safety checks, permissions, cleanup and summary. They don't test AWS itself.
The README also has the steps for a real AWS run. That costs money and creates three temporary IAM roles, so read the template first and use a test account. Each of my three runs took 44 to 45 minutes, mostly because of the crashing check.

What I haven't tested

  • Other deployments: I only used CodePipeline's Lambda deploy action, with  AllAtOnce . CodeDeploy, canary releases and ECS may work differently.
  • Real traffic: I used no calls, three good calls or five failing calls. Real traffic will have different timing.
  • Other alarms: I used one  Errors  alarm with one 60-second period. Other metrics and longer periods may work differently.
  • The stricter alarm settings after a successful release: in those setups, the good release failed too.
  • More complex checks: mine makes one request and checks for a 200 status code. A check that misses a bug will still let it through.
  • Other Regions and dates: all the AWS tests ran in us-west-2 on one day.
  • The new  OK  check on AWS: I've only tested it offline.
  • Cost: this is an estimate, as I haven't checked the bill. I estimated up to about $0.30 per run for CodePipeline, plus small costs for the other services. AWS's  pricing page  doesn't say whether time spent on rules is billed, so I allowed for it.
I deleted the stacks and log groups from these runs. A separate check after the last run found none of this project's stacks, buckets, functions, pipelines, alarms, roles or log groups.
This  DEV guide to stage conditions  is a useful introduction. It covers alarm-based rollbacks for problems that show up under real traffic. My tests look at what happens before that traffic arrives.

Start with one release

Pick a pipeline that relies on an error alarm. In a test copy, release code that always fails and don't call it. If the release passes, add a check that calls the new code. Then test that check with good code, broken code and a crash.
A quiet alarm doesn't prove that your release works. It may only mean that nobody has used it yet.
Code and saved results:  codepipeline-no-traffic-gate, v1.0.0 
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article