fix(serverless-offline-sqs): resolve intrinsic & pseudo-parameter ARNs to a queueName (#200, #74)#270
Merged
Merged
Conversation
d6b5c75 to
98f5931
Compare
…s to a queueName
extractQueueNameFromARN did a naive `arn.split(':')[5]`, which broke for two
common ARN shapes and produced `arn:...:undefined` (ElasticMQ then rejects with
"Missing required key 'QueueName'"):
- #200 (sndr): an `arn` given as `{Fn::Join: [sep, parts]}` (with a nested
`{Ref: AWS::AccountId}`) is an object, so the old `switch('string')` never
reached extraction at all.
- #74 (DenisOgr): serverless-pseudo-parameters leaves `#{AWS::AccountId}` in the
ARN string; the extra `::` it injects pushed split index [5] onto an empty
segment.
Fix: a pure `resolveCfnValue` flattens the intrinsic / pseudo-parameter forms
(Ref / Fn::Join / Fn::Sub, `#{AWS::X}` and `${AWS::X}`) to a string, then the
queue name is taken as the final ':'-delimited segment (robust to any number of
injected ':'). The fragile `switch('string')` is replaced by an explicit branch
that prefers an explicit queueName (the #211 override path) and otherwise derives
it from the resolved ARN. A `.fifo` suffix is intentionally preserved.
Helpers are exported and unit-tested (10 new AVA cases incl. the exact #200/#74
repros).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ments Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
98f5931 to
685d2cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extractQueueNameFromARNdid a naivearn.split(':')[5], which silently producedarn:...:undefinedfor two common ARN shapes. ElasticMQ then rejects the poll withMissing required key 'QueueName'/MissingQueryParamRejection(QueueName), and the Lambda never fires.arngiven as aFn::Joinobject (with a nested{Ref: AWS::AccountId}) is an object, so the oldswitch('string')never reached extraction at all →queueName: undefined.serverless-pseudo-parametersleaves#{AWS::AccountId}inside the ARN string; the extra::it injects pushedsplit(':')[5]onto an empty segment → empty queue name.Fix
A pure, exported
resolveCfnValueflattens the intrinsic / pseudo-parameter forms an eventarncan take —Ref,Fn::Join,Fn::Sub, and the#{AWS::X}/${AWS::X}pseudo-parameters — into a plain string. The queue name is then taken as the final:-delimited segment of the resolved ARN, which is robust to any number of:the pseudo-parameters inject. The fragileswitch('string')is replaced by an explicit branch that prefers an explicitqueueName(the #211 override path) and otherwise derives it from the resolved ARN. A.fifosuffix is intentionally preserved.Fn::GetAttis already resolved to a string ARN upstream inindex._resolveFn, so it deliberately has no branch here. Anything unresolvable offline (Fn::ImportValue, aRefto a stack resource) returnsundefinedrather than throwing — the ARN stays visibly bad instead of silently wrong.Fixes #200
Fixes #74
Testing
Fn::Join+Ref) and [serverless-offline-sqs] Doesn't work with serverless-pseudo-parameters #74 (#{AWS::AccountId}) repros, plus the pure-helper level (resolveCfnValue,extractQueueNameFromARN). Confirmed failing onmaster, passing here.npx ava packages/serverless-offline-sqs/test/index.js→ 30/30;npx eslint packages/serverless-offline-sqs/clean.package.jsonchanges (no lockfile regen needed).🤖 Generated with Claude Code