gpt4 book ai didi

aws-cloudformation - 替换查询字符串中的变量

转载 作者:行者123 更新时间:2023-12-03 07:15:39 26 4
gpt4 key购买 nike

此模板按预期工作。但是当我将其更改为功能替换时,它会抛出错误。

工作模板:

Parameters:
MyS3Bucket:
Type: String
Resources:
createTableOriginalCsv:
Type: 'AWS::Athena::NamedQuery'
Properties:
Database: default
Description: First query to create table based on AWS bucket data
Name: Blog1CreateTableOriginalCsv
QueryString: >-
CREATE table new_parquet11 WITH (format='PARQUET',
parquet_compression='SNAPPY', partitioned_by=array['year'],
external_location = 's3://MyS3Bucket/optimized-data11/') AS SELECT
id, date, element, datavalue, mflag, qflag, sflag, obstime,
substr("date",1,4) AS year FROM original_csv WHERE
cast(substr("date",1,4) AS bigint) >= 2015 AND cast(substr("date",1,4)
AS bigint) <= 2019

将上面的查询字符串更改为此,它将不起作用:

  QueryString: !Sub
- |-
CREATE table new_parquet11 WITH (format='PARQUET',
parquet_compression='SNAPPY', partitioned_by=array['year'],
external_location = 's3://${MyS3Bucket}/optimized-data11/') AS SELECT
id, date, element, datavalue, mflag, qflag, sflag, obstime,
substr("date",1,4) AS year FROM original_csv WHERE
cast(substr("date",1,4) AS bigint) >= 2015 AND cast(substr("date",1,4)
AS bigint) <= 2019

如何替换查询字符串中的变量?

最佳答案

CloudFormation Linter警告:

E1019 Sub 应该是 Resources/createTableOriginalCsv/Properties/QueryString/Fn::Sub 的 2 数组

因为Fn::Sub要么需要两个元素的列表(一个字符串和一个变量映射),要么只需要一个字符串。您可以通过删除第一个 - 使其成为字符串,这样它就不再是包含一个字符串的列表:

  QueryString: !Sub
|-
CREATE table new_parquet11 WITH (format='PARQUET',
parquet_compression='SNAPPY', partitioned_by=array['year'],
external_location = 's3://${MyS3Bucket}/optimized-data11/') AS SELECT
id, date, element, datavalue, mflag, qflag, sflag, obstime,
substr("date",1,4) AS year FROM original_csv WHERE
cast(substr("date",1,4) AS bigint) >= 2015 AND cast(substr("date",1,4)
AS bigint) <= 2019

该行第一个 - 之后的所有内容都是 YAML 多行语法的一部分,解释如下:

https://yaml-multiline.info/

关于aws-cloudformation - 替换查询字符串中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59390737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com