我有一个Beanstalk应用程序,默认情况下有一个app_name.elasticbeanstalk.com域名。
我想要一个像www.app_name.com这样的域名,可以通过bowser访问,并采取以下步骤。
www.app_name.com
设置为ELB公共DNS的CNAME。通过这种方式,我可以通过浏览器访问www.app_name.com。 但是,一旦加载浏览器,URL就会突然变为app_name.elasticbeanstalk.com
我不想向任何人展示app_name.elasticbeanstalk.com
。我可以使用www.app_name.com吗?怎么样?
请帮帮我。
答案 0 :(得分:5)
您可以使用Route53和CloudFormation来完成此操作。为此,您可以使用CloudFormation模板中的Elastic Beanstalk资源来创建Elastic Beanstalk堆栈。您还可以使用Route53资源来创建所需的域名。然后在Route53资源中创建一个映射到Elastic Beanstalk端点的别名。
这可能类似于:
"Resources" : {
"DNS" : {
"Type" : "AWS::Route53::RecordSetGroup",
"Properties" : {
"HostedZoneName" : "example.com",
"Comment" : "CNAME alias targeted to Elastic Beanstalk endpoint.",
"RecordSets" : [
{
"Name" : "example.example.com",
"Type" : "CNAME",
"TTL" : "900",
"ResourceRecords" : [{ "Fn::GetAtt" : ["sampleEnvironment","EndpointURL"] }]
}]
}
},
"sampleApplication" : {
"Type" : "AWS::ElasticBeanstalk::Application",
"Properties" : {
"Description" : "AWS Elastic Beanstalk Ruby Sample Application",
"ApplicationVersions" : [{
"VersionLabel" : "Initial Version",
"Description" : "Version 1.0",
"SourceBundle" : {
"S3Bucket" : { "Fn::Join" : ["-", ["elasticbeanstalk-samples", { "Ref" : "AWS::Region" }]]},
"S3Key" : "ruby-sample.zip"
}
}],
"ConfigurationTemplates" : [{
"TemplateName" : "DefaultConfiguration",
"Description" : "Default Configuration Version 1.0 - with SSH access",
"SolutionStackName" : "64bit Amazon Linux running Ruby 1.9.3",
"OptionSettings" : [{
"Namespace" : "aws:autoscaling:launchconfiguration",
"OptionName" : "EC2KeyName",
"Value" : { "Ref" : "KeyName" }
}]
}]
}
},
"sampleEnvironment" : {
"Type" : "AWS::ElasticBeanstalk::Environment",
"Properties" : {
"ApplicationName" : { "Ref" : "sampleApplication" },
"Description" : "AWS Elastic Beanstalk Environment running Ruby Sample Application",
"TemplateName" : "DefaultConfiguration",
"VersionLabel" : "Initial Version"
}
}
},
可以找到有关使用CloudFormation资源的更多信息here,可以找到示例模板here
CloudFormation可以动态地与资源进行交互,非常简单和干净......更不用说完全编写脚本了:)