gpt4 book ai didi

amazon-web-services - 云形成中的用户数据中的引用未得到解决

转载 作者:行者123 更新时间:2023-12-03 07:28:48 27 4
gpt4 key购买 nike

我正在云形成中创建 EFS 卷,并尝试在启动模板的用户数据中引用该卷。

我尝试了在 CF 中使用 Ref 的多种语法,但每次都会遇到相同的错误。我实际上想用 EFS 做不同的事情,但发布的示例代码也不起作用

  ClusterFileSystem:
Type: AWS::EFS::FileSystem
Properties:
Encrypted: true

ClusterLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
DependsOn: ClusterFileSystem
Properties:
LaunchTemplateName: !Sub ${AWS::StackName}
LaunchTemplateData:
ImageId: !Ref 'AMIId'
SecurityGroupIds: [!GetAtt 'ClusterSecurityGroup.GroupId']
InstanceType: !Ref 'InstanceType'
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
VolumeSize: "40"
VolumeType: "gp2"
Encrypted: true
- DeviceName: "/dev/xvdcz"
Ebs:
VolumeSize: "22"
VolumeType: "gp2"
Encrypted: true
IamInstanceProfile:
Name: 'ECSHostInstanceProfile'
Monitoring:
Enabled: true
KeyName: !Ref 'Key'
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe

function setup-efs () {

{
mkdir -p /ecs-resources/${AWS::StackName}/environment
EFS_FILE_SYSTEM_ID= !Ref ClusterFileSystem
echo ${EFS_FILE_SYSTEM_ID} >> /tmp/xyz.txt
}

这是错误 -

模板格式错误:模板的资源 block 中存在未解析的资源依赖关系 [EFS_FILE_SYSTEM_ID] 调用 UpdateStack 操作时发生错误 (ValidationError):模板格式错误:模板的资源 block 中存在未解析的资源依赖关系 [EFS_FILE_SYSTEM_ID] - ”

最佳答案

您不需要在 !Sub 中使用 !Ref,要获得相同的行为,您只需引用 ${} 中的逻辑 ID 即可.

此外,您需要转义 ${EFS_FILE_SYSTEM_ID},因为您想按字面打印它而不是让 !Sub 解析它。

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

function setup-efs () {

{
mkdir -p /ecs-resources/${AWS::StackName}/environment
EFS_FILE_SYSTEM_ID= ${ClusterFileSystem}
echo ${!EFS_FILE_SYSTEM_ID} >> /tmp/xyz.txt
}

请注意 ${ClusterFileSystem} 的引用以及 EFS_FILE_SYSTEM_ID 大括号内的 !

If you specify template parameter names or resource logical IDs, such as ${InstanceTypeParameter}, AWS CloudFormation returns the same values as if you used the Ref intrinsic function. If you specify resource attributes, such as ${MyInstance.PublicIp}, AWS CloudFormation returns the same values as if you used the Fn::GetAtt intrinsic function.

还有

To write a dollar sign and curly braces (${}) literally, add an exclamation point (!) after the open curly brace, such as ${!Literal}. AWS CloudFormation resolves this text as ${Literal}.

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

关于amazon-web-services - 云形成中的用户数据中的引用未得到解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56439159/

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