amazon-cloudformation - 获取通过 LaunchConfiguration 创建的 EC2 的属性
问题描述
我想获取我通过 LaunchConfiguration 创建的 EC2 的 PrivateIP 属性。
我需要该属性,以便我可以将 A 类型的 dns 记录分配给实例以用于其他目的。
这是我的代码:
Resources:
webLaunchConfig:
Type: 'AWS::AutoScaling::LaunchConfiguration'
Properties:
ImageId: !Ref webEc2AMI
InstanceType: !Ref ec2WebInstanceType
SecurityGroups: !Ref webEc2SG
UserData:
'Fn::Base64': !Sub >
#!/bin/bash -xe
apt update -y
dnsWebServerName:
Type: 'AWS::Route53::RecordSet'
Properties:
HostedZoneId: !Ref hostedZoneId
Comment: DNS name for my db server.
Name: !Ref dnsWebServerNamePar
Type: A
TTL: '900'
ResourceRecords:
- !GetAtt webLaunchConfig.PrivateIp
...当我尝试启动它时,我收到此错误:
模板包含错误。:模板错误:资源 webLaunchConfig 不支持 Fn::GetAtt 中的属性类型 PrivateIp
...表明我不支持我正在尝试做的事情。虽然必须有一种方法来实现这一点。
你知道怎么做吗?或者解决方法?
解决方案
可悲的是你不能这样做。AWS::AutoScaling::LaunchConfiguration
只是要启动的实例的蓝图。因此它不提供有关 instance的信息PrivateIp
。获取PrivateIp
您必须实际启动实例。
为此,您必须使用AWS::EC2::Instance。但是AWS::EC2::Instance
不支持从 ``AWS::AutoScaling::LaunchConfiguration . So either you have to change your
LaunchConfiguration into
LaunchTemplate or just create instance directly using
AWS::EC2::Instance` 而不是任何模板启动。
推荐阅读
- swift - SwiftUI:线程 1:EXC_BAD_INSTRUCTION(代码=EXC_I386_INVOP,子代码=0x0)
- catel - Catel 调用 ShowDialogAsync 同步
- android - 对 onClickListeners 使用数据绑定时如何将 UI 数据传递给 ViewModel 函数?
- php - Laravel 公共文件夹显示 500 内部服务器错误
- java - 使用 Junit 进行测试时,如何停止调用 sleep() 方法的主方法?
- python - 收到错误“TypeError:'int'对象不可迭代”
- r - 如何编码:如果可以加载文件/模型,请跳过再次运行它
- c# - 如何在 Xamarin 中使用 AIDL
- memory - PyCharm(i)Python控制台:“在Python控制台中执行选择”(= Alt + Shift + E)进程的“停止当前命令”不会丢失内存中的变量?
- docker - 在 Docker 中更改 nginx 服务器名称