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的配置,指定默认编辑器为vim

export EDITOR="vim"
eb config

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

$ eb evnets

查看控制台


无论是在控制台还是通过ebcli工具创建环境,最终都会使用cloudformation创建资源,清单如下

  • 目标组
  • 安全组
  • 启动模板或启动配置
  • 2个cloudwatch告警
  • 2个asg扩展策略
  • 自动扩展组asg

查看下启动模板(nodejs)的userdata部分如下

可以看到对于每种支持的language,都有对应的bootstrap脚本,通过向启动脚本传参实现环境的初始化

Content-Type: multipart/mixed; boundary="===============5189065377222898407=="
MIME-Version: 1.0--===============5189065377222898407==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"#cloud-config
repo_upgrade: none
repo_releasever: 2.0
cloud_final_modules:- [scripts-user, always]--===============5189065377222898407==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="user-data.txt"#!/bin/bash
exec > >(tee -a /var/log/eb-cfn-init.log|logger -t [eb-cfn-init] -s 2>/dev/console) 2>&1
echo [`date -u +"%Y-%m-%dT%H:%M:%SZ"`] Started EB User Data
set -xfunction sleep_delay
{if (( $SLEEP_TIME < $SLEEP_TIME_MAX )); then echo Sleeping $SLEEP_TIMEsleep $SLEEP_TIME  SLEEP_TIME=$(($SLEEP_TIME * 2)) else echo Sleeping $SLEEP_TIME_MAX  sleep $SLEEP_TIME_MAX  fi
}# Executing bootstrap script
SLEEP_TIME=2
SLEEP_TIME_MAX=3600
while true; do curl https://elasticbeanstalk-platform-assets-public-beta-cn-north-1.s3.cn-north-1.amazonaws.com.cn/stalks/eb_nodejs16_amazon_linux_2_1.0.1696.0_20220929200609/lib/UserDataScript.sh > /tmp/ebbootstrap.sh RESULT=$?if [[ "$RESULT" -ne 0 ]]; then sleep_delay else/bin/bash /tmp/ebbootstrap.sh     'https://cloudformation-waitcondition-cn-north-1.s3.cn-north-1.amazonaws.com.cn/arn%3Aaws-cn%3Acloudformation%3Acn-north-1%3A037047667284%3Astack/awseb-e-tuypgrwuf3-stack/cd3970d0-47e5-11ed-b386-066b31cc2db4/AWSEBInstanceLaunchWaitHandle?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20221009T151948Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86399&X-Amz-Credential=AKIAOMTUJJXMXKXJZEPQ%2F20221009%2Fcn-north-1%2Fs3%2Faws4_request&X-Amz-Signature=6a920d4ee295c755dc47d599cfcb7e87a3885b72f0e3429bdee6a5ed8ab75764'    'arn:aws-cn:cloudformation:cn-north-1:037047667284:stack/awseb-e-tuypgrwuf3-stack/cd3970d0-47e5-11ed-b386-066b31cc2db4'    '52ec14ac-5685-404a-b42e-3b5e92239559'    'https://elasticbeanstalk-health.cn-north-1.amazonaws.com.cn'    ''    'https://elasticbeanstalk-platform-assets-public-beta-cn-north-1.s3.cn-north-1.amazonaws.com.cn/stalks/eb_nodejs16_amazon_linux_2_1.0.1696.0_20220929200609'    'cn-north-1'RESULT=$?if [[ "$RESULT" -ne 0 ]]; then sleep_delay else exit 0  fi fi
done--===============5189065377222898407==--

默认创建的2个告警

对应的event rule

{"source": ["aws.cloudwatch"],"detail-type": ["CloudWatch Alarm State Change"],"resources": ["arn:aws-cn:cloudwatch:cn-north-1:xxxxxxx:alarm:awseb-e-tuypgrwuf3-stack-AWSEBCloudwatchAlarmHigh-xxxxxxxx"]
}

默认创建的两个扩展策略

将asg扩展策略和cw告警联系,当网络请求大于6M/s,就会触发asg扩容1个实例

通过webbench测试加压,eb实例扩容成功

webbench -c 300 -t 60  http://xxxxxxx-xxxxxxxx.cn-north-1.elb.amazonaws.com.cn:xxxxx/

aws beanstalk 使用eb cli配置和启动环境相关推荐

  1. aws beanstalk mysql_将数据库添加到 Elastic Beanstalk 环境 - AWS Elastic Beanstalk

    将数据库添加到 Elastic Beanstalk 环境 Elastic Beanstalk 提供了与 Amazon Relational Database Service (Amazon RDS) ...

  2. aws beanstalk mysql_DevOps on AWS之Elastic BeanStalk

    Elastic BeanStalk相关概念 童话世界中存在着一种魔力beanstalk(豆荚),种在花盆里可以无限的向上生长,越长越高直达云端.AWS Elastic Beanstalk也采用类似概念 ...

  3. 【Linux环境部署】最新版 elasticsearch + kibana(7.15.0)安装、配置、启动(多个问题处理 + kibana仪表盘使用)

    本文的安装文件是 2021.09.23 最新发布的[elasticsearch-7.15.0-linux-x86_64.tar.gz]和[kibana-7.15.0-linux-x86_64.tar. ...

  4. linux构建基于mac的vlan,通过CLI配置交换机的基于MAC的VLAN组

    通过CLI配置交换机的基于MAC的VLAN组 Introduction 虚拟局域网逻辑上允许您对网段A区域网(LAN)到不同的广播域.在敏感数据可能是在网络的广播的方案中, VLAN可以通过选定广播创 ...

  5. aws beanstalk mysql_AWS Beanstalk搭建WordPress站点

    一般搭建一个Web服务器和数据库分离的Wordpress环境需要3-4小时,而使用AWS Elastic Beanstalk搭建Wordpress环境(EC2 + RDS)不需1个小时,竟是如此简单. ...

  6. CiscoAIR-AP1832I-H-K9最全刷机步骤和WEB页面及控制器模式CLI配置。

    CiscoAP-1832I-H-K9刷机和web页面基本配置 实验准备: 一. 准备工具:console线.网线.文件传输工具<TFTPD64>.SecureCRT软件.IOS文件. 二. ...

  7. Vue CLI配置与安装

    文章目录 一.关于Vue CLI 安装Node.js 安装Vue CLI 创建Vue CLI项目 启动项目 停止服务 重启服务 二. Vue CLI项目结构 关于.vue视图文件 关于路由配置 关于r ...

  8. redis配置开机启动

    2019独角兽企业重金招聘Python工程师标准>>> 一.下载安装 去http://download.redis.io/releases/现在最新的redis版本 解压 tar z ...

  9. Ubuntu16.04桌面系统如何配置和启动wireshark

    上一篇介绍了在Ubuntu系统中安装wireshark 本篇介绍在Ubuntu系统中配置和启动wireshark: 安装好后,直接在终端运行$ wireshark.出于安全方面的考虑,普通用户不能够打 ...

最新文章

  1. ThinkPHP的标签制作
  2. IIS7 Request format is unrecognized.
  3. Ubuntu 10.10(64位)编译Android 2.3
  4. 看了这篇C++笔记,你出去行走江湖我就放心了【C++】
  5. 深拷贝的缺点_JavaScript 深拷贝
  6. 暑期训练日志----2018.8.22
  7. 需要用sq语句 修改大批量用户的密码_网站文章seo优化及修改已收录文章建议
  8. 微课|玩转Python轻松过二级(2.1.4节):列表、元组、字典、集合概述
  9. spring3-mvc实例-信息转换
  10. win7下用docker部署的基于openvino的yolov5算法(一)docker与win文件夹共享
  11. Qt之QMessageBox详解
  12. 【暴力枚举】LeetCode 78. Subsets
  13. 每周百万封业务邮件的服务器不知道为啥就down掉了?
  14. 《UNIX网络编程 卷1:套接字联网API》学习笔记——基本UDP套接字编程
  15. 计量经济学(十)---模型选择:标准与检验
  16. react native 获取验证码
  17. 什么是智能家电?消费者不知判定标准
  18. 3dsMax学习笔记01_用VRayMtl材质制作玻璃材质
  19. 抖音屏保Java_java编写抖音超火时钟屏保 swing编写
  20. frp服务实现内网穿透SSH远程内网虚拟机

热门文章

  1. vue根据后端菜单数据生成动态路由
  2. 大促系统全流量压测及稳定性保证——京东交易架构分享(含PPT)
  3. 自动驾驶技术:前景、优势与挑战
  4. Docker玩腻了,不妨试试用Vagrant
  5. Java分别采用继承、多态、抽象类、接口实现猫和狗的入门案例
  6. WmiPrvSE.exe是什么进程?WMI Provider Host占用很高CPU怎么办?
  7. 看了必懂的并查集原理(转载)
  8. 疫情后的第三年:时代更迭下的技术管理与团队协作
  9. android studio记账,Android Studio--家庭记账本(五)
  10. 前华为员工的1则爆料帖,让我看清了职场上最赤裸裸的真相