serverless/serverless

Fn::Sub for SQS event source breaks

Open

#8637 opened on Dec 17, 2020

View on GitHub
 (10 comments) (1 reaction) (0 assignees)JavaScript (46,915 stars) (5,734 forks)batch import
bugcat/aws-event-sqshelp wanted

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.

https://github.com/serverless/serverless/blob/8791cdacb75c84a2e08c5639abf769e915968288/lib/plugins/aws/package/compile/events/sqs.js#L60-L72

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):

https://github.com/serverless/serverless/blob/8791cdacb75c84a2e08c5639abf769e915968288/lib/plugins/aws/provider.js#L261-L269


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

  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