在Cloudformation Beanstalk脚本中将子网添加到ELB和子网值

时间:2014-03-27 21:11:20

标签: amazon-web-services elastic-beanstalk amazon-cloudformation

我不是JSON专家,但我能够操纵AWS Beanstalk VPC云形态模板从S3中提取.WAR文件并作为新应用程序部署。我还操纵脚本为公共创建另外2个子网1,为私有创建另外2个子网,而不是仅创建2个子网的原始脚本。我遇到了下面这段代码的问题。我需要操作,以便EC2实例和ELB使用我在脚本中创建的其他子网。因此,对于值子网,我需要添加 PrivateSubnet PrivateSubnet2 即可。 ELBs 值也是如此。

"SampleEnvironment" : {
  "Type" : "AWS::ElasticBeanstalk::Environment",
  "Properties" : {
    "ApplicationName" : { "Ref" : "SampleApplication" },
    "EnvironmentName" : "Sandbox",
     "Description" :  "AWS Elastic Beanstalk Environment running Python Sample Application",
     "SolutionStackName" : "64bit Amazon Linux 2014.02 running Tomcat 7 Java 7",
     "OptionSettings" : [
       {"Namespace" : "aws:autoscaling:launchconfiguration", "OptionName" : "SSHSourceRestriction", "Value" : { "Fn::Join" : [ "", ["tcp,22,22,", { "Ref" : "BastionSecurityGroup" }]]}},
       {"Namespace" : "aws:autoscaling:launchconfiguration", "OptionName" : "SecurityGroups", "Value" : { "Ref" : "BeanstalkSecurityGroup" }},
       {"Namespace" : "aws:autoscaling:launchconfiguration", "OptionName" : "EC2KeyName", "Value" : { "Ref" : "InstanceKeyName" }},
       {"Namespace" : "aws:ec2:vpc", "OptionName" : "VPCId", "Value" : { "Ref" : "VPC" }},
       {"Namespace" : "aws:ec2:vpc", "OptionName" : "Subnets", "Value" : { "Ref" : "PrivateSubnet" }},
       {"Namespace" : "aws:ec2:vpc", "OptionName" : "ELBSubnets", "Value" : { "Ref" : "PublicSubnet" }}],
     "VersionLabel" : "Initial Version"
  }
}

},

任何帮助将不胜感激..

1 个答案:

答案 0 :(得分:5)

当我试图找到同一个问题的答案时,跑过这个

OptionName Value必须是一个以逗号分隔的字符串,例如" a,b"

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk-option-settings.html

与RDSSubnetGroup中的SubnetID不同,您可以在其中列出子元素,例如" a"," b"

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbsubnet-group.html

我使用内部连接函数将我模板中的一些引用加入到一个字符串中。

{
  "Namespace" : "aws:ec2:vpc", 
  "OptionName" : "Subnets", 
  "Value" : { "Fn::Join" : [ ",", [ { "Ref": "PrivateSubnetAvailabiltyZoneA" }, {"Ref": "PrivateSubnetAvailabiltyZoneB"} ] ] } 
},
{
  "Namespace" : "aws:ec2:vpc", 
  "OptionName" : "ELBSubnets", 
  "Value" : { "Fn::Join" : [ ",", [ { "Ref": "PublicSubnetAvailabiltyZoneA" }, {"Ref": "PublicSubnetAvailabiltyZoneB"} ] ] } 
},