aws beanstalk 使用eb cli配置和启动环境
创始人
2024-03-01 10:49:36
0

Elastic Beanstalk 不额外收费,只需为存储和运行应用程序所需的 AWS 资源付费

EB CLI 是 Amazon Elastic Beanstalk 的命令行界面,它提供了可简化从本地存储库创建、更新和监控环境的交互式命令

安装eb cli

$ pip install virtualenv
$ virtualenv ebvenv
$ source venv/bin/activate
$ (ebvenv) pip install awsebcli --upgrade
$ $ eb --version
EB CLI 3.20.3 (Python 3.7.1)

帮助信息

commands:abort        Cancels an environment update or deployment.appversion   Listing and managing application versionsclone        Clones an environment.codesource   Configures the code source for the EB CLI to use by default.config       Modify an environment's configuration. Use subcommands to manage saved configurations.console      Opens the environment in the AWS Elastic Beanstalk Management Console.create       Creates a new environment.deploy       Deploys your source code to the environment.events       Gets recent events.health       Shows detailed environment health.init         Initializes your directory with the EB CLI. Creates the application.labs         Extra experimental commands.list         Lists all environments.local        Runs commands on your local machine.logs         Gets recent logs.open         Opens the application URL in a browser.platform     Commands for managing platforms.printenv     Shows the environment variables.restore      Restores a terminated environment.scale        Changes the number of running instances.setenv       Sets environment variables.ssh          Opens the SSH client to connect to an instance.status       Gets environment information and status.swap         Swaps two environment CNAMEs with each other.tags         Allows adding, deleting, updating, and listing of environment tags.terminate    Terminates the environment.upgrade      Updates the environment to the most recent platform version.use          Sets default environment.

初始化

初始化eb环境,可以指定凭证profile

$ mkdir test-beangolang && cd test-beangolang
$ eb init
$ #eb init --profile profilename

初始化使用默认的aws凭证,要求选择region,application,ssh,platform(此处选择go)等。新的application默认以当前文件夹名称创建。

初始化完成后在本地生成如下文件。其中config.yml包含配置信息

$ tree -a
.
├── .elasticbeanstalk
│   └── config.yml
└── .gitignore
$ cat .elasticbeanstalk/config.yml
branch-defaults:default:environment: nullgroup_suffix: null
global:application_name: test-beangolangbranch: nulldefault_ec2_keyname: dev-keydefault_platform: Go 1 running on 64bit Amazon Linux 2default_region: cn-north-1include_git_submodules: trueinstance_profile: nullplatform_name: nullplatform_version: nullprofile: nullrepository: nullsc: nullworkspace_type: Application

初始化之后只会创建application,不会启动environment(即实例,负载均衡器,数据库等资源)
在这里插入图片描述

高级配置

如果 .ebignore 不存在,但存在 .gitignore,EB CLI 将忽略 .gitignore 中指定的文件。如果存在 .ebignore,EB CLI 将不会读取 .gitignore

eb cli工具的凭证优先级

部署构建而非文件夹

创建环境

$ eb create

环境初始化会选择环境name,dns,lb,是否下载sample,最后启动环境,启动过程中会输出日志

最终所有资源都会通过创建cloudformation的方式进行创建

Would you like to enable Spot Fleet requests for this environment? (y/N): n
NOTE: The current directory does not contain any source code. Elastic Beanstalk is launching the sample application instead.
Do you want to download the sample application into the current directory? (Y/n): y
INFO: Downloading sample application to the current directory.
INFO: Download complete.
Environment details for: test-beangolang-devApplication name: test-beangolangRegion: cn-north-1Deployed Version: Sample ApplicationEnvironment ID: e-254v23ad2mPlatform: arn:aws-cn:elasticbeanstalk:cn-north-1::platform/Go 1 running on 64bit Amazon Linux 2/3.6.1Tier: WebServer-Standard-1.0CNAME: test-beangolang-dev.cn-north-1.eb.amazonaws.com.cnUpdated: 2022-11-13 15:35:24.287000+00:00
Printing Status:
2022-11-13 15:35:23    INFO    createEnvironment is starting.
2022-11-13 15:35:24    INFO    Using elasticbeanstalk-cn-north-1-xxxxxxxxxxxx as Amazon S3 storage bucket for environment data.
2022-11-13 15:35:46    INFO    Created target group named: arn:aws-cn:elasticloadbalancing:cn-north-1:xxxxxxxxxxxx:targetgroup/awseb-test-bea-default-5gkjd/6de4b45758a2fab6
2022-11-13 15:35:46    INFO    Created security group named: awseb-e-254v23ad2m-stack-AWSEBSecurityGroup-1X8RQFJTFG3WA
2022-11-13 15:36:03    INFO    Created Auto Scaling launch configuration named: awseb-e-254v23ad2m-stack-AWSEBAutoScalingLaunchConfiguration-vWQ0HP7XfOUA
2022-11-13 15:36:03    INFO    Created Load Balancer listener rule named: arn:aws-cn:elasticloadbalancing:cn-north-1:xxxxxxxxxxxx:listener-rule/app/main-alb/17ec2f283414a86a/80c5154ba2598551/d2ff9a73b3344c39-- Events -- (safe to Ctrl+C)

下载sample程序,一个简单的go web程序

$ tree
.
├── application.go
├── cron.yaml
└── public└── index.html

查看当前状态和健康状况

$ eb status
Environment details for: test-beangolang-devApplication name: test-beangolangRegion: cn-north-1Deployed Version: Sample ApplicationEnvironment ID: e-254v23ad2mPlatform: arn:aws-cn:elasticbeanstalk:cn-north-1::platform/Go 1 running on 64bit Amazon Linux 2/3.6.1Tier: WebServer-Standard-1.0CNAME: test-beangolang-dev.cn-north-1.eb.amazonaws.com.cnUpdated: 2022-11-13 15:37:06.756000+00:00Status: LaunchingHealth: Grey
$ eb health

查看事件输出,包括环境构建,重新部署,配置修改等事件日志,和图形控制台一致

$ eb evnets

查看控制台

在这里插入图片描述

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...