我不是 JSON 专家,但我能够操纵 AWS Beanstalk VPC cloudformation 模板从 S3 中提取 .WAR 文件并部署为新应用程序。我还操纵脚本为公共(public)创建了 2 个额外的子网,另一个为私有(private)子网,而不是仅创建 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"
  }
}

},

任何帮助将不胜感激..

最佳答案

在我试图找到同一问题的答案时遇到了这个问题

OptionName 值需要是一个逗号分隔的字符串,例如“a,b”

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

与 RDSSubnetGroup 中的 SubnetID 不同,您可以在其中列出子网 ID,例如“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"} ] ] }
},

关于amazon-web-services - 在 Cloudformation Beanstalk 脚本中将子网添加到 ELB 和子网值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22699277/

10-11 08:48