serverless: new `aws:accountId`, `aws:region` variables cannot be referenced/are failing to resolve

The documentation describes use of the aws:accountId and aws:region variables here. These were introduced in version 2.50.0. In version 2.54.0, these are failing to resolve with the following error message:

Invalid variable reference syntax for variable aws:accountId. You can only reference env vars, options, & files. You can check our docs for more info.
serverless.yml
frameworkVersion: "2"
service: delete-me

custom:
  namespace: ${self:service}-${opt:stage}
  config:
    env: ${file(config/${opt:stage}.yml)}
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true

plugins:
  - serverless-webpack

provider:
  name: aws
  versionFunctions: false
  stage: ${opt:stage, 'dev'}
  region: ${opt:region, 'us-east-1'}
  runtime: nodejs12.x
  tracing:
    lambda: Active
  apiGateway:
    minimumCompressionSize: 1024
    shouldStartNameWithService: true
  iamRoleStatements: []
  environment:
    AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
    APPLICATION_AND_QUALIFIER: ${self:service}
    ACCOUNT_ID: ${aws:accountId}
    REGION: ${aws:region}
    ENVIRONMENT: ${opt:stage}

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          method: get
          path: hello

resources:
  - Conditions:
      IsDev:
        Fn::Equals:
          - ${opt:stage}
          - dev
      IsNotDev:
        Fn::Not:
          - Condition: IsDev
yarn sls package --stage dev output
yarn run v1.22.10
warning ../../../../../package.json: No license field
$ sls package --service delete-me --env dev
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 upgrade
Serverless: Load command uninstall
Serverless: Load command webpack
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 Error ----------------------------------------

  ServerlessError: Invalid variable reference syntax for variable aws:accountId. You can only reference env vars, options, & files. You can check our docs for more info.
      at Variables.getValueFromSource (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:575:11)
      at Variables.splitAndGet (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:429:17)
      at /Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:366:40
      at Array.map (<anonymous>)
      at Variables.populateMatches (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:366:20)
      at Variables.populateValue (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:397:30)
      at /Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:277:12
      at Array.map (<anonymous>)
      at Variables.populateVariables (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:276:22)
      at Variables.populateObjectImpl (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:311:30)
      at /Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/serverless/lib/classes/Variables.js:192:16
      at tryCatcher (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at PromiseArray._resolve (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise_array.js:127:19)
      at PromiseArray._promiseFulfilled (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise_array.js:145:14)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:609:26)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:489:14)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at PromiseArray._resolve (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise_array.js:127:19)
      at PromiseArray._promiseFulfilled (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise_array.js:145:14)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:609:26)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:489:14)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:673:18)
      at PromiseArray._resolve (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise_array.js:127:19)
      at PromiseArray._promiseFulfilled (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise_array.js:145:14)
      at Promise._settlePromise (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:609:26)
      at Promise._settlePromise0 (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/Users/lwoodson/src/auctane/odd-squad-lab/nos/aws/typescript/base/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:464:21)

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

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.17.1
     Framework Version:         2.55.0 (local)
     Plugin Version:            5.4.3
     SDK Version:               4.2.6
     Components Version:        3.15.1
Serverless: Deprecation warnings:

CLI options definitions were upgraded with "type" property (which could be one of "string", "boolean", "multiple"). Below listed plugins do not predefine type for introduced options:
 - ServerlessWebpack for "out"
Please report this issue in plugin issue tracker.
Starting with next major release, this will be communicated with a thrown error.
More Info: https://www.serverless.com/framework/docs/deprecations/#CLI_OPTIONS_SCHEMA

Installed version

Framework Core: 2.54.0 (local)
Plugin: 5.4.3
SDK: 4.2.6
Components: 3.15.0
✨  Done in 1.88s.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

We need to be able to have the serverless version managed by package.json as we have many serverless projects and cannot maintain them all in lockstep on the exact same serverless version. Any ideas?

IIRC yarn is interfering with Node.js internals that are responsible for modules resolution, and that most likely causes that.

I would strongly suggest to rely on package manager that does not do that, e.g. you won’t have such issues when running serverless via npx that’s installed with npm (npx will also run project local version for you)

@lwoodson it looks that for some reason new variable resolver doesn’t pick up. It’s possible if there are issues with some vars resolution, still you should be also notified of that, and I can’t see any remark of that in your logs, and that’s puzzling

Let me try to reproduce it locally