ebcli帮助程序
commands:
abort Cancels an environment update or deployment.
appversion Listing and managing application versions
clone 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 init/create
分别对应创建应用和创建环境,一个应用可以对应多个环境,之前已经介绍过了此处略过
eb config
修改默认的配置文件,增加自定义配置。此处列出了默认的环境配置,涉及到以下方面
- 环境的语言和平台版本
- elb监听器和规则
- asg容量配置,扩缩策略,更新策略
- cw告警规则
- 启动配置参数
- 实例类型和大小
- 其他额外配置
更新环境配置后,环境会自动进行更新。
- 如果需要放弃更新,可以执行
eb abort
终止环境更新 - 环境变动过程中,可以执行
eb events -f
查看最新的event(和控制台一致)
ApplicationName: test-beanpython
DateUpdated: 2023-03-30 03:26:48+00:00
EnvironmentName: test-beanpython-dev
PlatformArn: arn:aws-cn:elasticbeanstalk:cn-north-1::platform/Python 3.8 running on
64bit Amazon Linux 2/3.5.0
settings:
:default.aws:elbv2:listener:8095:
Rules: default
:default.aws:elbv2:listenerrule:default:
HostHeaders: test-beanpython-dev.cn-north-1.eb.amazonaws.com.cn
PathPatterns: /*
Priority: '1'
Process: default
AWSEBAutoScalingScaleDownPolicy.aws:autoscaling:trigger:
LowerBreachScaleIncrement: '-1'
AWSEBAutoScalingScaleUpPolicy.aws:autoscaling:trigger:
UpperBreachScaleIncrement: '1'
AWSEBCloudwatchAlarmHigh.aws:autoscaling:trigger:
UpperThreshold: '6000000'
AWSEBCloudwatchAlarmLow.aws:autoscaling:trigger:
BreachDuration: '5'
EvaluationPeriods: '1'
LowerThreshold: '2000000'
MeasureName: NetworkOut
Period: '5'
Statistic: Average
Unit: Bytes
aws:autoscaling:asg:
Availability Zones: Any
Cooldown: '360'
Custom Availability Zones: ''
EnableCapacityRebalancing: 'false'
MaxSize: '4'
MinSize: '1'
aws:autoscaling:launchconfiguration:
BlockDeviceMappings: null
DisableIMDSv1: 'false'
EC2KeyName: temp-key
IamInstanceProfile: aws-elasticbeanstalk-ec2-role
ImageId: ami-07595fd9680882696
InstanceType: t2.micro
MonitoringInterval: 5 minute
RootVolumeIOPS: null
RootVolumeSize: null
RootVolumeThroughput: null
RootVolumeType: null
SSHSourceRestriction: tcp,22,22,0.0.0.0/0
SecurityGroups: awseb-e-npzn8apcmw-stack-AWSEBSecurityGroup-1IV9P7J8WDOKP
aws:autoscaling:updatepolicy:rollingupdate:
MaxBatchSize: '1'
MinInstancesInService: '1'
PauseTime: null
RollingUpdateEnabled: 'true'
RollingUpdateType: Health
Timeout: PT30M
aws:ec2:instances:
EnableSpot: 'false'
InstanceTypes: t2.micro, t2.small
SpotFleetOnDemandAboveBasePercentage: '70'
SpotFleetOnDemandBase: '0'
SpotMaxPrice: null
SupportedArchitectures: x86_64
aws:ec2:vpc:
AssociatePublicIpAddress: null
ELBScheme: public
ELBSubnets: null
Subnets: null
VPCId: null
aws:elasticbeanstalk:application:
Application Healthcheck URL: ''
aws:elasticbeanstalk:cloudwatch:logs:
DeleteOnTerminate: 'false'
RetentionInDays: '7'
StreamLogs: 'false'
aws:elasticbeanstalk:cloudwatch:logs:health:
DeleteOnTerminate: 'false'
HealthStreamingEnabled: 'false'
RetentionInDays: '7'
aws:elasticbeanstalk:command:
BatchSize: '30'
BatchSizeType: Percentage
DeploymentPolicy: Rolling
IgnoreHealthCheck: 'false'
Timeout: '600'
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
WSGIPath: application
aws:elasticbeanstalk:control:
DefaultSSHPort: '22'
LaunchTimeout: '0'
LaunchType: Migration
RollbackLaunchOnFailure: 'false'
aws:elasticbeanstalk:environment:
EnvironmentType: LoadBalanced
ExternalExtensionsS3Bucket: null
ExternalExtensionsS3Key: null
LoadBalancerIsShared: 'true'
LoadBalancerType: application
ServiceRole: aws-elasticbeanstalk-service-role
aws:elasticbeanstalk:environment:process:default:
DeregistrationDelay: '20'
HealthCheckInterval: '15'
HealthCheckPath: /
HealthCheckTimeout: '5'
HealthyThresholdCount: '3'
MatcherHTTPCode: null
Port: '80'
Protocol: HTTP
StickinessEnabled: 'false'
StickinessLBCookieDuration: '86400'
StickinessType: lb_cookie
UnhealthyThresholdCount: '5'
aws:elasticbeanstalk:environment:proxy:
ProxyServer: nginx
aws:elasticbeanstalk:healthreporting:system:
ConfigDocument: '{"Version":1,"CloudWatchMetrics":{"Instance":{"CPUIrq":null,"LoadAverage5min":null,"ApplicationRequests5xx":null,"ApplicationRequests4xx":null,"CPUUser":null,"LoadAverage1min":null,"ApplicationLatencyP50":null,"CPUIdle":null,"InstanceHealth":null,"ApplicationLatencyP95":null,"ApplicationLatencyP85":null,"RootFilesystemUtil":null,"ApplicationLatencyP90":null,"CPUSystem":null,"ApplicationLatencyP75":null,"CPUSoftirq":null,"ApplicationLatencyP10":null,"ApplicationLatencyP99":null,"ApplicationRequestsTotal":null,"ApplicationLatencyP99.9":null,"ApplicationRequests3xx":null,"ApplicationRequests2xx":null,"CPUIowait":null,"CPUNice":null},"Environment":{"InstancesSevere":null,"InstancesDegraded":null,"ApplicationRequests5xx":null,"ApplicationRequests4xx":null,"ApplicationLatencyP50":null,"ApplicationLatencyP95":null,"ApplicationLatencyP85":null,"InstancesUnknown":null,"ApplicationLatencyP90":null,"InstancesInfo":null,"InstancesPending":null,"ApplicationLatencyP75":null,"ApplicationLatencyP10":null,"ApplicationLatencyP99":null,"ApplicationRequestsTotal":null,"InstancesNoData":null,"ApplicationLatencyP99.9":null,"ApplicationRequests3xx":null,"ApplicationRequests2xx":null,"InstancesOk":null,"InstancesWarning":null}}}'
EnhancedHealthAuthEnabled: 'true'
HealthCheckSuccessThreshold: Ok
SystemType: enhanced
aws:elasticbeanstalk:hostmanager:
LogPublicationControl: 'false'
aws:elasticbeanstalk:managedactions:
ManagedActionsEnabled: 'false'
PreferredStartTime: null
ServiceRoleForManagedUpdates: aws-elasticbeanstalk-service-role
aws:elasticbeanstalk:managedactions:platformupdate:
InstanceRefreshEnabled: 'false'
UpdateLevel: null
aws:elasticbeanstalk:monitoring:
Automatically Terminate Unhealthy Instances: 'true'
aws:elasticbeanstalk:sns:topics:
Notification Endpoint: null
Notification Protocol: email
Notification Topic ARN: null
Notification Topic Name: null
aws:elasticbeanstalk:trafficsplitting:
EvaluationTime: null
NewVersionPercent: null
aws:elasticbeanstalk:xray:
XRayEnabled: 'false'
aws:elbv2:loadbalancer:
SecurityGroups: sg-0d892xxxxx36e51
SharedLoadBalancer: arn:aws-cn:elasticloadbalancing:cn-north-1:xxxxxxxxdbalancer/app/main-alb/17ec2f283414a86a
aws:rds:dbinstance:
HasCoupledDatabase: 'false'
可以选择保存当前配置
$ eb config save --cfg my-app-v1
Configuration saved at: xxxxx/.elasticbeanstalk/saved_configs/my-app-v1.cfg.yml
eb deploy
当对应用程序或扩展配置进行更新之后,可以执行eb deploy
命令推送新部署
查看日志如下
2023-03-31 04:59:36 INFO Successfully deployed new configuration to environment.
2023-03-31 04:59:36 INFO Environment update completed successfully.
2023-03-31 05:00:00 INFO Removed instance [i-0d825b2d28f9e5ab4] from your environment.
2023-03-31 05:01:00 WARN Environment health has transitioned from Info to Degraded. 1 instance online is below Auto Scaling group minimum size 2. Configuration update completed 26 seconds ago and took 4 minutes.
2023-03-31 05:02:00 INFO Environment health has transitioned from Degraded to Ok.
2023-03-31 05:02:21 INFO requestEnvironmentInfo is starting.
2023-03-31 05:02:23 INFO Instance deployment completed successfully.
2023-03-31 05:02:28 INFO Pulled logs for environment instances.
2023-03-31 05:12:08 INFO Environment update is starting.
2023-03-31 05:12:16 INFO Updating environment test-beanpython-dev's configuration settings.
2023-03-31 05:12:59 INFO Added instance [i-03e2081eee3a9715e] to your environment.
2023-03-31 05:13:03 INFO Auto Scaling group update progress: New instance(s) added to autoscaling group - Waiting on 1 resource signal(s) with a timeout of PT30M.
2023-03-31 05:16:22 INFO Successfully deployed new configuration to environment.
2023-03-31 05:16:22 INFO Environment update completed successfully.
2023-03-31 05:17:22 INFO Deleted log fragments for this environment.
2023-03-31 05:17:43 INFO createConfigurationTemplate is starting.
2023-03-31 05:17:44 INFO Created new Configuration template: test-python-cfg at https://s3.cn-north-1.amazonaws.com.cn/elasticbeanstalk-cn-north-1-xxxxxxxx/resources/templates/test-beanpython/test-python-cfg
2023-03-31 05:17:44 INFO createConfigurationTemplate completed successfully.
2023-03-31 05:27:46 INFO Environment update is starting.
2023-03-31 05:27:58 INFO Environment health has transitioned from Ok to Info. Application update in progress (running for 6 seconds).
2023-03-31 05:28:26 INFO Deploying new version to instance(s).
2023-03-31 05:28:27 INFO Batch 1: Starting application deployment on instance(s) [i-03exxxxxx15e].
2023-03-31 05:28:49 INFO Batch 1: Starting application deployment command execution.
2023-03-31 05:28:51 INFO Instance deployment successfully generated a 'Procfile'.
2023-03-31 05:28:55 INFO Instance deployment completed successfully.
2023-03-31 05:28:59 INFO Batch 1: Completed application deployment command execution.
2023-03-31 05:28:59 INFO Command execution completed on 1 of 2 instances in environment.
2023-03-31 05:28:59 INFO Batch 1: Registering instance(s) with the load balancer and waiting for them to be healthy.
2023-03-31 05:31:03 INFO Batch 1: Completed application deployment.
2023-03-31 05:31:04 INFO Batch 2: Starting application deployment on instance(s) [i-01bxxxxxx1c0].
2023-03-31 05:31:26 INFO Batch 2: Starting application deployment command execution.
2023-03-31 05:31:27 INFO Instance deployment successfully generated a 'Procfile'.
2023-03-31 05:31:31 INFO Instance deployment completed successfully.
2023-03-31 05:31:35 INFO Batch 2: Completed application deployment command execution.
2023-03-31 05:31:35 INFO Command execution completed on 2 of 2 instances in environment.
2023-03-31 05:31:36 INFO Batch 2: Registering instance(s) with the load balancer and waiting for them to be healthy.
eb health/status
eb health
查看当前应用和环境的整体状况
标题和颜色会显示当前状态
降级会导致环境为red状态
eb status
功能类似
$ eb status
Environment details for: test-beanpython-dev
Application name: test-beanpython
Region: cn-north-1
Deployed Version: Sample Application
Environment ID: e-npzn8apcmw
Platform: arn:aws-cn:elasticbeanstalk:cn-north-1::platform/Python 3.8 running on 64bit Amazon Linux 2/3.5.0
Tier: WebServer-Standard-1.0
CNAME: test-beanpython-dev.cn-north-1.eb.amazonaws.com.cn
Updated: 2023-03-31 05:02:28.576000+00:00
Status: Ready
Health: Green
eb labs
下载当前应用部署包
$ eb labs download
Downloading application version...
Application version downloaded to: xxx/test-beanpython/.elasticbeanstalk/downloads/sample.zip
创建cw监控,会在.ebextensions
下创建配置文件,需要重新部署
$ eb labs setup-cloudwatchlogs
.ebextensions created. In order to complete setup you will need
to check in any changes, (if applicable) and run "eb deploy".
You will also need the cloudwatch log permissions for this IAM User
as well as for the environments instance profile.
For more information see: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html
$ ls .ebextensions/
00sample_log.config cwl-activity-logs-v1.config cwl-setup-v1.config eb-logs-v1.config
$ cat 00sample_log.config
files:
"/opt/elasticbeanstalk/tasks/bundlelogs.d/01-sample-app.conf":
content: |
/tmp/sample-app*
"/opt/elasticbeanstalk/tasks/taillogs.d/01-sample-app.conf":
content: |
/tmp/sample-app.log
eb labs setup-ssl
可以设置环境的ssl通信加密
eb local
eb local只能在beanstalk和docker环境集成时使用,详细可以看这篇
eb logs
可以获取eb环境中ec2实例的日志,可以查看这些日志来对应用程序或配置文件进行故障排除
https://docs.amazonaws.cn/elasticbeanstalk/latest/dg/using-features.logging.html?icmpid=docs_elasticbeanstalk_console
注意:由于beanstalk会将结尾和捆绑日志存储在s3存储桶中,并生成可用于访问日志的预签名url。但是由于中国区的预签名功能只有备案之后才能使用,因此无论是控制台还是cli都会出现401的报错
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HrKyhNVp-1680242328207)(assets/image-20230331130544565.png)]
eb platform
看样子是管理用户自定义平台版本的命令,详情可以看这篇
eb scale
手动扩缩容eb环境对应的asg容量
$ eb scale
usage: eb scale {number} <environment_name> [options ...]
将desired count
扩容为2
$ eb scale 2
eb ssh
ssh登录eb实例的快捷命令,可以选择需要登陆的实例id
$ eb ssh
Select an instance to ssh into
1) i-03e208xxxxa9715e
2) i-01bxxxxxxxbb1c0
(default is 1): 1
eb printenv
打印环境变量
$ eb printenv
Environment Variables:
PYTHONPATH = /var/app/venv/staging-LQM1lest/bin
进入eb实例查看该路径
$ ls /var/app/venv/staging-LQM1lest/bin
activate activate.csh activate.fish Activate.ps1 gunicorn pip pip3 pip3.8 python python3 python3.8
eb tags
对环境tag的
$ eb tags test-beanpython-dev -l
Showing tags for resource 'arn:aws-cn:elasticbeanstalk:cn-north-1:xxxxxxxx:environment/test-beanpython/test-beanpython-dev':
Key Value
Name test-beanpython-dev
elasticbeanstalk:environment-id e-npzn8apcmw
elasticbeanstalk:environment-name test-beanpython-dev