うまく動いているやつ
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/';
以上