Serverless Framework で Pseudo Parameters を使う

Serverless FrameworkAWSPseudo Parameters を使うのに少し悩んだのでメモとして残します。

うまくいったパターン

2通りの方法で定義しています(var1 と var2)。

service: hello
provider:
  name: aws
  runtime: nodejs8.10

custom:
  accountId: 
    Ref: 'AWS::AccountId'

functions:
  hello:
    handler: handler.hello
    environment:
      var1: ${self:custom.accountId}
      var2: 
        Ref: 'AWS::AccountId'

うまくいかないパターン

Serverless Framework では ${} のように囲まれた部分を、定義されている変数で置換しようとするためエラーになってしまいました。

service: hello
provider:
  name: aws
  runtime: nodejs8.10

functions:
  hello:
    handler: handler.hello
    environment:
      var1:
        Fn::Sub:
          '${Ref: AWS::AccountId}'