Kon*_*los 3 aws-cloudformation amazon-iam
我想创建一个LaunchTemplate,其中引用了一个IamInstanceProfile,在我Cloudformation堆栈。这是代码-我省略了不相关的部分:
...
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
...
Run Code Online (Sandbox Code Playgroud)
该ServerProfile被成功创建。但是,当堆栈创建过程到达创建ServerLaunchTemplate的步骤时,它将失败并显示以下错误:
Property validation failure: [Value of property {/LaunchTemplateData/IamInstanceProfile} does not match type {Object}]
Run Code Online (Sandbox Code Playgroud)
如果我省略对IamInstanceProfile的引用,则会成功创建LaunchTemplate。
根据文档和一些示例,这应该可以工作...根据我理解的错误,LaunchTemplate的InstanceType字段需要引用一个对象,但是“ !Ref InstanceType ”返回资源ID。
我怎样才能解决这个问题?我应该如何检索“ / LaunchTemplateData / IamInstanceProfile ”字段可能需要的对象?
谢谢
Tho*_*mas 11
在文档中容易错过:IamInstanceProfile需要一个IamInstanceProfile Cloudformation对象,其中所引用的IamInstanceProfile的Arn是其属性。
请参阅https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata.html#cfn-ec2-launchtemplate-launchtemplatedata-iaminstanceprofile和https://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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1325 次 |
| 最近记录: |