Skip to content

chore(serverless-offline-sqs): allow passing queueName from config#211

Closed
mfamilia wants to merge 1 commit into
CoorpAcademy:masterfrom
mfamilia:master
Closed

chore(serverless-offline-sqs): allow passing queueName from config#211
mfamilia wants to merge 1 commit into
CoorpAcademy:masterfrom
mfamilia:master

Conversation

@mfamilia

Copy link
Copy Markdown

Seems like this functionality was once supported (see PR)

I've found that allowing queueName to be overridden via configuration can help address issues with other plugins (e.g. Lift - getlift/lift#101)

Feedback welcomed!

@phmasek

phmasek commented Nov 30, 2023

Copy link
Copy Markdown

Any plans on merging this @godu? It would be very helpful to get offline-sqs compatible with serverless-lift.

@vadymhimself

Copy link
Copy Markdown

+1 @godu

1 similar comment
@ahmadaccino

Copy link
Copy Markdown

+1 @godu

@costjonah

Copy link
Copy Markdown

another +1 to merging this in 🙂

@PMCorbett

Copy link
Copy Markdown

+1 @godu, it would be very useful to get this in

silouone added a commit that referenced this pull request Jun 19, 2026
…ueName fixes

- Serverless v4 logger migration (src/log.js shim threaded into the SQS emulator).
- Fix undefined this.region -> this.options.region so emitted events carry awsRegion. Re-implements #166 (thanks @zlalvani).
- Make SQS deleteMessageBatch entry Ids unique within a batch (index-based, <=80 chars). Re-implements #253 (thanks @flipscholtz).
- Add custom.serverless-offline-sqs.queueName override (non-mutating; strips arn so it wins for arn-bearing shapes). Re-implements #211 (thanks @mfamilia).
- Backward compatible with serverless v3. Adds docker-free unit tests. v8.1.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@silouone

Copy link
Copy Markdown
Member

Thank you @mfamilia for adding the custom.serverless-offline-sqs.queueName override — a really handy bit of configurability. We've folded this in as part of #265 (on master now, released shortly in the next release of serverless-offline-sqs), so I'm closing this in favor of #265. Much appreciated 🙏

@silouone silouone closed this Jun 20, 2026
silouone added a commit that referenced this pull request Jun 20, 2026
…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>
silouone added a commit that referenced this pull request Jun 20, 2026
…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>
silouone added a commit that referenced this pull request Jun 20, 2026
…listener per queue (#262)

A single SQS event mapping may target multiple queues via a `queueName` that is
an array (`[appLogsQueue, ediProcessingQueue]`) or a comma-separated string
(`'a,b,c'`, e.g. the `--queueName a,b` CLI form), at the event level or via the
`custom.serverless-offline-sqs.queueName` override. Previously `create()` ran
exactly one `_create` per event, so an array/comma `queueName` was String-coerced
into a single malformed queue (`'appLogsQueue,ediProcessingQueue'`) and no second
listener was ever created (#262, reported by renanlido).

Fix (sqs.js only — the SQSEventDefinition ARN-extraction path from #74/#200/#211
is already correct and is left untouched):

- normalizeQueueNames(spec) -> string[]: pure lodash/fp helper that normalizes a
  scalar / comma-separated / array `queueName` into a trimmed, de-duplicated,
  empty-dropped list; nullish/empty/whitespace input returns [] without throwing
  (preserves origin/master's non-throwing contract — the issue's proposed
  `throw new Error('missing queueName or arn')` is intentionally NOT applied).
- expandSqsEventDefinitions(options, rawDef) -> def[]: fans a raw event definition
  out into one definition per resolved queue name. The override wins and strips
  `arn`/`queueName` so SQSEventDefinition rebuilds the ARN from the override (the
  #211 contract). A scalar `queueName` yields exactly one def (zero behavior change
  for existing single-queue configs). An ARN string or `{arn}`/intrinsic object
  with no literal `queueName` is passed straight through as a single listener, so
  extractQueueNameFromARN/resolveCfnValue keeps owning name derivation (#74/#200).
- create() now fans out via expandSqsEventDefinitions before _create; _create
  receives a fully-resolved single-queue definition. resolveQueueName stays
  exported (its #211 tests remain green) but is no longer wired into _create.

Adds 14 unit tests covering scalar/array/comma forms, override precedence,
de-dup, prop preservation, immutability, and the ARN single-listener guards.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
silouone added a commit that referenced this pull request Jun 20, 2026
…listener per queue (#262)

A single SQS event mapping may target multiple queues via a `queueName` that is
an array (`[appLogsQueue, ediProcessingQueue]`) or a comma-separated string
(`'a,b,c'`, e.g. the `--queueName a,b` CLI form), at the event level or via the
`custom.serverless-offline-sqs.queueName` override. Previously `create()` ran
exactly one `_create` per event, so an array/comma `queueName` was String-coerced
into a single malformed queue (`'appLogsQueue,ediProcessingQueue'`) and no second
listener was ever created (#262, reported by renanlido).

Fix (sqs.js only — the SQSEventDefinition ARN-extraction path from #74/#200/#211
is already correct and is left untouched):

- normalizeQueueNames(spec) -> string[]: pure lodash/fp helper that normalizes a
  scalar / comma-separated / array `queueName` into a trimmed, de-duplicated,
  empty-dropped list; nullish/empty/whitespace input returns [] without throwing
  (preserves origin/master's non-throwing contract — the issue's proposed
  `throw new Error('missing queueName or arn')` is intentionally NOT applied).
- expandSqsEventDefinitions(options, rawDef) -> def[]: fans a raw event definition
  out into one definition per resolved queue name. The override wins and strips
  `arn`/`queueName` so SQSEventDefinition rebuilds the ARN from the override (the
  #211 contract). A scalar `queueName` yields exactly one def (zero behavior change
  for existing single-queue configs). An ARN string or `{arn}`/intrinsic object
  with no literal `queueName` is passed straight through as a single listener, so
  extractQueueNameFromARN/resolveCfnValue keeps owning name derivation (#74/#200).
- create() now fans out via expandSqsEventDefinitions before _create; _create
  receives a fully-resolved single-queue definition. resolveQueueName stays
  exported (its #211 tests remain green) but is no longer wired into _create.

Adds 14 unit tests covering scalar/array/comma forms, override precedence,
de-dup, prop preservation, immutability, and the ARN single-listener guards.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants