gpt4 book ai didi

aws-cloudformation - 用存储桶名称替换变量

转载 作者:行者123 更新时间:2023-12-04 08:38:31 24 4
gpt4 key购买 nike

我的这个模板可以按预期工作,并创建一个 S3 存储桶和一些 athena 查询。

https://datameetgeobk.s3.amazonaws.com/cftemplates/athena_saved_query_blog_partition_parquet.tpl

问题是:如何将 S3 存储桶名称“athenadata162a”替换为第一步中创建的存储桶名称。

external_location = 's3://athenadata162a/optimized-data11/'

创建新存储桶的代码如下所示...

"myS3Bucket" : {
"Type" : "AWS::S3::Bucket"
},

按照建议,将代码更改为 yaml,但仍然收到此错误:

Template validation error: Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to specify a mapping of values to replace in the string

代码:

Resources:
myS3Bucket:
Type: 'AWS::S3::Bucket'
createTableASParquetPartioned:
Type: 'AWS::Athena::NamedQuery'
Properties:
Database: default
Description: Create table as parquet partitioned
Name: Blog2createTableAS
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

最佳答案

通常您使用 Fn::Sub替换某些输入字符串中的变量。

在您的 YAML 中,这将类似于:

    QueryString: !Sub
- |-
CREATE table new_parquet11
WITH (format='PARQUET',
parquet_compression='SNAPPY',
partitioned_by=array['year'],
external_location = 's3://${myS3Bucket}/optimized-data11/')
...

抱歉,我不会提供 JSON 语法,因为它对于多行值来说太糟糕了。

关于aws-cloudformation - 用存储桶名称替换变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59085135/

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