[英]Can we add a CNAME for an EC2 in Cloud Formation Template when ec2s are created using auto scaling?
I am working with a kafka cluster on AWS, I would like to give each broker a CNAME so I can reference that rather than the IP address. 我正在AWS上使用kafka集群,我想给每个代理一个CNAME,这样我就可以引用它而不是IP地址。
I know usually with an EC2 we can do this in the cloud formation template using something like this.. 我知道通常使用EC2我们可以使用类似的东西在云形成模板中执行此操作。
{
"Parameters": {
"TestCname":{
"Description": "The IpAddress for the MyInstance Ec2",
"Type": "String",
"Default": "domainName.com"
}
},
"Resources": {
"MyInstanceCNAME": {
"Type": "Custom::ResourceDNS",
"Version": "1.0",
"Properties": {
"ServiceToken": { "Fn::Sub": "arn:aws:sns:${AWS::Region}:<Account_Num>:custom-resource" },
"Resource": "CNAME",
"CNAME": { "Ref": "TestCname" },
"IpAddress" : { "Fn::GetAtt" : [ "MyInstance", "PrivateIp" ]}
}
},
"MyInstance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": "us-east-1a",
"ImageId": "ami-a4c7edb2",
"InstanceType": "t2.micro"}
}
}
The problem is that with confluent quickstart script for AWS 问题是AWS的汇总快速入门脚本
https://github.com/aws-quickstart/quickstart-confluent-kafka/blob/master/templates/confluent-kafka.template https://github.com/aws-quickstart/quickstart-confluent-kafka/blob/master/templates/confluent-kafka.template
I initially thought the creation of the ec2s must be in the referenced templates eg. 我最初认为ec2s的创建必须在引用的模板中,例如。
Fn::Sub": "https://${QSS3BucketName}.s3.amazonaws.com/${QSS3KeyPrefix}templates/nodegroup.template
But I couldn't see the instantation in that template either and have just discovered through a guy on my team that the ec2s are being created through auto scaling. 但我无法看到该模板中的瞬间,并且刚刚通过我团队中的一个人发现ec2是通过自动缩放创建的。
Can we add a CNAME and how is the question? 我们可以添加CNAME吗?问题是什么? Thanks
谢谢
EC2 Autoscaling helps you setup scaling for your EC2 quickly. EC2 Autoscaling可帮助您快速设置EC2的缩放比例。 The EC2s controlled by this can be terminated or started depending on demand or schedules.
由此控制的EC2可以根据需求或时间表终止或启动。 Because of this, it does not make sense to reference to any particular EC2.
因此,参考任何特定的EC2都没有意义。
I would like to suggest two alternatives: 我想建议两种选择:
Here is a small cloudformation snippet of how I assign a custom domain name to my ELB: 这是一个关于如何为ELB分配自定义域名的小型cloudformation摘录:
Resources:
MyAppEnvironment:
Type: AWS::ElasticBeanstalk::Environment
Properties:
# this one also becomes a part of the domain name
EnvironmentName: !Join ['', [!Ref MyApp, '-env']]
ApplicationName: !Ref MyApp
TemplateName: !Ref ConfigurationTemplate
VersionLabel: !Ref ApplicationVersion
DNS:
Type: AWS::Route53::RecordSetGroup
DependsOn: MyAppEnvironment
Properties:
HostedZoneName: your.hosted.zone
RecordSets:
- Name: !Join ['.', [!Ref appName, !Ref domain]]
Type: CNAME
TTL: 900
ResourceRecords: [!GetAtt [MyAppEnvironment, EndpointURL]]
Other elastic beanstalk snippets can be found here . 其他弹性豆茎片段可以在这里找到。
Because the instances are being created with an ASG they're unavailable as CloudFormation resources. 由于实例是使用ASG创建的,因此它们不可用作CloudFormation资源。
To overcome this you could: 要克服这个问题,您可以:
Custom::ResourceDNS
, you could again retrieve the instance IP addresses and then pass them in to your CloudFormation stack as another parameter. Custom::ResourceDNS
,您可以再次检索实例IP地址,然后将它们作为另一个参数传递到您的CloudFormation堆栈。 Not sure how many brokers you need to spin up (I am not kafka-knowledgeable), but if it is a small set of brokers.....you can block a set of ENIs and attach them using the user-data script based on a pool of available ENIs. 不确定你需要多少经纪人(我不是kafka知识渊博),但如果它是一小部分经纪人......你可以阻止一组ENI并使用基于用户数据的脚本附加它们在可用的ENI池上。 You can define a CNAME for the ENIs.
您可以为ENI定义CNAME。 Only limitation or risk is that you cannot enable the 'Delete on Termination' flag...else your ENI gets deleted too.
唯一的限制或风险是您无法启用“终止时删除”标记...否则您的ENI也会被删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.