Skip to content

fix(cli-internal): handle ResourceNotFoundException in fetchFunctionSchedule#14891

Open
adrianjoshua-strutt wants to merge 2 commits into
devfrom
fix/eventbus-rule-14883
Open

fix(cli-internal): handle ResourceNotFoundException in fetchFunctionSchedule#14891
adrianjoshua-strutt wants to merge 2 commits into
devfrom
fix/eventbus-rule-14883

Conversation

@adrianjoshua-strutt
Copy link
Copy Markdown
Member

Description

Fixes #14883.

When a Lambda function has no CloudWatch Events rule (i.e., it is not a scheduled function), the DescribeRuleCommand API throws ResourceNotFoundException. Previously, this call was not wrapped in error handling, causing the entire amplify gen2-migration generate command to crash.

Fix

Wrap the DescribeRuleCommand call in a targeted try-catch that catches only ResourceNotFoundException and returns undefined (no schedule found). This matches the existing error-handling pattern already used for GetPolicyCommand in the same method. Non-ResourceNotFoundException errors (permissions, network) still propagate.

Testing

  • Added aws-fetcher.test.ts with 7 test cases covering:
    • Happy path (rule exists → returns schedule expression)
    • GetPolicyCommand throws ResourceNotFoundException → returns undefined
    • DescribeRuleCommand throws ResourceNotFoundException → returns undefined (the bug scenario)
    • Non-ResourceNotFoundException errors propagate from both API calls
    • Policy has no schedule rule reference → returns undefined
    • Policy response has no Policy field → returns undefined
  • All existing snapshot tests (12/12) and function generator tests (7/7) continue to pass.

@adrianjoshua-strutt adrianjoshua-strutt marked this pull request as ready for review May 18, 2026 16:29
@adrianjoshua-strutt adrianjoshua-strutt requested a review from a team as a code owner May 18, 2026 16:29
@adrianjoshua-strutt adrianjoshua-strutt changed the base branch from gen2-migration to dev May 18, 2026 17:40
@adrianjoshua-strutt adrianjoshua-strutt force-pushed the fix/eventbus-rule-14883 branch from 2acec73 to a81d064 Compare May 18, 2026 20:46
soberm
soberm previously approved these changes May 19, 2026
sarayev
sarayev previously approved these changes May 19, 2026
@adrianjoshua-strutt adrianjoshua-strutt self-assigned this May 19, 2026
…chedule

When a Lambda function has no CloudWatch Events rule (non-scheduled
functions), the DescribeRuleCommand API throws
ResourceNotFoundException. This crashed the entire gen2-migration
generate command.

Wrap the DescribeRuleCommand call in a try-catch that specifically
catches ResourceNotFoundException and returns undefined (no
schedule), matching the existing pattern for GetPolicyCommand.
Add 7 unit tests covering all fetchFunctionSchedule scenarios.

Closes #14883
---
Prompt: Fix issue #14883 — ResourceNotFoundException in
fetchFunctionSchedule when function has no CloudWatch Events rule.
@adrianjoshua-strutt adrianjoshua-strutt force-pushed the fix/eventbus-rule-14883 branch from a81d064 to a73dea9 Compare May 21, 2026 15:38
@adrianjoshua-strutt adrianjoshua-strutt dismissed stale reviews from soberm and sarayev via 955a3ec May 21, 2026 17:44
@benjeater
Copy link
Copy Markdown

@adrianjoshua-strutt Are you able to provide an ETA for when this will be merged in and released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(gen2-migration): Error during amplify gen2-migration generate - "Rule <env> does not exist on EventBus default"

4 participants