LoginSignup
6
3

More than 1 year has passed since last update.

AWS SAM CLIで生成される samconfig.toml の parameter_overrides は配列形式で記述可能

Last updated at Posted at 2021-12-11

概要

AWS SAM CLIの sam deploy --guided でデプロイする際に生成される samconfig.tomlparameter_overrides は文字列で記載されているが、配列形式で記述することで視認性が向上する。

parameter_overrides = [
    "param1=abc",
    "param2=def"
]

環境

SAM CLI, version 1.51.0

問題点

下記のような Parameters を含むテンプレートをデプロイする場合を考える。

template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sample SAM Template

Parameters:
  param1:
    Type: String
  param2:
    Type: String

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.8

sam deploy --guided で初回のデプロイを行う。

sam deploy --guided

--guided オプションによりインタラクティブに設定が進められる。

Configuring SAM deploy
======================

        Looking for config file [samconfig.toml] :  Not found

        Setting default arguments for 'sam deploy'
        =========================================
        Stack Name [sam-app]:
        AWS Region [us-east-1]: ap-northeast-1
        Parameter param1 []: abc
        Parameter param2 []: def
        #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
        Confirm changes before deploy [y/N]: 
        #SAM needs permission to be able to create roles to connect to the resources in your template
        Allow SAM CLI IAM role creation [Y/n]:
        #Preserves the state of previously provisioned resources when an operation fails
        Disable rollback [y/N]:
        Save arguments to configuration file [Y/n]: 
        SAM configuration file [samconfig.toml]: 
        SAM configuration environment [default]: 

上記の Save arguments to configuration file [Y/n]:Y とした場合、設定した項目が samconfig.toml に出力される。

samconfig.toml
version = 0.1
[default]
[default.deploy]
[default.deploy.parameters]
stack_name = "sam-app"
s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-1ru428utn0xc6"
s3_prefix = "sam-app"
region = "ap-northeast-1"
capabilities = "CAPABILITY_IAM"
parameter_overrides = "param1=\"abc\" param2=\"def\""
image_repositories = []

次回以降デプロイする際は、この samconfig.toml を直接編集し、 sam deploy コマンドによりデプロイできる。しかし、 parameter_overrides には複数のパラメータが一つの文字列として記載されており、視認性が低く編集もしにくい。

parameter_overrides = "param1=\"abc\" param2=\"def\""

解決策

parameter_overrides の記述はtomlの配列型もサポートされている。 下記のように配列形式で複数行で記載することで、視認性が向上する。

parameter_overrides = [
    "param1=abc",
    "param2=def"
]

参考URL

6
3
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
3