serverless / serverless/serverless
Fn::Sub for SQS event source breaks
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.9k
- Forks
- 5.7k
- Avg merge
- 10h 7m
- Merged PRs (30d)
- 57
Description
Using sqs event with Fn::Sub for the arn property breaks the package step. When I create my queue inside the resources section, and want to reference it, it breaks with the following error:
TypeError: EventSourceArn.split is not a function
at /...[snip].../serverless/lib/plugins/aws/package/compile/events/sqs/index.js:69:37
Which makes sense, because it breaks on the logic to try and get the queueName to add a queue to the resources itself (which I don't want). I think the whole block should be in an if/else or try/catch maybe.
I currently fixed my issue by rewriting to use Fn::GetAtt but there is a very specific use case for Fn::Sub that can be very valuable. Also, I think it should just accept any valid Arn reference, as defined by the definitions (which also allows for Ref):
serverless.yml
service: myFooService
provider:
name: aws
runtime: python3.8
stage: ${env:STAGE, 'beta'}
region: eu-west-1
timeout: 30
functions:
fooFunction:
handler: foo.bar
reservedConcurrency: 10
timeout: 30
events:
- sqs:
arn:
Fn::Sub: "#{FooQueue.Arn}"
batchSize: 25 # max events per run
maximumBatchingWindow: 10
resources:
FooQueue:
Type: AWS::SQS::Queue
serverless package output
Type Error ---------------------------------------------
TypeError: EventSourceArn.split is not a function
at /...[snip].../node_modules/serverless/lib/plugins/aws/package/compile/events/sqs/index.js:69:37
at /...[snip].../node_modules/serverless/lib/plugins/aws/package/compile/events/sqs/index.js:70:15
at Array.forEach (<anonymous>)
at /...[snip].../node_modules/serverless/lib/plugins/aws/package/compile/events/sqs/index.js:44:28
at Array.forEach (<anonymous>)
at AwsCompileSQSEvents.compileSQSEvents (/...[snip].../node_modules/serverless/lib/plugins/aws/package/compile/events/sqs/index.js:34:47)
at /...[snip].../node_modules/serverless/lib/classes/PluginManager.js:521:55
at tryCatcher (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Object.gotValue (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/reduce.js:168:18)
at Object.gotAccum (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/reduce.js:155:25)
at Object.tryCatcher (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/...[snip].../node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:456:21)
at process.topLevelDomainCallback (domain.js:137:15)
Installed version
Framework Core: 2.15.0 (local)
Plugin: 4.3.0
SDK: 2.3.2
Components: 3.4.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/plugins/aws/package/compile/events/sqs.js around the linked lines and the ARN definitions in lib/plugins/aws/provider.js. Reproduce the failure with the supplied serverless.yml by running serverless package, then verify that an SQS event using Fn::Sub is accepted without the EventSourceArn.split error and that valid ARN references remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100