gpt4 book ai didi

amazon-web-services - AWS : cloudformation CommaDelimitedList and manual list not matching

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

我正在尝试创建一个具有默认值的 cloudformation 模板,并且我正在运行一些 !Sub 函数来将导入的参数替换到模板中。但是,我将一个列表传递给 Nodejs Lambda 函数,在发送它之前我需要 !Sub

我正在编写的代码:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Creating Athena database and tables

Parameters:
S3DataLocations:
Type: CommaDelimitedList
Description: The S3 locations where the logs are read from (Specify 'Use,Default' to inherit defaults)
Default: Use,Default

Conditions:
CustomS3DataLocations: !Equals ['Use,Default', !Join [",", !Ref S3DataLocations]]

Resources:
# Custom resource for running CreateTableFunction, to create databases
CreateLogTable:
Type: Custom::CreateLogTable
Properties:
ServiceToken: !GetAtt [CreateLogTableFunction, Arn]
S3DataLocations:
Fn::If:
- CustomS3DataLocations
- !Split
- ","
- !Sub
- s3://${LoggingBucket}/data/ApplicationLogs1/,
s3://${LoggingBucket}/data/ApplicationLogs2/,
s3://${LoggingBucket}/data/ApplicationLogs3/
- { LoggingBucket: !ImportValue Parent-LoggingBucket}
- !Ref S3DataLocations

如果我将它们作为文字外部DataTypes参数传递s3://logbucket/data/ApplicationLogs1/,s3://logbucket/data/ApplicationLogs2/,s3://logbucket/data/ApplicationLogs3/ 它工作正常并转换为 ["s3://logbucket/data/ApplicationLogs1/","s3://logbucket/data/ApplicationLogs2/","s3://logbucket/data/ApplicationLogs3/"] 并由 Lambda 毫无问题地进行解释。该参数通过 CommaDelimitedList 类型进行解析,并顺利传递给 Lambda。

问题的出现是因为我正在尝试创建手动默认值,因此我需要 !Sub 列表作为字符串,然后将 !Split 传递作为自定义 Lambda 的实际列表。这似乎并不是我尝试的每一种方法都有效,而且我不明白为什么。

我一直在检查成功(手动参数)和失败(默认,没有手动参数),但我看不出有什么大的区别。lambda 的事件显示,工作时:

{
"RequestType": "Create",
"ServiceToken": "hidden",
"ResponseURL": "hidden",
"StackId": "hidden",
"RequestId": "hidden",
"LogicalResourceId": "CreateLogTable",
"ResourceType": "Custom::CreateLogTable",
"ResourceProperties": {
"S3DataLocations": [
"s3://loggingbucket/data/ApplicationLogs/",
"s3://loggingbucket/data/ApplicationLogs/",
"s3://loggingbucket/data/ApplicationLogs/",
"s3://loggingbucket/data/ApplicationLogs/"
]
}
}

不工作时:

...
{
"RequestType": "Create",
"ServiceToken": "hidden",
"ResponseURL": "hidden",
"StackId": "hidden",
"RequestId": "hidden",
"LogicalResourceId": "CreateLogTable",
"ResourceType": "Custom::CreateLogTable",
"ResourceProperties": {
"S3DataLocations": [
"s3://logging/data/ApplicationLogs/",
" s3://loggingbucket/data/ApplicationLogs/",
" s3://loggingbucket/data/ApplicationLogs/",
" s3://loggingbucket/data/ApplicationLogs/"
]
}
}

我有点卡在这里,我认为可能存在一些类型不匹配,但我无法区分手册和参数之间的区别。

有人知道吗?

最佳答案

您可以使用引号和斜杠组合将字符串分成多行,同时防止将\n更改为空格。

为了验证这一点,我针对您的情况使用了以下代理模板:


Resources:

MyBucket:
Type: AWS::S3::Bucket
Properties: {}

Outputs:
Test1:
Value: !Sub
- s3://${LoggingBucket}/data/ApplicationLogs1/,
s3://${LoggingBucket}/data/ApplicationLogs2/,
s3://${LoggingBucket}/data/ApplicationLogs3/
- { LoggingBucket: "Parent-LoggingBucket"}

Test2:
Value: !Sub
- "s3://${LoggingBucket}/data/ApplicationLogs1/,\
s3://${LoggingBucket}/data/ApplicationLogs2/,\
s3://${LoggingBucket}/data/ApplicationLogs3/"
- { LoggingBucket: "Parent-LoggingBucket"}

Test1 生成带有空格的字符串,如您的问题所示:

s3://Parent-LoggingBucket/data/ApplicationLogs1/, s3://Parent-LoggingBucket/data/ApplicationLogs2/, s3://Parent-LoggingBucket/data/ApplicationLogs3/

相比之下,Test2 没有空间:

s3://Parent-LoggingBucket/data/ApplicationLogs1/,s3://Parent-LoggingBucket/data/ApplicationLogs2/,s3://Parent-LoggingBucket/data/ApplicationLogs3/

关于amazon-web-services - AWS : cloudformation CommaDelimitedList and manual list not matching,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63688277/

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