Amazon web services 如何使用CloudFormation创建具有集成RDS的AWS Elasticbeanstalk应用程序?

Amazon web services 如何使用CloudFormation创建具有集成RDS的AWS Elasticbeanstalk应用程序?,amazon-web-services,amazon-cloudformation,amazon-rds,amazon-elastic-beanstalk,Amazon Web Services,Amazon Cloudformation,Amazon Rds,Amazon Elastic Beanstalk,我正在尝试为使用Postgres的SpringBoot应用程序设置AWS环境。 我决定使用CloudFormation来配置我的应用程序所需的所有AWS组件 以下是云形成模板app.json: { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "S3BucketName": { "Description": "S3 BucketName", "Type": "String" },

我正在尝试为使用Postgres的SpringBoot应用程序设置AWS环境。 我决定使用CloudFormation来配置我的应用程序所需的所有AWS组件

以下是云形成模板app.json:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "S3BucketName": {
      "Description": "S3 BucketName",
      "Type": "String"
    },
    "S3FileName": {
      "Description": "Name of the jar/war file",
      "Type": "String"
    },
    "DBName":{
      "Default":"mytododb",
      "Description":"The database name",
      "Type":"String",
      "MinLength":"1",
      "MaxLength":"64",
      "AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*",
      "ConstraintDescription":"must begin with a letter and contain only alphanumeric characters."
    },
    "DBUser":{
      "Description":"The database admin account username",
      "Type":"String",
      "MinLength":"1",
      "MaxLength":"16",
      "AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*",
      "ConstraintDescription":"must begin with a letter and contain only alphanumeric characters."
    },
    "DBPassword":{
      "NoEcho":"true",
      "Description":"The database admin account password",
      "Type":"String",
      "MinLength":"8",
      "MaxLength":"41",
      "AllowedPattern":"[a-zA-Z0-9]*",
      "ConstraintDescription":"must contain only alphanumeric characters."
    },
    "DBAllocatedStorage":{
      "Default":"5",
      "Description":"The size of the database (Gb)",
      "Type":"Number",
      "MinValue":"5",
      "MaxValue":"1024",
      "ConstraintDescription":"must be between 5 and 1024Gb."
    },
    "DBInstanceClass":{
      "Default":"db.t2.micro",
      "Description":"The database instance type",
      "Type":"String",
      "ConstraintDescription":"must select a valid database instance type."
    },
    "MultiAZDatabase":{
      "Default":"false",
      "Description":"Create a multi-AZ RDS database instance",
      "Type":"String",
      "AllowedValues":[
        "true",
        "false"
      ],
      "ConstraintDescription":"must be either true or false."
    }
  },
  "Resources": {
    "SpringBootApplication": {
      "Type": "AWS::ElasticBeanstalk::Application",
      "Properties": {
        "Description":"Spring boot and elastic beanstalk"
      }
    },
    "SpringBootApplicationVersion": {
      "Type": "AWS::ElasticBeanstalk::ApplicationVersion",
      "Properties": {
        "ApplicationName":{"Ref":"SpringBootApplication"},
        "SourceBundle": {
          "S3Bucket": {
            "Ref": "S3BucketName"
          },
          "S3Key": {
            "Ref": "S3FileName"
          }
        }
      }
    },
    "SpringBootBeanStalkConfigurationTemplate": {
      "Type": "AWS::ElasticBeanstalk::ConfigurationTemplate",
      "Properties": {
        "ApplicationName": {"Ref":"SpringBootApplication"},
        "Description":"A display of speed boot application",
        "OptionSettings": [
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "DBAllocatedStorage",
            "Value": {
              "Ref": "DBAllocatedStorage"
            }
          },
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "DBDeletionPolicy",
            "Value": "Delete"
          },
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "DBEngine",
            "Value": "postgres"
          },
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "DBEngineVersion",
            "Value": "10.4"
          },
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "DBInstanceClass",
            "Value": { "Ref": "DBInstanceClass" }
          },
          {
            "OptionName": "DBPassword",
            "Namespace": "aws:rds:dbinstance",
            "Value": { "Ref": "DBPassword" }
          },
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "DBUser",
            "Value": { "Ref": "DBUser" }
          },
          {
            "Namespace": "aws:rds:dbinstance",
            "OptionName": "MultiAZDatabase",
            "Value": { "Ref": "MultiAZDatabase" }
          }
        ],
        "SolutionStackName": "64bit Amazon Linux 2018.03 v2.9.2 running Java 8"
      }
    },
    "SpringBootBeanstalkEnvironment": {
      "Type": "AWS::ElasticBeanstalk::Environment",
      "Properties": {
        "ApplicationName": {"Ref":"SpringBootApplication"},
        "EnvironmentName":"TodoAppEnvironment",
        "TemplateName": {"Ref":"SpringBootBeanStalkConfigurationTemplate"},
        "VersionLabel": {"Ref": "SpringBootApplicationVersion"}
      }
    }
  },
  "Outputs": {
    "DevURL": {
      "Description": "The URL of the DEV Elastic Beanstalk environment",
      "Value": {
        "Fn::Join": [
          "",
          [
            {
              "Fn::GetAtt": [
                "SpringBootBeanstalkEnvironment",
                "EndpointURL"
              ]
            }
          ]
        ]
      },
      "Export": {
        "Name": {
          "Fn::Sub": "${AWS::StackName}-EndpointURL"
        }
      }
    }
  }
}

参数文件parameters.json是:

[
  {
    "ParameterKey": "DBUser",
    "ParameterValue": "myuser"
  },
  {
    "ParameterKey": "DBPassword",
    "ParameterValue": "secret"
  },
  {
    "ParameterKey": "S3BucketName",
    "ParameterValue": "todoapp"
  },
  {
    "ParameterKey": "S3FileName",
    "ParameterValue": "todo-api-spring-boot-0.0.1.jar"
  }
]

我正在使用 aws cloudformation创建堆栈--模板体file://app.json --参数file://parameters.json --堆栈名称=todo堆栈

问题: 堆栈正在创建,但是数据库(RDS)实例没有创建,当我在管理控制台中看到应用程序的ElasticBeanstalk配置时,没有与应用程序关联的数据库配置

我的期望/假设是,通过在选项设置中配置各种aws:rds:dbinstance属性,将配置一个rds实例,并将其与ElasticBeanstalk应用程序关联

我的理解是错误的还是遗漏了其他设置

附言: 其想法是使用集成的RDS,以便我可以在应用程序中使用RDS_主机、RDS_端口等属性连接到数据库

我可以配置单独的RDS资源并通过指定连接参数连接到它。但是我希望选项设置中的aws:rds:dbinstance属性将创建rds并将其与Elasticbeanstalk应用程序关联。如果不是这样,那么在选项设置中配置这些参数的目的是什么

参考:


由于名称空间方法,RDS创建未完成。基本上,名称空间用于覆盖您创建的资源的默认属性

因此,解决方案是在“SpringBootBeanStalkConfigurationTemplate”之前包含RDS创建模板


在此之后,您可以将RDS参数包括在其他资源中,因为它将首先创建。

由于名称空间方法的原因,无法创建RDS。基本上,名称空间用于覆盖您创建的资源的默认属性

因此,解决方案是在“SpringBootBeanStalkConfigurationTemplate”之前包含RDS创建模板


在此之后,您可以将RDS参数包括在其他资源中,因为它将首先创建。

感谢您的回复。我还不清楚在选项设置中配置“aws:rds:dbinstance”参数的目的是什么?谢谢回复。我仍然不清楚在选项设置中配置“aws:rds:dbinstance”参数的目的是什么?
  "Resources": {
    "RDS Creation": {
      {
      "Type" : "AWS::RDS::DBInstance",
      "Properties" : {
          "AllocatedStorage" : String,
          "AllowMajorVersionUpgrade" : Boolean,
          "AssociatedRoles" : [ DBInstanceRole, ... ],
          "AutoMinorVersionUpgrade" : Boolean,
          "AvailabilityZone" : String,
          "BackupRetentionPeriod" : Integer,
          "CharacterSetName" : String,
          "CopyTagsToSnapshot" : Boolean,
          "DBClusterIdentifier" : String,
          "DBInstanceClass" : String,
          "DBInstanceIdentifier" : String,
          "DBName" : String,
          "DBParameterGroupName" : String,
          "DBSecurityGroups" : [ String, ... ],
          "DBSnapshotIdentifier" : String,
          "DBSubnetGroupName" : String,
          "DeleteAutomatedBackups" : Boolean,
          "DeletionProtection" : Boolean,
          "Domain" : String,
          "DomainIAMRoleName" : String,
          "EnableCloudwatchLogsExports" : [ String, ... ],
          "EnableIAMDatabaseAuthentication" : Boolean,
          "EnablePerformanceInsights" : Boolean,
          "Engine" : String,
          "EngineVersion" : String,
          "Iops" : Integer,
          "KmsKeyId" : String,
          "LicenseModel" : String,
          "MasterUsername" : String,
          "MasterUserPassword" : String,
          "MonitoringInterval" : Integer,
          "MonitoringRoleArn" : String,
          "MultiAZ" : Boolean,
          "OptionGroupName" : String,
          "PerformanceInsightsKMSKeyId" : String,
          "PerformanceInsightsRetentionPeriod" : Integer,
          "Port" : String,
          "PreferredBackupWindow" : String,
          "PreferredMaintenanceWindow" : String,
          "ProcessorFeatures" : [ ProcessorFeature, ... ],
          "PromotionTier" : Integer,
          "PubliclyAccessible" : Boolean,
          "SourceDBInstanceIdentifier" : String,
          "SourceRegion" : String,
          "StorageEncrypted" : Boolean,
          "StorageType" : String,
          "Tags" : [ Tag, ... ],
          "Timezone" : String,
          "UseDefaultProcessorFeatures" : Boolean,
          "VPCSecurityGroups" : [ String, ... ]
        }
    }
  }
}