AWS CLI 使用 elasticbeanstalk 创建环境创建 RDS [英] AWS CLI create RDS with elasticbeanstalk create-environment
问题描述
如何使用 create-environment
或 aws 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
的内容:
有人知道为什么会失败吗?我使用 aws:rds:dbinstance
命名空间指定的任何内容似乎都会从配置中删除.
仅设置 aws:rds:dbinstance 选项不会创建 RDS 数据库.目前,您可以使用以下技术之一创建 RDS 实例:
- 使用 AWS 控制台创建
- 使用 eb cli
- 使用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:
- Create using AWS Console
- Use eb cli
- 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屋!