gpt4 book ai didi

aws-cloudformation - 引用 IamInstanceProfile 的 Cloudformation LaunchTemplate 无法创建

转载 作者:行者123 更新时间:2023-12-01 22:59:35 25 4
gpt4 key购买 nike

我正在尝试在我的 Cloudformation 堆栈中创建一个 LaunchTemplate,它引用 IamInstanceProfile。这是代码 - 我省略了不相关的部分:

...
Resources:
ServerLaunchTemplate:
Type: 'AWS::EC2::LaunchTemplate'
Properties:
LaunchTemplateData:
InstanceType: !Ref InstanceType
SecurityGroups:
- !Ref SecGroup
IamInstanceProfile: !Ref ServerProfile
UserData:
...
ServerProfile:
Type: 'AWS::IAM::InstanceProfile'
Properties:
Path: /
Roles:
- !Ref ServerRole
...

ServerProfile 已成功创建。但是,当堆栈创建过程到达创建 ServerLaunchTemplate 的步骤时,它会失败并出现错误:

Property validation failure: [Value of property {/LaunchTemplateData/IamInstanceProfile} does not match type {Object}]

如果我省略对 IamInstanceProfile 的引用,LaunchTemplate 将成功创建。

根据documentation以及一些应该可以工作的示例...根据我理解的错误,LaunchTemplateInstanceType 字段需要引用一个对象,但是“!Ref InstanceType”返回资源 ID。

我该如何解决这个问题?我如何检索“/LaunchTemplateData/IamInstanceProfile”字段可能需要的对象?

谢谢

最佳答案

文档中很容易错过:IamInstanceProfile 需要一个 IamInstanceProfile Cloudformation 对象,引用的 IamInstanceProfile 的 Arn 是它的一个属性。

参见https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata.html#cfn-ec2-launchtemplate-launchtemplatedata-iaminstanceprofilehttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-iaminstanceprofile.html .

这应该有效:

  PortalLaunchTemplate:
Type: 'AWS::EC2::LaunchTemplate'
Properties:
LaunchTemplateName: !Sub ${InstanceName}-launch-template
LaunchTemplateData:
ImageId: !Ref AmiId
...
IamInstanceProfile:
Arn: !GetAtt InstanceProfile.Arn

关于aws-cloudformation - 引用 IamInstanceProfile 的 Cloudformation LaunchTemplate 无法创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53854184/

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