LoginSignup
1
0

More than 5 years have passed since last update.

AWS CloudFormation で ParameterValue のエスケープが理解できていない。

Last updated at Posted at 2018-07-09

うまく動いているやつ

Athena のクエリを作る CloudFormation のテンプレート

CommaDelimitedList 型での例

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  FieldList: 
    Description: "Columns."
    Default: ""
    Type: "CommaDelimitedList"
Resources:
  AthenaNamedQuery:
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: "sampledb"
      Description: "example"
      Name: "fieldsparameter"
      QueryString: 
        !Sub
          - |
            CREATE EXTERNAL TABLE IF NOT EXISTS sampledb.hoge (
            ${Fields}
            )
            ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
            WITH SERDEPROPERTIES (
            'serialization.format' = '1'
            ) LOCATION 's3://xxxxx/';
          - Fields: !Join [", ", !Ref FieldList]

aws-cli cloudformation の ParameterValue スペースとカンマのエスケープ

  • time bigint, type string, source string これを渡したい。
  • スペースは、1つのバックスラッシュでエスケープ。
  • カンマは、3つのバックスラッシュでエスケープ。
aws cloudformation create-stack \
  --region us-east-1 \
  --template-body file://athena.yaml \
  --parameters \
  ParameterKey=FieldList,ParameterValue=time\ bigint\\\,type\ string\\\,source\ string  \
  --stack-name foo

こんなクエリが出来上がる

CREATE EXTERNAL TABLE IF NOT EXISTS sampledb.hoge (
time bigint, type string, source string
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
'serialization.format' = '1'
) LOCATION 's3://xxxxxx/';

以上

1
0
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
1
0