Cloudformation - 在中间添加字符串

0

【以下的问题经过翻译处理】 我在AWS CloudFormation中合并字符串,但出现错误。有一个参数是Environment。我尝试使用join创建EndpointIdentifier,但不起作用,请告诉我正确的格式。报错为: Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.

最终结果应该是,如果从下拉列表中选择dev,则为fp-epk-dev-dms-source或fp-epk-dev-dms-target。代码如下所示:

AWSTemplateFormatVersion: 2010-09-09 Parameters: Enviroment: Type: String Default: "dev" AllowedValues: - "dev" - "uat" - "prod" Resources: DMSSourceEndpoint: Type: "AWS::DMS::Endpoint" Properties: EndpointIdentifier: !Join - '' - 'fp-epk-' - !Ref Enviroment - '-dms-source' EngineName: "ORACLE" EndpointType: "source" Username: !Ref Username Password: !Ref Password ServerName: !Ref SourceServer Port: !Ref SourcePort DatabaseName: !Ref SourceDatabase
ExtraConnectionAttributes: "addSupplementalLogging=Y"

DMSTargetEndpoint: Type: "AWS::DMS::Endpoint" Properties: EndpointIdentifier: !Join - '' - '-epk-' - !Ref Enviroment - '-dms-target' EngineName: "S3" EndpointType: "target"

profile picture
专家
已提问 2 年前73 查看次数
1 回答
0

【以下的回答经过翻译处理】 您好,在这种情况下,建议使用Fn::Sub 内在函数 [1]。您可以定义一个类似以下的参数:

Enviroment: Type: String Default: "dev" AllowedValues: - "dev" - "uat" - "prod"

然后在 AWS::DMS::Endpoint 资源中,对于 'EndpointIdentifier' 选项,可以像这样定义它:

Description: "Endpoint test" Resources: BasicEndpoint: Type: "AWS::DMS::Endpoint" Properties: .... EndpointIdentifier: !Sub 'fp-epk-${Environment}-dms-target' .... ....

这将使用所选 Environment 参数的值填充伪参数 ${Environment}。

希望对您有用。如果您还有其他问题,请告诉我!

参考资料:

[1]https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html

profile picture
专家
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则