gpt4 book ai didi

amazon-web-services - 尝试在 CloudFormation 中的 UserData 中使用变量时出现错误 "One or more Fn::Sub intrinsic functions don' t 指定预期参数

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

尝试在 CloudFormation 中将 !Sub 与 UserData 中的变量一起使用时,出现此错误:

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

为什么我会收到此错误?

这是我的代码:

LinuxEC2Instance:
Type: AWS::EC2::Instance
Properties:
UserData:
Fn::Base64: !Sub
- arn_id: !If [TestEnvironment, 'id1', 'id2']
- key: !If [TestEnvironment, 'key1', 'key2']
- |
ARN_ID=${arn_id}
KEY=${key}

echo $ARN_ID
echo $KEY

最佳答案

Sub 的第一个参数必须是字符串。因此,您应该更改 UserData 中的顺序。例如:

    Fn::Base64: 
!Sub
- |
#!/bin/bash -xe

ARN_ID=${arn_id}
KEY=${key}

echo $ARN_ID
echo $KEY
- arn_id: !If [TestEnvironment, 'id1', 'id2']
key: !If [TestEnvironment, 'key1', 'key2']

关于amazon-web-services - 尝试在 CloudFormation 中的 UserData 中使用变量时出现错误 "One or more Fn::Sub intrinsic functions don' t 指定预期参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62832162/

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