Elastic Beanstalk 的例子使用 AWS CLI - AWS Command Line Interface

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Elastic Beanstalk 的例子使用 AWS CLI

下列程式碼範例會示範如何使用 Elastic Beanstalk 來執行動作及實作常見案例。 AWS Command Line Interface

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境和跨服務範例中查看內容中的動作。

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用abort-environment-update

AWS CLI

中止部署的步驟

下列命令會中止名my-env為的環境執行中的應用程式版本部署:

aws elasticbeanstalk abort-environment-update --environment-name my-env

下列程式碼範例會示範如何使用check-dns-availability

AWS CLI

若要檢查 CNAME 的可用性

下面的命令檢查子域my-cname.elasticbeanstalk.com的可用性:

aws elasticbeanstalk check-dns-availability --cname-prefix my-cname

輸出:

{ "Available": true, "FullyQualifiedCNAME": "my-cname.elasticbeanstalk.com" }

下列程式碼範例會示範如何使用create-application-version

AWS CLI

建立新的應用程式版本

下列命令會建立名為 "" 的應用程式的新版本 MyApp「V1":

aws elasticbeanstalk create-application-version --application-name MyApp --version-label v1 --description MyAppv1 --source-bundle S3Bucket="my-bucket",S3Key="sample.war" --auto-create-application

由於該 auto-create-application 選項,如果應用程序不存在,則將自動創建該應用程序。源代碼包是存儲在一個名為「我的桶」的 s3 存儲桶中的 .war 文件,該存儲桶包含 Apache Tomcat 示例應用程序。

輸出:

{ "ApplicationVersion": { "ApplicationName": "MyApp", "VersionLabel": "v1", "Description": "MyAppv1", "DateCreated": "2015-02-03T23:01:25.412Z", "DateUpdated": "2015-02-03T23:01:25.412Z", "SourceBundle": { "S3Bucket": "my-bucket", "S3Key": "sample.war" } } }

下列程式碼範例會示範如何使用create-application

AWS CLI

若要建立新的應用程式

下列命令會建立名為 "MyApp「的新應用程式:

aws elasticbeanstalk create-application --application-name MyApp --description "my application"

此命create-application令只會設定應用程式的名稱和說明。若要上傳應用程式的原始程式碼,請使用建立應用程式的初始版本create-application-versioncreate-application-version還有一個auto-create-application選項,可讓您在一個步驟中創建應用程序和應用程序版本。

輸出:

{ "Application": { "ApplicationName": "MyApp", "ConfigurationTemplates": [], "DateUpdated": "2015-02-12T18:32:21.181Z", "Description": "my application", "DateCreated": "2015-02-12T18:32:21.181Z" } }

下列程式碼範例會示範如何使用create-configuration-template

AWS CLI

建立組態範本的步驟

下列指令會根據套用至具有 id 之環境的設定建立名為my-app-v1的組態範本e-rpqsewtp2j

aws elasticbeanstalk create-configuration-template --application-name my-app --template-name my-app-v1 --environment-id e-rpqsewtp2j

輸出:

{ "ApplicationName": "my-app", "TemplateName": "my-app-v1", "DateCreated": "2015-08-12T18:40:39Z", "DateUpdated": "2015-08-12T18:40:39Z", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8" }

下列程式碼範例會示範如何使用create-environment

AWS CLI

建立應用程式的新環境

以下命令為名為「my-app」的 Java 應用程序的版本「V1」創建一個新環境:

aws elasticbeanstalk create-environment --application-name my-app --environment-name my-env --cname-prefix my-app --version-label v1 --solution-stack-name "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8"

輸出:

{ "ApplicationName": "my-app", "EnvironmentName": "my-env", "VersionLabel": "v1", "Status": "Launching", "EnvironmentId": "e-izqpassy4h", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8", "CNAME": "my-app.elasticbeanstalk.com", "Health": "Grey", "Tier": { "Type": "Standard", "Name": "WebServer", "Version": " " }, "DateUpdated": "2015-02-03T23:04:54.479Z", "DateCreated": "2015-02-03T23:04:54.479Z" }

v1是先前使用上傳的應用程式版本的標籤 create-application-version。

若要指定 JSON 檔案以定義環境組態選項

下列create-environment命令會指定myoptions.json應使用名稱為 JSON 檔案來覆寫從解決方案堆疊或設定範本取得的值:

aws elasticbeanstalk create-environment --environment-name sample-env --application-name sampleapp --option-settings file://myoptions.json

myoptions.json是一個 JSON 對象,定義了幾個設置:

[ { "Namespace": "aws:elb:healthcheck", "OptionName": "Interval", "Value": "15" }, { "Namespace": "aws:elb:healthcheck", "OptionName": "Timeout", "Value": "8" }, { "Namespace": "aws:elb:healthcheck", "OptionName": "HealthyThreshold", "Value": "2" }, { "Namespace": "aws:elb:healthcheck", "OptionName": "UnhealthyThreshold", "Value": "3" } ]

如需詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的選項值。

下列程式碼範例會示範如何使用create-storage-location

AWS CLI

建立儲存位置

下列命令會在 Amazon S3 中建立儲存位置:

aws elasticbeanstalk create-storage-location

輸出:

{ "S3Bucket": "elasticbeanstalk-us-west-2-0123456789012" }

下列程式碼範例會示範如何使用delete-application-version

AWS CLI

若要刪除應用程式版本

下列命令會刪除以名稱為的應用程式命名22a0-stage-150819_182129的應用程式版本my-app

aws elasticbeanstalk delete-application-version --version-label 22a0-stage-150819_182129 --application-name my-app

下列程式碼範例會示範如何使用delete-application

AWS CLI

如欲刪除應用程式

下列命令會刪除名為的應用程式my-app

aws elasticbeanstalk delete-application --application-name my-app

下列程式碼範例會示範如何使用delete-configuration-template

AWS CLI

若要刪除組態範本

下列命令會刪除名為應用程式名稱my-template的組態範本my-app

aws elasticbeanstalk delete-configuration-template --template-name my-template --application-name my-app

下列程式碼範例會示範如何使用delete-environment-configuration

AWS CLI

刪除草繪模型組態

下列指令會刪除名為之環境的草稿規劃my-env

aws elasticbeanstalk delete-environment-configuration --environment-name my-env --application-name my-app

下列程式碼範例會示範如何使用describe-application-versions

AWS CLI

若要檢視應用程式版本的相關資訊

下列命令會擷取標示為應用程式版本的相關資訊v2

aws elasticbeanstalk describe-application-versions --application-name my-app --version-label "v2"

輸出:

{ "ApplicationVersions": [ { "ApplicationName": "my-app", "VersionLabel": "v2", "Description": "update cover page", "DateCreated": "2015-07-23T01:32:26.079Z", "DateUpdated": "2015-07-23T01:32:26.079Z", "SourceBundle": { "S3Bucket": "elasticbeanstalk-us-west-2-015321684451", "S3Key": "my-app/5026-stage-150723_224258.war" } }, { "ApplicationName": "my-app", "VersionLabel": "v1", "Description": "initial version", "DateCreated": "2015-07-23T22:26:10.816Z", "DateUpdated": "2015-07-23T22:26:10.816Z", "SourceBundle": { "S3Bucket": "elasticbeanstalk-us-west-2-015321684451", "S3Key": "my-app/5026-stage-150723_222618.war" } } ] }

下列程式碼範例會示範如何使用describe-applications

AWS CLI

若要檢視應用程式清單

下列命令會擷取目前區域中應用程式的相關資訊:

aws elasticbeanstalk describe-applications

輸出:

{ "Applications": [ { "ApplicationName": "ruby", "ConfigurationTemplates": [], "DateUpdated": "2015-08-13T21:05:44.376Z", "Versions": [ "Sample Application" ], "DateCreated": "2015-08-13T21:05:44.376Z" }, { "ApplicationName": "pythonsample", "Description": "Application created from the EB CLI using \"eb init\"", "Versions": [ "Sample Application" ], "DateCreated": "2015-08-13T19:05:43.637Z", "ConfigurationTemplates": [], "DateUpdated": "2015-08-13T19:05:43.637Z" }, { "ApplicationName": "nodejs-example", "ConfigurationTemplates": [], "DateUpdated": "2015-08-06T17:50:02.486Z", "Versions": [ "add elasticache", "First Release" ], "DateCreated": "2015-08-06T17:50:02.486Z" } ] }

下列程式碼範例會示範如何使用describe-configuration-options

AWS CLI

若要檢視環境的組態選項

下列命令會擷取名為之環境的所有可用組態選項的描述my-env

aws elasticbeanstalk describe-configuration-options --environment-name my-env --application-name my-app

輸出(縮寫):

{ "Options": [ { "Name": "JVMOptions", "UserDefined": false, "DefaultValue": "Xms=256m,Xmx=256m,XX:MaxPermSize=64m,JVM Options=", "ChangeSeverity": "RestartApplicationServer", "Namespace": "aws:cloudformation:template:parameter", "ValueType": "KeyValueList" }, { "Name": "Interval", "UserDefined": false, "DefaultValue": "30", "ChangeSeverity": "NoInterruption", "Namespace": "aws:elb:healthcheck", "MaxValue": 300, "MinValue": 5, "ValueType": "Scalar" }, ... { "Name": "LowerThreshold", "UserDefined": false, "DefaultValue": "2000000", "ChangeSeverity": "NoInterruption", "Namespace": "aws:autoscaling:trigger", "MinValue": 0, "ValueType": "Scalar" }, { "Name": "ListenerEnabled", "UserDefined": false, "DefaultValue": "true", "ChangeSeverity": "Unknown", "Namespace": "aws:elb:listener", "ValueType": "Boolean" } ] }

可用的組態選項會因平台和組態版本而異。如需有關命名空間和支援選項的詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的選項值。

下列程式碼範例會示範如何使用describe-configuration-settings

AWS CLI

檢視環境的組態設定

下列命令會擷取名為之環境的組態設定my-env

aws elasticbeanstalk describe-configuration-settings --environment-name my-env --application-name my-app

輸出(縮寫):

{ "ConfigurationSettings": [ { "ApplicationName": "my-app", "EnvironmentName": "my-env", "Description": "Environment created from the EB CLI using \"eb create\"", "DeploymentStatus": "deployed", "DateCreated": "2015-08-13T19:16:25Z", "OptionSettings": [ { "OptionName": "Availability Zones", "ResourceName": "AWSEBAutoScalingGroup", "Namespace": "aws:autoscaling:asg", "Value": "Any" }, { "OptionName": "Cooldown", "ResourceName": "AWSEBAutoScalingGroup", "Namespace": "aws:autoscaling:asg", "Value": "360" }, ... { "OptionName": "ConnectionDrainingTimeout", "ResourceName": "AWSEBLoadBalancer", "Namespace": "aws:elb:policies", "Value": "20" }, { "OptionName": "ConnectionSettingIdleTimeout", "ResourceName": "AWSEBLoadBalancer", "Namespace": "aws:elb:policies", "Value": "60" } ], "DateUpdated": "2015-08-13T23:30:07Z", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8" } ] }

如需有關命名空間和支援選項的詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的選項值。

下列程式碼範例會示範如何使用describe-environment-health

AWS CLI

若要檢視環境健康

下列命令會擷取名為的環境的整體健全狀況資訊my-env

aws elasticbeanstalk describe-environment-health --environment-name my-env --attribute-names All

輸出:

{ "Status": "Ready", "EnvironmentName": "my-env", "Color": "Green", "ApplicationMetrics": { "Duration": 10, "Latency": { "P99": 0.004, "P75": 0.002, "P90": 0.003, "P95": 0.004, "P85": 0.003, "P10": 0.001, "P999": 0.004, "P50": 0.001 }, "RequestCount": 45, "StatusCodes": { "Status3xx": 0, "Status2xx": 45, "Status5xx": 0, "Status4xx": 0 } }, "RefreshedAt": "2015-08-20T21:09:18Z", "HealthStatus": "Ok", "InstancesHealth": { "Info": 0, "Ok": 1, "Unknown": 0, "Severe": 0, "Warning": 0, "Degraded": 0, "NoData": 0, "Pending": 0 }, "Causes": [] }

Health 資訊僅適用於已啟用增強健全狀況報告的環境。如需詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的增強型 Health 報告和監控。

下列程式碼範例會示範如何使用describe-environment-resources

AWS CLI

若要檢視環境中 AWS 資源的相關資訊

下列命令會擷取名為的環境中的資源相關資訊my-env

aws elasticbeanstalk describe-environment-resources --environment-name my-env

輸出:

{ "EnvironmentResources": { "EnvironmentName": "my-env", "AutoScalingGroups": [ { "Name": "awseb-e-qu3fyyjyjs-stack-AWSEBAutoScalingGroup-QSB2ZO88SXZT" } ], "Triggers": [], "LoadBalancers": [ { "Name": "awseb-e-q-AWSEBLoa-1EEPZ0K98BIF0" } ], "Queues": [], "Instances": [ { "Id": "i-0c91c786" } ], "LaunchConfigurations": [ { "Name": "awseb-e-qu3fyyjyjs-stack-AWSEBAutoScalingLaunchConfiguration-1UUVQIBC96TQ2" } ] } }

下列程式碼範例會示範如何使用describe-environments

AWS CLI

若要檢視環境的相關資訊

下列指令會擷取名為的環境的相關資訊my-env

aws elasticbeanstalk describe-environments --environment-names my-env

輸出:

{ "Environments": [ { "ApplicationName": "my-app", "EnvironmentName": "my-env", "VersionLabel": "7f58-stage-150812_025409", "Status": "Ready", "EnvironmentId": "e-rpqsewtp2j", "EndpointURL": "awseb-e-w-AWSEBLoa-1483140XB0Q4L-109QXY8121.us-west-2.elb.amazonaws.com", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8", "CNAME": "my-env.elasticbeanstalk.com", "Health": "Green", "AbortableOperationInProgress": false, "Tier": { "Version": " ", "Type": "Standard", "Name": "WebServer" }, "DateUpdated": "2015-08-12T18:16:55.019Z", "DateCreated": "2015-08-07T20:48:49.599Z" } ] }

下列程式碼範例會示範如何使用describe-events

AWS CLI

若要檢視環境的事件

下列命令會擷取名為環境的事件my-env

aws elasticbeanstalk describe-events --environment-name my-env

輸出(縮寫):

{ "Events": [ { "ApplicationName": "my-app", "EnvironmentName": "my-env", "Message": "Environment health has transitioned from Info to Ok.", "EventDate": "2015-08-20T07:06:53.535Z", "Severity": "INFO" }, { "ApplicationName": "my-app", "EnvironmentName": "my-env", "Severity": "INFO", "RequestId": "b7f3960b-4709-11e5-ba1e-07e16200da41", "Message": "Environment update completed successfully.", "EventDate": "2015-08-20T07:06:02.049Z" }, ... { "ApplicationName": "my-app", "EnvironmentName": "my-env", "Severity": "INFO", "RequestId": "ca8dfbf6-41ef-11e5-988b-651aa638f46b", "Message": "Using elasticbeanstalk-us-west-2-012445113685 as Amazon S3 storage bucket for environment data.", "EventDate": "2015-08-13T19:16:27.561Z" }, { "ApplicationName": "my-app", "EnvironmentName": "my-env", "Severity": "INFO", "RequestId": "cdfba8f6-41ef-11e5-988b-65638f41aa6b", "Message": "createEnvironment is starting.", "EventDate": "2015-08-13T19:16:26.581Z" } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DescribeEvents中的。

下列程式碼範例會示範如何使用describe-instances-health

AWS CLI

若要檢視環境健康

下列命令會擷取名為的環境中執行個體的健全狀況資訊my-env

aws elasticbeanstalk describe-instances-health --environment-name my-env --attribute-names All

輸出:

{ "InstanceHealthList": [ { "InstanceId": "i-08691cc7", "ApplicationMetrics": { "Duration": 10, "Latency": { "P99": 0.006, "P75": 0.002, "P90": 0.004, "P95": 0.005, "P85": 0.003, "P10": 0.0, "P999": 0.006, "P50": 0.001 }, "RequestCount": 48, "StatusCodes": { "Status3xx": 0, "Status2xx": 47, "Status5xx": 0, "Status4xx": 1 } }, "System": { "LoadAverage": [ 0.0, 0.02, 0.05 ], "CPUUtilization": { "SoftIRQ": 0.1, "IOWait": 0.2, "System": 0.3, "Idle": 97.8, "User": 1.5, "IRQ": 0.0, "Nice": 0.1 } }, "Color": "Green", "HealthStatus": "Ok", "LaunchedAt": "2015-08-13T19:17:09Z", "Causes": [] } ], "RefreshedAt": "2015-08-20T21:09:08Z" }

Health 資訊僅適用於已啟用增強健全狀況報告的環境。如需詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的增強型 Health 報告和監控。

下列程式碼範例會示範如何使用list-available-solution-stacks

AWS CLI

檢視解決方案堆疊

下列命令會列出目前所有可用平台組態的解決方案堆疊,以及您過去使用過的任何項目:

aws elasticbeanstalk list-available-solution-stacks

輸出(縮寫):

{ "SolutionStacks": [ "64bit Amazon Linux 2015.03 v2.0.0 running Node.js", "64bit Amazon Linux 2015.03 v2.0.0 running PHP 5.6", "64bit Amazon Linux 2015.03 v2.0.0 running PHP 5.5", "64bit Amazon Linux 2015.03 v2.0.0 running PHP 5.4", "64bit Amazon Linux 2015.03 v2.0.0 running Python 3.4", "64bit Amazon Linux 2015.03 v2.0.0 running Python 2.7", "64bit Amazon Linux 2015.03 v2.0.0 running Python", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 2.2 (Puma)", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 2.2 (Passenger Standalone)", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 2.1 (Puma)", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 2.1 (Passenger Standalone)", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 2.0 (Puma)", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 2.0 (Passenger Standalone)", "64bit Amazon Linux 2015.03 v2.0.0 running Ruby 1.9.3", "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8", "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 7 Java 7", "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 7 Java 6", "64bit Windows Server Core 2012 R2 running IIS 8.5", "64bit Windows Server 2012 R2 running IIS 8.5", "64bit Windows Server 2012 running IIS 8", "64bit Windows Server 2008 R2 running IIS 7.5", "64bit Amazon Linux 2015.03 v2.0.0 running Docker 1.6.2", "64bit Amazon Linux 2015.03 v2.0.0 running Multi-container Docker 1.6.2 (Generic)", "64bit Debian jessie v2.0.0 running GlassFish 4.1 Java 8 (Preconfigured - Docker)", "64bit Debian jessie v2.0.0 running GlassFish 4.0 Java 7 (Preconfigured - Docker)", "64bit Debian jessie v2.0.0 running Go 1.4 (Preconfigured - Docker)", "64bit Debian jessie v2.0.0 running Go 1.3 (Preconfigured - Docker)", "64bit Debian jessie v2.0.0 running Python 3.4 (Preconfigured - Docker)", ], "SolutionStackDetails": [ { "PermittedFileTypes": [ "zip" ], "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Node.js" }, ... ] }

下列程式碼範例會示範如何使用rebuild-environment

AWS CLI

重新建置環境

下列指令會在名為的環境中終止並重新建立資源:my-env

aws elasticbeanstalk rebuild-environment --environment-name my-env

下列程式碼範例會示範如何使用request-environment-info

AWS CLI

要求尾部記錄

下列命令會從名為的環境要求記錄檔my-env

aws elasticbeanstalk request-environment-info --environment-name my-env --info-type tail

請求日誌後,使用 retrieve-environment-info.

下列程式碼範例會示範如何使用restart-app-server

AWS CLI

重新啟動應用程式伺

下列命令會在名為my-env的環境中重新啟動所有執行個體的應用程式伺服

aws elasticbeanstalk restart-app-server --environment-name my-env
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考RestartAppServer中的。

下列程式碼範例會示範如何使用retrieve-environment-info

AWS CLI

若要擷取尾部記錄

下列命令會從名為的環境擷取記錄檔的連結my-env

aws elasticbeanstalk retrieve-environment-info --environment-name my-env --info-type tail

輸出:

{ "EnvironmentInfo": [ { "SampleTimestamp": "2015-08-20T22:23:17.703Z", "Message": "https://elasticbeanstalk-us-west-2-0123456789012.s3.amazonaws.com/resources/environments/logs/tail/e-fyqyju3yjs/i-09c1c867/TailLogs-1440109397703.out?AWSAccessKeyId=AKGPT4J56IAJ2EUBL5CQ&Expires=1440195891&Signature=n%2BEalOV6A2HIOx4Rcfb7LT16bBM%3D", "InfoType": "tail", "Ec2InstanceId": "i-09c1c867" } ] }

在瀏覽器中檢視連結。在擷取之前,必須使用請求記錄檔 request-environment-info。

下列程式碼範例會示範如何使用swap-environment-cnames

AWS CLI

交換環境名稱

下列指令會置換兩個環境的指派子網域:

aws elasticbeanstalk swap-environment-cnames --source-environment-name my-env-blue --destination-environment-name my-env-green

下列程式碼範例會示範如何使用terminate-environment

AWS CLI

終止環境的步驟

以下命令終止名為的 Elastic Beanstalk 環境:my-env

aws elasticbeanstalk terminate-environment --environment-name my-env

輸出:

{ "ApplicationName": "my-app", "EnvironmentName": "my-env", "Status": "Terminating", "EnvironmentId": "e-fh2eravpns", "EndpointURL": "awseb-e-f-AWSEBLoa-1I9XUMP4-8492WNUP202574.us-west-2.elb.amazonaws.com", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8", "CNAME": "my-env.elasticbeanstalk.com", "Health": "Grey", "AbortableOperationInProgress": false, "Tier": { "Version": " ", "Type": "Standard", "Name": "WebServer" }, "DateUpdated": "2015-08-12T19:05:54.744Z", "DateCreated": "2015-08-12T18:52:53.622Z" }

下列程式碼範例會示範如何使用update-application-version

AWS CLI

若要變更應用程式版本的說明

下列命令會更新名為的應用程式版本的說明22a0-stage-150819_185942

aws elasticbeanstalk update-application-version --version-label 22a0-stage-150819_185942 --application-name my-app --description "new description"

輸出:

{ "ApplicationVersion": { "ApplicationName": "my-app", "VersionLabel": "22a0-stage-150819_185942", "Description": "new description", "DateCreated": "2015-08-19T18:59:17.646Z", "DateUpdated": "2015-08-20T22:53:28.871Z", "SourceBundle": { "S3Bucket": "elasticbeanstalk-us-west-2-0123456789012", "S3Key": "my-app/22a0-stage-150819_185942.war" } } }

下列程式碼範例會示範如何使用update-application

AWS CLI

若要變更應用程式的說明

下列命令會更新名為之應用程式的說明my-app

aws elasticbeanstalk update-application --application-name my-app --description "my Elastic Beanstalk application"

輸出:

{ "Application": { "ApplicationName": "my-app", "Description": "my Elastic Beanstalk application", "Versions": [ "2fba-stage-150819_234450", "bf07-stage-150820_214945", "93f8", "fd7c-stage-150820_000431", "22a0-stage-150819_185942" ], "DateCreated": "2015-08-13T19:15:50.449Z", "ConfigurationTemplates": [], "DateUpdated": "2015-08-20T22:34:56.195Z" } }

下列程式碼範例會示範如何使用update-configuration-template

AWS CLI

更新組態範本

下列命令會從名稱為的儲存組態範本ConfigDocument中移除設定的 CloudWatch 自訂健全狀況測量結果組態my-template

aws elasticbeanstalk update-configuration-template --template-name my-template --application-name my-app --options-to-remove Namespace=aws:elasticbeanstalk:healthreporting:system,OptionName=ConfigDocument

輸出:

{ "ApplicationName": "my-app", "TemplateName": "my-template", "DateCreated": "2015-08-20T22:39:31Z", "DateUpdated": "2015-08-20T22:43:11Z", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8" }

如需有關命名空間和支援選項的詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的選項值。

下列程式碼範例會示範如何使用update-environment

AWS CLI

將環境更新為新版本的步驟

下列指令會將名為「my-env」的環境更新為其所屬應用程式的版本「v2」:

aws elasticbeanstalk update-environment --environment-name my-env --version-label v2

此指令要求「my-env」環境已存在,且屬於具有標籤為「v2」之有效應用程式版本的應用程式。

輸出:

{ "ApplicationName": "my-app", "EnvironmentName": "my-env", "VersionLabel": "v2", "Status": "Updating", "EnvironmentId": "e-szqipays4h", "EndpointURL": "awseb-e-i-AWSEBLoa-1RDLX6TC9VUAO-0123456789.us-west-2.elb.amazonaws.com", "SolutionStackName": "64bit Amazon Linux running Tomcat 7", "CNAME": "my-env.elasticbeanstalk.com", "Health": "Grey", "Tier": { "Version": " ", "Type": "Standard", "Name": "WebServer" }, "DateUpdated": "2015-02-03T23:12:29.119Z", "DateCreated": "2015-02-03T23:04:54.453Z" }

設定環境變數

以下命令將 "我的 ENV" 環境中的 "PARAM1" 變量的值設置為" "ParamValue:

aws elasticbeanstalk update-environment --environment-name my-env --option-settings Namespace=aws:elasticbeanstalk:application:environment,OptionName=PARAM1,Value=ParamValue

除了變option-settings數的名稱和值之外,參數還需要命名空間。除了環境變量之外,Elastic Beanstalk 還支持多個選項命名空間。

從檔案規劃選項設定的步驟

以下命令從文件配置命aws:elb:loadbalancer名空間中的幾個選項:

aws elasticbeanstalk update-environment --environment-name my-env --option-settings file://options.json

options.json是一個 JSON 對象,定義了幾個設置:

[ { "Namespace": "aws:elb:healthcheck", "OptionName": "Interval", "Value": "15" }, { "Namespace": "aws:elb:healthcheck", "OptionName": "Timeout", "Value": "8" }, { "Namespace": "aws:elb:healthcheck", "OptionName": "HealthyThreshold", "Value": "2" }, { "Namespace": "aws:elb:healthcheck", "OptionName": "UnhealthyThreshold", "Value": "3" } ]

輸出:

{ "ApplicationName": "my-app", "EnvironmentName": "my-env", "VersionLabel": "7f58-stage-150812_025409", "Status": "Updating", "EnvironmentId": "e-wtp2rpqsej", "EndpointURL": "awseb-e-w-AWSEBLoa-14XB83101Q4L-104QXY80921.sa-east-1.elb.amazonaws.com", "SolutionStackName": "64bit Amazon Linux 2015.03 v2.0.0 running Tomcat 8 Java 8", "CNAME": "my-env.elasticbeanstalk.com", "Health": "Grey", "AbortableOperationInProgress": true, "Tier": { "Version": " ", "Type": "Standard", "Name": "WebServer" }, "DateUpdated": "2015-08-12T18:15:23.804Z", "DateCreated": "2015-08-07T20:48:49.599Z" }

如需有關命名空間和支援選項的詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的選項值。

下列程式碼範例會示範如何使用validate-configuration-settings

AWS CLI

驗證組態設定的步驟

下列指令會驗證 CloudWatch 自訂量度組態文件:

aws elasticbeanstalk validate-configuration-settings --application-name my-app --environment-name my-env --option-settings file://options.json

options.json是 JSON 文件,其中包含要驗證的一或多個組態設定:

[ { "Namespace": "aws:elasticbeanstalk:healthreporting:system", "OptionName": "ConfigDocument", "Value": "{\"CloudWatchMetrics\": {\"Environment\": {\"ApplicationLatencyP99.9\": null,\"InstancesSevere\": 60,\"ApplicationLatencyP90\": 60,\"ApplicationLatencyP99\": null,\"ApplicationLatencyP95\": 60,\"InstancesUnknown\": 60,\"ApplicationLatencyP85\": 60,\"InstancesInfo\": null,\"ApplicationRequests2xx\": null,\"InstancesDegraded\": null,\"InstancesWarning\": 60,\"ApplicationLatencyP50\": 60,\"ApplicationRequestsTotal\": null,\"InstancesNoData\": null,\"InstancesPending\": 60,\"ApplicationLatencyP10\": null,\"ApplicationRequests5xx\": null,\"ApplicationLatencyP75\": null,\"InstancesOk\": 60,\"ApplicationRequests3xx\": null,\"ApplicationRequests4xx\": null},\"Instance\": {\"ApplicationLatencyP99.9\": null,\"ApplicationLatencyP90\": 60,\"ApplicationLatencyP99\": null,\"ApplicationLatencyP95\": null,\"ApplicationLatencyP85\": null,\"CPUUser\": 60,\"ApplicationRequests2xx\": null,\"CPUIdle\": null,\"ApplicationLatencyP50\": null,\"ApplicationRequestsTotal\": 60,\"RootFilesystemUtil\": null,\"LoadAverage1min\": null,\"CPUIrq\": null,\"CPUNice\": 60,\"CPUIowait\": 60,\"ApplicationLatencyP10\": null,\"LoadAverage5min\": null,\"ApplicationRequests5xx\": null,\"ApplicationLatencyP75\": 60,\"CPUSystem\": 60,\"ApplicationRequests3xx\": 60,\"ApplicationRequests4xx\": null,\"InstanceHealth\": null,\"CPUSoftirq\": 60}},\"Version\": 1}" } ]

如果您指定的選項對指定的環境有效,Elastic Beanstalk 會傳回空的訊息陣列:

{ "Messages": [] }

如果驗證失敗,則響應將包含有關錯誤的信息:

{ "Messages": [ { "OptionName": "ConfigDocumet", "Message": "Invalid option specification (Namespace: 'aws:elasticbeanstalk:healthreporting:system', OptionName: 'ConfigDocumet'): Unknown configuration setting.", "Namespace": "aws:elasticbeanstalk:healthreporting:system", "Severity": "error" } ] }

如需有關命名空間和支援選項的詳細資訊,請參閱 E AWS lastic Beanstalk 開發人員指南中的選項值。