Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS&x2B;云形成&x2B;弹性豆茎_Amazon Web Services_Java 8_Amazon Elastic Beanstalk_Amazon Cloudformation_Tomcat8 - Fatal编程技术网

Amazon web services AWS&x2B;云形成&x2B;弹性豆茎

Amazon web services AWS&x2B;云形成&x2B;弹性豆茎,amazon-web-services,java-8,amazon-elastic-beanstalk,amazon-cloudformation,tomcat8,Amazon Web Services,Java 8,Amazon Elastic Beanstalk,Amazon Cloudformation,Tomcat8,当我使用输入参数EnvironmentType“dev”使用以下cloudformation模板创建堆栈时,它会创建ebs应用程序,在应用程序内创建环境,并从S3 bucket部署sample-app.war文件 然后,我使用同一个模板和一个输入参数EnvironmentType“stage”执行更新堆栈,这次它删除了现有的dev环境,并在应用程序内创建了stage环境 我还尝试使用示例模板再次创建堆栈,输入在第一步中创建的示例应用程序名称,这次它显示应用程序已经存在 我的要求是保留dev环境和

当我使用输入参数EnvironmentType“dev”使用以下cloudformation模板创建堆栈时,它会创建ebs应用程序,在应用程序内创建环境,并从S3 bucket部署sample-app.war文件

然后,我使用同一个模板和一个输入参数EnvironmentType“stage”执行更新堆栈,这次它删除了现有的dev环境,并在应用程序内创建了stage环境

我还尝试使用示例模板再次创建堆栈,输入在第一步中创建的示例应用程序名称,这次它显示应用程序已经存在

我的要求是保留dev环境和stage环境,以便使用cloudformation在示例应用程序中创建

有什么建议吗

---
AWSTemplateFormatVersion: 2010-09-09

Description: 'Create an ElasticBeanstalk Application, Environment and deploy the war file from S3 bucket'

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      -
        Label:
          default: 'EBS Application Configuration'
        Parameters:
          - ApplicationName
          - ApplicationDescription
          - ApplicationVersion
      -
        Label:
          default: 'EBS Environment Configuration'
        Parameters:
          - EnvironmentName
          - EnvironmentType
          - EnvironmentDescription
          - EnvironmentCName
          - MinInstances
          - MaxInstances

Mappings:
  PropertiesMap:
    IntanceType:
      dev: 'SingleInstance'
      qa: 'SingleInstance'
      stage: 'LoadBalanced'
      prod: 'LoadBalanced'

Parameters:
  ApplicationName:
    Type: String
    Description: 'Name of the ElasticBeanstalk Application'

  ApplicationDescription:
    Type: String
    Description: 'ElasticBeanstalk Application Description'

  ApplicationVersion:
    Type: String
    Description: 'Application version description'

  EnvironmentName:
    Type: String
    Description: 'Name of the Environment'
    AllowedPattern: '^([A-Za-z]|[0-9]|-)+$'

  EnvironmentType:
    Type: String
    Description: 'Type of the Environment (dev, qa, stage, prod)'
    AllowedValues:
      - 'dev'
      - 'qa'
      - 'stage'
      - 'prod'

  EnvironmentCName:
    Type: String
    Description: 'CName Prefix for the ElasticBeanstalk environment'
    AllowedPattern: '^([A-Za-z]|[0-9]|-)+$'

  EnvironmentDescription:
    Type: String
    Description: 'Description of the ElasticBeanstalk environment'

  MinInstances:
    Type: Number
    Description: 'Minimum load balanced instances (Mandatory for stage/prod)'
    Default: 2
    MinValue: 2
    MaxValue: 10

  MaxInstances:
    Type: Number
    Description: 'Maximum load balanced instances (Mandatory for stage/prod)'
    Default: 2
    MinValue: 2
    MaxValue: 10

Conditions:
  IsStageOrProdEnvironment:
    !Or [!Equals [stage, !Ref EnvironmentType], !Equals [prod, !Ref EnvironmentType]]

Resources:
  EBSApplication:
    Type: AWS::ElasticBeanstalk::Application
    Properties:
      ApplicationName: !Ref ApplicationName
      Description: !Ref ApplicationDescription

  EBSApplicationVersion:
    Type: AWS::ElasticBeanstalk::ApplicationVersion  
    Properties:
      ApplicationName: !Ref EBSApplication
      Description: !Ref ApplicationVersion

      SourceBundle:
        S3Bucket: deployable
        S3Key: artifacts/sample-app.war

  EBSApplicationConfigurationTemplate:
    Type: AWS::ElasticBeanstalk::ConfigurationTemplate
    Properties:
      ApplicationName: !Ref EBSApplication
      Description: 'ElasticBeanstalk Configuration Template'
      SolutionStackName: '64bit Amazon Linux 2018.03 v3.0.2 running Tomcat 8.5 Java 8'
      OptionSettings:
        - Namespace: aws:elasticbeanstalk:environment
          OptionName: EnvironmentType
          Value: !FindInMap [PropertiesMap, IntanceType, !Ref EnvironmentType]
        - Namespace: aws:autoscaling:asg
          OptionName: MinSize
          Value: !If [IsStageOrProdEnvironment, !Ref MinInstances, !Ref 'AWS::NoValue']
        - Namespace: aws:autoscaling:asg
          OptionName: MaxSize
          Value: !If [IsStageOrProdEnvironment, !Ref MaxInstances, !Ref 'AWS::NoValue']

  EBSEnvironment:
    Type: AWS::ElasticBeanstalk::Environment
    Properties:
      ApplicationName: !Ref EBSApplication
      CNAMEPrefix: !Ref EnvironmentCName
      Description: !Ref EnvironmentDescription
      EnvironmentName: !Ref EnvironmentName
      TemplateName: !Ref EBSApplicationConfigurationTemplate
      VersionLabel: !Ref EBSApplicationVersion

Outputs:
  ApplicationURL:
    Description: 'ElasticBeanstalk environment endpoint'
    Value: !Join 
      - ''
      - - 'http://'
        - !GetAtt EBSEnvironment.EndpointURL

您是否使用aws cli进行部署?您可以显示命令行吗?不,我使用aws控制台运行此模板,并在控制台中传递输入参数。您是否检查了“dev”和“prod”堆栈是否具有不同的名称?是的,我尝试创建了两个具有不同名称的“dev”和“prod”堆栈。由于应用程序已经为开发环境创建,它显示应用程序已经存在并回滚堆栈创建。我还尝试更新堆栈my project dev,这次它创建了暂存环境并删除了开发环境。