LoginSignup
6
1

More than 5 years have passed since last update.

serverless.ymlで設定値を条件分岐したい

Posted at

cloudformationではよく!Ifとか!Equalを使って条件分岐書いてたのですが、
どうやらserverless.ymlではその記法ができないそうなので。。。

ex)
develop環境の場合にはdev, production環境の場合にはprodとなるような省略名の設定値'envShorten'を作りたい

serverless.yml

provider:
  name: aws
  runtime: python3.6
  region: ap-northeast-1
  stage: ${opt:stage, 'develop'}
  conf:
    #hogehoge
  iamRoleStatements:
    #hogehoge

  environment:
    ENVIRONMENT_TYPE: ${self:provider.stage}

plugins:
  #hogehoge

custom:
  envShorten:
    develop: dev
    production: prod

上記のような書き方によって、!Ifなどを使わないで条件分岐を実現できる。
上記のyml内で、実際に値を取りに行くときは

${self:custom.envShorten.${self:provider.stage}}

と指定してやれば良い

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1