AWS CLI 使用 elasticbeanstalk 创建环境创建 RDS [英] AWS CLI create RDS with elasticbeanstalk create-environment

查看:29
本文介绍了AWS CLI 使用 elasticbeanstalk 创建环境创建 RDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 create-environmentaws elasticbeanstalk 的其他子命令创建 RDS 实例?我尝试了几种参数组合都无济于事.下面是一个例子.

APP_NAME="randall-railsapp"aws s3api create-bucket --bucket "$APP_NAME"APP_VERSION="$(git describe --always)"APP_FILE="部署-$APP_NAME-$APP_VERSION.zip"git archive -o "$APP_FILE" HEADaws s3 cp "$APP_FILE" "s3://$APP_NAME/$APP_FILE"aws --region us-east-1 elasticbeanstalk 创建应用程序版本 --auto-create-application --application-name "$APP_NAME" --version-label "$APP_VERSION" --source-bundle S3Bucket="$APP_NAME",S3Key="$APP_FILE"aws --region us-east-1 elasticbeanstalk 创建环境 --application-name "$APP_NAME" --version-label "$APP_VERSION" --environment-name "$APP_NAME-env" --description "randall 的 rails 应用程序环境" --solution-stack-name "64 位 Amazon Linux 2014.03 v1.0.0 运行 Ruby 2.1 (Puma)" --cname-prefix "$APP_NAME-test" --option-settings file://test.json

以及test.json的内容:

<预><代码>[{"OptionName": "EC2KeyName","命名空间": "aws:autoscaling:launchconfiguration",价值":钥匙在这里"},{"OptionName": "环境类型","命名空间": "aws:elasticbeanstalk:environment",值":单个实例"},{"OptionName": "SECRET_KEY_BASE","命名空间": "aws:elasticbeanstalk:application:environment",价值":哈哈哈哈哈哈哈"},{"OptionName": "DBPassword","命名空间": "aws:rds:dbinstance",值":猎人2"},{"OptionName": "DBUser","命名空间": "aws:rds:dbinstance",值":随机"},{"OptionName": "DBEngineVersion","命名空间": "aws:rds:dbinstance",值":9.3"},{"OptionName": "DBEngine","命名空间": "aws:rds:dbinstance",值":postgres"}]

有人知道为什么会失败吗?我使用 aws:rds:dbinstance 命名空间指定的任何内容似乎都会从配置中删除.

解决方案

仅设置 aws:rds:dbinstance 选项不会创建 RDS 数据库.目前,您可以使用以下技术之一创建 RDS 实例:

  1. 使用 AWS 控制台创建
  2. 使用 eb cli
  3. 使用ebextensions的资源部分创建RDS资源

前两种方法最方便,因为它们可以为您完成所有繁重的工作,但对于第三种方法,您必须做一些额外的工作.第三种方法是您在不使用控制台或 eb CLI 时想要使用的方法.

您可以使用以下 ebextension 代码段为 beanstalk 环境创建 RDS 资源.在应用源的 .ebextensions 目录中创建一个名为 01-rds.config 的文件.

资源:AWSEBRDS数据库:类型:AWS::RDS::DBInstance特性:分配的存储空间:5数据库实例类:db.t2.micro数据库名称:myawesomeapp引擎:postgres引擎版本:9.3主用户名:myAwesomeUsername主用户密码:myCrazyPassword

此文件采用 YAML 格式,因此缩进很重要.如果您愿意,也可以使用 JSON.这些不是选项设置,因此您不能将其作为 --option-settings test.json 传递.您只需将此文件与您的应用程序源捆绑在一起即可.

详细了解您可以在 RDS 数据库上配置哪些属性 这里.在此页面上,您还可以找到哪些属性是必需的,哪些属性是可选的.

如果上述方法对您不起作用或您有任何其他问题,请告诉我.

How can I create an RDS instance with the create-environment or another subcommand of aws elasticbeanstalk? I've tried several combinations of parameters to no avail. Below is an example.

APP_NAME="randall-railsapp"
aws s3api create-bucket --bucket "$APP_NAME"
APP_VERSION="$(git describe --always)"
APP_FILE="deploy-$APP_NAME-$APP_VERSION.zip"
git archive -o "$APP_FILE" HEAD
aws s3 cp "$APP_FILE" "s3://$APP_NAME/$APP_FILE"

aws --region us-east-1 elasticbeanstalk create-application-version 
--auto-create-application 
--application-name "$APP_NAME" 
--version-label "$APP_VERSION" 
--source-bundle S3Bucket="$APP_NAME",S3Key="$APP_FILE"

aws --region us-east-1 elasticbeanstalk create-environment 
--application-name "$APP_NAME" 
--version-label "$APP_VERSION" 
--environment-name "$APP_NAME-env" 
--description "randall's rails app environment" 
--solution-stack-name "64bit Amazon Linux 2014.03 v1.0.0 running Ruby 2.1 (Puma)" 
--cname-prefix "$APP_NAME-test" 
--option-settings file://test.json

And the contents of test.json:

[
{
    "OptionName": "EC2KeyName",
    "Namespace": "aws:autoscaling:launchconfiguration",
    "Value": "a-key-is-here"
},
{
    "OptionName": "EnvironmentType",
    "Namespace": "aws:elasticbeanstalk:environment",
    "Value": "SingleInstance"
},
{
    "OptionName": "SECRET_KEY_BASE",
    "Namespace": "aws:elasticbeanstalk:application:environment",
    "Value": "HAHAHAHAHAHA"
},
{
    "OptionName": "DBPassword",
    "Namespace": "aws:rds:dbinstance",
    "Value": "hunter2"
},
{
    "OptionName": "DBUser",
    "Namespace": "aws:rds:dbinstance",
    "Value": "random"
},
{
    "OptionName": "DBEngineVersion",
    "Namespace": "aws:rds:dbinstance",
    "Value": "9.3"
},
{
    "OptionName": "DBEngine",
    "Namespace": "aws:rds:dbinstance",
    "Value": "postgres"
}
]

Anyone know why this is failing? Anything I specify with a aws:rds:dbinstance namespace seems to get removed from the configuration.

解决方案

Just setting the aws:rds:dbinstance options does not create an RDS database. Currently you can create an RDS instance using one of the following techniques:

  1. Create using AWS Console
  2. Use eb cli
  3. Use Resources section of ebextensions to create an RDS resource

The first two approaches are the most convenient as they do all the heavy lifting for you but for the third one you have to do some extra work. The third approach is what you would want to use if you are not using the console or eb CLI.

You can create an RDS resource for your beanstalk environment using the following ebextension snippet. Create a file called 01-rds.config in the .ebextensions directory of your app source.

Resources:
    AWSEBRDSDatabase:
        Type: AWS::RDS::DBInstance
        Properties:
            AllocatedStorage: 5
            DBInstanceClass: db.t2.micro
            DBName: myawesomeapp
            Engine: postgres
            EngineVersion: 9.3
            MasterUsername: myAwesomeUsername
            MasterUserPassword: myCrazyPassword

This file is in YAML format so indentation is important. You could also use JSON if you like. These are not option settings so you cannot pass it as --option-settings test.json. You just need to bundle this file with your app source.

Read more about what properties you can configure on your RDS database here. On this page you can also find what properties are required and what properties are optional.

Let me know if the above does not work for you or if you have any further questions.

这篇关于AWS CLI 使用 elasticbeanstalk 创建环境创建 RDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆