aws cloudformation deploy
コマンドでデプロイする時に環境変数を使いたい。素直にはできないようなので --parameter-overrides
で代用する。
template.yml
以下のようにParameters
を定義する。TargetParameter
はパラメータ名なので自由に設定可能。
AWSTemplateFormatVersion: 2010-09-09
Parameters:
TargetParameter:
Type: 'String'
Default: 'foobar'
...
参照は↓のように行う。
...
SomeEC2:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref TargetParameter
...
deployコマンド
デプロイ時に以下のようにパラメータを指定する。
aws cloudformation deploy \
--template-file template.yaml \
--capabilities CAPABILITY_IAM \
--parameter-overrides TargetParameter=ami-bec974d8 \
--stack-name foobar