serverless / serverless/serverless

Cannot use Fn::ImportValue function for ALB event listener due to validation error - 'ServerlessError: Invalid ALB listenerArn in function "app".'

Open
#8,440 6 comments 3 reactions 1 assignee View on GitHub

@lukeplausin is already working on this.

Since Oct 28, 2020.

question
Dominant language
JavaScript
Stars
46.9k
Forks
5.7k
Avg merge
10h 7m
Merged PRs (30d)
57

Description

I'm trying to deploy a serverless function to AWS lambda using the ALB events trigger. The ALB and listener were created in external cloudformation templates, and I'm trying to use an Fn::ImportValue function to import the listener ARN.

Since there are different stacks for different environments, it isn't really practical for me to copy and paste the ARN into the serverless.yaml file.

I believe the issue is caused by overly-strict validation checks within the core codebase. I checked in the file where the exception was thrown (lib/plugins/aws/package/compile/events/alb/lib/validate.js:100:13) and it appears to throw a validation error if the listener is a dictionary which doesn't have a Ref key. Expanding this to include other cloudformation keyworkds (Sub, ImportValue, Fn::Sub, Fn::ImportValue) might solve this.

Any suggested workarounds would be helpful.

serverless.yml
functions:
  myapp:
    handler: myapp.handler
    events:
      - alb:
          listenerArn: 
            Fn::ImportValue: !Sub myapp-${self:provider.stage}-WebLoadBalancerListenerHttpsArn
          priority: 1
          conditions:
            path: /proxy/myapp
⚠️⚠️ REPLACE WITH FULL COMMAND NAME output
Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command wsgi
Serverless: Load command wsgi:serve
Serverless: Load command wsgi:install
Serverless: Load command wsgi:clean
Serverless: Load command wsgi:command
Serverless: Load command wsgi:command:local
Serverless: Load command wsgi:exec
Serverless: Load command wsgi:exec:local
Serverless: Load command wsgi:manage
Serverless: Load command wsgi:manage:local
Serverless: Load command wsgi:flask
Serverless: Load command wsgi:flask:local
Serverless: Load command requirements
Serverless: Load command requirements:clean
Serverless: Load command requirements:install
Serverless: Load command requirements:cleanCache
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Load command dev
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Using Python specified in "runtime": python3.6
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Injecting required Python packages to package...
Serverless: [AWS sts 200 1.306s 0 retries] assumeRole({ RoleArn: 'arn:aws:iam::000000000000:role/Administrator',
  RoleSessionName: 'lplausin' })
 
  Serverless Error ---------------------------------------

  ServerlessError: Invalid ALB listenerArn in function "app".
      at AwsCompileAlbEvents.validateListenerArn (/usr/local/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/alb/lib/validate.js:100:13)
      at functionObject.events.forEach.event (/usr/local/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/alb/lib/validate.js:37:48)
      at Array.forEach (<anonymous>)
      at _.forEach (/usr/local/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/alb/lib/validate.js:34:29)
      at /usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:4925:15
      at baseForOwn (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:2990:24)
      at /usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:4894:18
      at Function.forEach (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:9368:14)
      at AwsCompileAlbEvents.validate (/usr/local/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/alb/lib/validate.js:33:7)
      at BbPromise.try (/usr/local/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/alb/index.js:21:33)
  From previous event:
      at Object.package:compileEvents [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/alb/index.js:20:29)
  From previous event:
      at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:476:22)
      at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:496:17)
      at BbPromise.try (/usr/local/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:122:50)
  From previous event:
      at Object.before:deploy:deploy [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:102:22)
      at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:476:55)
  From previous event:
      at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:476:22)
      at getHooks.reduce.then (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:511:24)
  From previous event:
      at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:511:8)
      at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:131:33)
  From previous event:
      at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:118:74)
      at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:80:26)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)
      at process.topLevelDomainCallback (domain.js:126:23)
  From previous event:
      at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless.js:80:4)
      at Module._compile (internal/modules/cjs/loader.js:778:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
      at Module.load (internal/modules/cjs/loader.js:653:32)
      at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
      at Function.Module._load (internal/modules/cjs/loader.js:585:3)
      at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
      at startup (internal/bootstrap/node.js:283:19)
      at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              10.22.1
     Framework Version:         1.74.1
     Plugin Version:            3.6.15
     SDK Version:               2.3.1
     Components Version:        2.31.12

Installed version

Framework Core: 1.74.1
Plugin: 3.6.15
SDK: 2.3.1
Components: 2.31.12

Thanks for your time

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.