應用運行器示例使用 AWS CLI - AWS Command Line Interface

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

應用運行器示例使用 AWS CLI

下列程式碼範例會示範如何透過 AWS Command Line Interface 與 App Runner 搭配使用來執行動作和實作常見案例。

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

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

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

主題

動作

下列程式碼範例會示範如何使用associate-custom-domain

AWS CLI

將網域名稱和 www 子網域與服務建立關聯

下列associate-custom-domain範例會將您控制的自訂網域名稱與 App Runner 服務產生關聯。網域名稱是根網域example.com,包括特殊情況下的子網域。www.example.com

aws apprunner associate-custom-domain \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "DomainName": "example.com", "EnableWWWSubdomain": true }

輸出:

{ "CustomDomain": { "CertificateValidationRecords": [ { "Name": "_70d3f50a94f7c72dc28784cf55db2f6b.example.com", "Status": "PENDING_VALIDATION", "Type": "CNAME", "Value": "_1270c137383c6307b6832db02504c4b0.bsgbmzkfwj.acm-validations.aws." }, { "Name": "_287870d3f50a94f7c72dc4cf55db2f6b.www.example.com", "Status": "PENDING_VALIDATION", "Type": "CNAME", "Value": "_832db01270c137383c6307b62504c4b0.mzkbsgbfwj.acm-validations.aws." } ], "DomainName": "example.com", "EnableWWWSubdomain": true, "Status": "CREATING" }, "DNSTarget": "psbqam834h.us-east-1.awsapprunner.com", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

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

AWS CLI

建立高可用性 auto 調整規模設定

下列create-auto-scaling-configuration範例會透過MinSize將設定為 5,建立針對高可用性最佳化的 auto 調整設定。透過此設定,App Runner 會嘗試將您的服務執行個體分散到盡可能多達五個可用區域,視 AWS 區域而定。

呼叫會傳回其他設定為預設值的AutoScalingConfiguration物件。在範例中,這是建立名為的組態的第一個呼叫high-availability。修訂版設定為 1,並且是最新的修訂版本。

aws apprunner create-auto-scaling-configuration \ --cli-input-json file://input.json

input.json 的內容:

{ "AutoScalingConfigurationName": "high-availability", "MinSize": 5 }

輸出:

{ "AutoScalingConfiguration": { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/1/2f50e7656d7819fead0f59672e68042e", "AutoScalingConfigurationName": "high-availability", "AutoScalingConfigurationRevision": 1, "CreatedAt": "2020-11-03T00:29:17Z", "Latest": true, "Status": "ACTIVE", "MaxConcurrency": 100, "MaxSize": 50, "MinSize": 5 } }

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

AWS CLI

建立 GitHub 連線

下列create-connection範例會建立私人 GitHub 程式碼儲存庫的連線。成功呼叫後的連線狀態為PENDING_HANDSHAKE。這是因為與提供者的身份驗證握手仍然沒有發生。使用應用程式執行器主控台完成握手。

aws apprunner create-connection \ --cli-input-json file://input.json

input.json 的內容:

{ "ConnectionName": "my-github-connection", "ProviderType": "GITHUB" }

輸出:

{ "Connection": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection", "ConnectionName": "my-github-connection", "Status": "PENDING_HANDSHAKE", "CreatedAt": "2020-11-03T00:32:51Z", "ProviderType": "GITHUB" } }

如需詳細資訊,請參閱 App Runner 開發人員指南中的管理AWS 應用程式執行器連線

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateConnection中的。

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

AWS CLI

範例 1:建立原始程式碼儲存庫服務

下列create-service範例會建立以 Python 原始程式碼儲存庫為基礎的應用程式執行器服務。

aws apprunner create-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceName": "python-app", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" }, "CodeConfiguration": { "ConfigurationSource": "API", "CodeConfigurationValues": { "Runtime": "PYTHON_3", "BuildCommand": "pip install -r requirements.txt", "StartCommand": "python server.py", "Port": "8080", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ] } } } }, "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-20T19:05:25Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }

範例 2:建立原始程式碼儲存庫服務

下列create-service範例會建立以 Python 原始程式碼儲存庫為基礎的應用程式執行器服務。

aws apprunner create-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceName": "python-app", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" }, "CodeConfiguration": { "ConfigurationSource": "API", "CodeConfigurationValues": { "Runtime": "PYTHON_3", "BuildCommand": "pip install -r requirements.txt", "StartCommand": "python server.py", "Port": "8080", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ] } } } }, "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-20T19:05:25Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }

範例 3:建立來源影像儲存庫服務

下列create-service範例會根據儲存在彈性容器登錄 (ECR) 中的映像建立應用程式執行器服務。

aws apprunner create-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceName": "golang-container-app", "SourceConfiguration": { "AuthenticationConfiguration": { "AccessRoleArn": "arn:aws:iam::123456789012:role/my-ecr-role" }, "AutoDeploymentsEnabled": true, "ImageRepository": { "ImageIdentifier": "123456789012.dkr.ecr.us-east-1.amazonaws.com/golang-app:latest", "ImageConfiguration": { "Port": "8080", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ] }, "ImageRepositoryType": "ECR" } }, "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-06T23:15:30Z", "UpdatedAt": "2020-11-06T23:15:30Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/golang-container-app/51728f8a20ce46d39b25398a6c8e9d1a", "ServiceId": "51728f8a20ce46d39b25398a6c8e9d1a", "ServiceName": "golang-container-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "AccessRoleArn": "arn:aws:iam::123456789012:role/my-ecr-role" }, "AutoDeploymentsEnabled": true, "ImageRepository": { "ImageIdentifier": "123456789012.dkr.ecr.us-east-1.amazonaws.com/golang-app:latest", "ImageConfiguration": { "Port": "8080", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ] }, "ImageRepositoryType": "ECR" } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateService中的。

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

AWS CLI

範例 1:刪除自 auto 調整比例組態的最新使用中修訂版本

下列delete-auto-scaling-configuration範例會刪除 App Runner auto 縮放設定的最新作用中修訂版本。若要刪除最新的使用中修訂版,請指定以組態名稱結尾的 Amazon 資源名稱 (ARN),而不使用修訂版元件。

在此範例中,在此動作之前存在兩個版本修訂。因此,修訂版 2 (最新的) 會被刪除。但是,它現在顯示"Latest": false,因為刪除後,它不再是最新的活動版本。

aws apprunner delete-auto-scaling-configuration \ --cli-input-json file://input.json

input.json 的內容:

{ "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability" }

輸出:

{ "AutoScalingConfiguration": { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/2/e76562f50d78042e819fead0f59672e6", "AutoScalingConfigurationName": "high-availability", "AutoScalingConfigurationRevision": 2, "CreatedAt": "2021-02-25T17:42:59Z", "DeletedAt": "2021-03-02T08:07:06Z", "Latest": false, "Status": "INACTIVE", "MaxConcurrency": 30, "MaxSize": 90, "MinSize": 5 } }

範例 2:刪除 auto 縮放組態的特定修訂版本

下列delete-auto-scaling-configuration範例會刪除 App Runner auto 縮放設定的特定修訂版本。若要刪除特定修訂版本,請指定包含修訂編號的 ARN。

在此範例中,在此動作之前存在數個版本修訂。動作會刪除版本修訂1

aws apprunner delete-auto-scaling-configuration \ --cli-input-json file://input.json

input.json 的內容:

{ "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/1" }

輸出:

{ "AutoScalingConfiguration": { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/1/2f50e7656d7819fead0f59672e68042e", "AutoScalingConfigurationName": "high-availability", "AutoScalingConfigurationRevision": 1, "CreatedAt": "2020-11-03T00:29:17Z", "DeletedAt": "2021-03-02T08:07:06Z", "Latest": false, "Status": "INACTIVE", "MaxConcurrency": 100, "MaxSize": 50, "MinSize": 5 } }

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

AWS CLI

刪除連接

下列delete-connection範例會刪除應用程式執行器連線。成功呼叫後的連線狀態為DELETED。這是因為連接不再可用。

aws apprunner delete-connection \ --cli-input-json file://input.json

input.json 的內容:

{ "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection" }

輸出:

{ "Connection": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection", "ConnectionName": "my-github-connection", "Status": "DELETED", "CreatedAt": "2020-11-03T00:32:51Z", "ProviderType": "GITHUB" } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteConnection中的。

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

AWS CLI

若要刪除服務

下列delete-service範例會刪除應用程式執行器服務。

aws apprunner delete-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-20T19:05:25Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteService中的。

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

AWS CLI

範例 1:描述自 auto 調整資源配置的最新使用中修訂版本

下列describe-auto-scaling-configuration範例會取得 App Runner auto 縮放設定的最新使用中修訂版本的說明。要描述最新的使用中修訂版,請指定一個以模型組態名稱結尾的 ARN,而不含修訂版零組件。

在此範例中,存在兩個版本修訂。因此,描述了修訂版2(最新版本)。產生的物件會顯示出來"Latest": true

aws apprunner describe-auto-scaling-configuration \ --cli-input-json file://input.json

input.json 的內容:

{ "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability" }

輸出:

{ "AutoScalingConfiguration": { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/2/e76562f50d78042e819fead0f59672e6", "AutoScalingConfigurationName": "high-availability", "AutoScalingConfigurationRevision": 2, "CreatedAt": "2021-02-25T17:42:59Z", "Latest": true, "Status": "ACTIVE", "MaxConcurrency": 30, "MaxSize": 90, "MinSize": 5 } }

範例 2:描述 auto 縮放組態的特定修訂版本

下列describe-auto-scaling-configuration範例會取得 App Runner auto 縮放設定之特定修訂版本的說明。若要描述特定修訂版本,請指定包含修訂號碼的 ARN。

1此範例中,存在數個版本修訂,並查詢修訂版本。產生的物件會顯示出來"Latest": false

aws apprunner describe-auto-scaling-configuration \ --cli-input-json file://input.json

input.json 的內容:

{ "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/1" }

輸出:

{ "AutoScalingConfiguration": { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/1/2f50e7656d7819fead0f59672e68042e", "AutoScalingConfigurationName": "high-availability", "AutoScalingConfigurationRevision": 1, "CreatedAt": "2020-11-03T00:29:17Z", "Latest": false, "Status": "ACTIVE", "MaxConcurrency": 100, "MaxSize": 50, "MinSize": 5 } }

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

AWS CLI

取得與服務相關聯之自訂網域名稱的說明

下列describe-custom-domains範例會取得與 App Runner 服務相關聯之自訂網域名稱的說明和狀態。

aws apprunner describe-custom-domains \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "DomainName": "example.com", "EnableWWWSubdomain": true }

輸出:

{ "CustomDomains": [ { "CertificateValidationRecords": [ { "Name": "_70d3f50a94f7c72dc28784cf55db2f6b.example.com", "Status": "PENDING_VALIDATION", "Type": "CNAME", "Value": "_1270c137383c6307b6832db02504c4b0.bsgbmzkfwj.acm-validations.aws." }, { "Name": "_287870d3f50a94f7c72dc4cf55db2f6b.www.example.com", "Status": "PENDING_VALIDATION", "Type": "CNAME", "Value": "_832db01270c137383c6307b62504c4b0.mzkbsgbfwj.acm-validations.aws." } ], "DomainName": "example.com", "EnableWWWSubdomain": true, "Status": "PENDING_CERTIFICATE_DNS_VALIDATION" }, { "CertificateValidationRecords": [ { "Name": "_a94f784c70d3f507c72dc28f55db2f6b.deals.example.com", "Status": "SUCCESS", "Type": "CNAME", "Value": "_2db02504c1270c137383c6307b6834b0.bsgbmzkfwj.acm-validations.aws." } ], "DomainName": "deals.example.com", "EnableWWWSubdomain": false, "Status": "ACTIVE" } ], "DNSTarget": "psbqam834h.us-east-1.awsapprunner.com", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

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

AWS CLI

描述服務

下列describe-service範例會取得應用程式執行器服務的說明。

aws apprunner describe-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-20T19:05:25Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "RUNNING", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DescribeService中的。

下列程式碼範例會示範如何使用disassociate-custom-domain

AWS CLI

取消網域名稱與服務的關聯

下列disassociate-custom-domain範例會取消網域example.com與應用程式執行器服務的關聯性。呼叫也會取消與根網域相關聯www.example.com的子網域的關聯性。

aws apprunner disassociate-custom-domain \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "DomainName": "example.com" }

輸出:

{ "CustomDomain": { "CertificateValidationRecords": [ { "Name": "_70d3f50a94f7c72dc28784cf55db2f6b.example.com", "Status": "PENDING_VALIDATION", "Type": "CNAME", "Value": "_1270c137383c6307b6832db02504c4b0.bsgbmzkfwj.acm-validations.aws." }, { "Name": "_287870d3f50a94f7c72dc4cf55db2f6b.www.example.com", "Status": "PENDING_VALIDATION", "Type": "CNAME", "Value": "_832db01270c137383c6307b62504c4b0.mzkbsgbfwj.acm-validations.aws." } ], "DomainName": "example.com", "EnableWWWSubdomain": true, "Status": "DELETING" }, "DNSTarget": "psbqam834h.us-east-1.awsapprunner.com", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

下列程式碼範例會示範如何使用list-auto-scaling-configurations

AWS CLI

取得 App Runner auto 縮放設定的分頁清單

下列list-auto-scaling-configurations範例會列出您 AWS 帳戶中的所有 App Runner auto 縮放設定。每個回應中最多會列出五個 auto 調整配置。 AutoScalingConfigurationNameLatestOnly未指定。它們的預設會列出所有使用中模型組態的最新修訂版。

在此範例中,回應包含兩個結果,而且沒有其他結果,因此不NextToken會傳回。

aws apprunner list-auto-scaling-configurations \ --cli-input-json file://input.json

input.json 的內容:

{ "MaxResults": 5 }

輸出:

{ "AutoScalingConfigurationSummaryList": [ { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/high-availability/2/e76562f50d78042e819fead0f59672e6", "AutoScalingConfigurationName": "high-availability", "AutoScalingConfigurationRevision": 2 }, { "AutoScalingConfigurationArn": "arn:aws:apprunner:us-east-1:123456789012:autoscalingconfiguration/low-cost/1/50d7804e7656fead0f59672e62f2e819", "AutoScalingConfigurationName": "low-cost", "AutoScalingConfigurationRevision": 1 } ] }

下列程式碼範例會示範如何使用list-connections

AWS CLI

範例 1:列出所有連線

下列list-connections範例會列出 AWS 帳戶中所有應用程式執行器連線。

aws apprunner list-connections

輸出:

{ "ConnectionSummaryList": [ { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection", "ConnectionName": "my-github-connection", "Status": "AVAILABLE", "CreatedAt": "2020-11-03T00:32:51Z", "ProviderType": "GITHUB" }, { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-org-connection", "ConnectionName": "my-github-org-connection", "Status": "AVAILABLE", "CreatedAt": "2020-11-03T02:54:17Z", "ProviderType": "GITHUB" } ] }

範例 2:依名稱列出連線

下列list-connections範例會依據連線名稱列出連線。

aws apprunner list-connections \ --cli-input-json file://input.json

input.json 的內容:

{ "ConnectionName": "my-github-org-connection" }

輸出:

{ "ConnectionSummaryList": [ { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-org-connection", "ConnectionName": "my-github-org-connection", "Status": "AVAILABLE", "CreatedAt": "2020-11-03T02:54:17Z", "ProviderType": "GITHUB" } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListConnections中的。

下列程式碼範例會示範如何使用list-operations

AWS CLI

若要列出在服務上發生的作業

下列list-operations範例會列出目前為止在 App Runner 服務上發生的所有作業。在此範例中,服務是新的,而且只發生CREATE_SERVICE了類型的單一作業。

aws apprunner list-operations \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "OperationSummaryList": [ { "EndedAt": 1606156217, "Id": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "StartedAt": 1606156014, "Status": "SUCCEEDED", "TargetArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "Type": "CREATE_SERVICE", "UpdatedAt": 1606156217 } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListOperations中的。

下列程式碼範例會示範如何使用list-services

AWS CLI

獲取應用程序運行器服務的分頁列表

下列list-services範例會列出 AWS 帳戶中的所有應用程式執行器服務。每個回應中最多會列出兩個服務。此範例顯示第一個要求。響應包括兩個結果和一個令牌,可以在下一個請求中使用。當後續回應未包含 Token 時,表示已列出所有服務。

aws apprunner list-services \ --cli-input-json file://input.json

input.json 的內容:

{ "MaxResults": 2 }

輸出:

{ "NextToken": "eyJDdXN0b21lckFjY291bnRJZCI6IjI3MDIwNTQwMjg0NSIsIlNlcnZpY2VTdGF0dXNDb2RlIjoiUFJPVklTSU9OSU5HIiwiSGFzaEtleSI6IjI3MDIwNTQwMjg0NSNhYjhmOTRjZmUyOWE0NjBmYjg3NjBhZmQyZWU4NzU1NSJ9", "ServiceSummaryList": [ { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-23T12:41:37Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "Status": "RUNNING" }, { "CreatedAt": "2020-11-06T23:15:30Z", "UpdatedAt": "2020-11-23T13:21:22Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/golang-container-app/ab8f94cfe29a460fb8760afd2ee87555", "ServiceId": "ab8f94cfe29a460fb8760afd2ee87555", "ServiceName": "golang-container-app", "ServiceUrl": "e2m8rrrx33.us-east-1.awsapprunner.com", "Status": "RUNNING" } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListServices中的。

下列程式碼範例會示範如何使用list-tags-for-resource

AWS CLI

列出與應用程式執行器服務相關聯的標籤

下列list-tags-for-resource範例會列出所有與應用程式執行器服務相關聯的標籤。

aws apprunner list-tags-for-resource \ --cli-input-json file://input.json

input.json 的內容:

{ "ResourceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "Tags": [ { "Key": "Department", "Value": "Retail" }, { "Key": "CustomerId", "Value": "56439872357912" } ] }

下列程式碼範例會示範如何使用pause-service

AWS CLI

若要暫停服務

下列pause-service範例會暫停應用程式執行器服務。

aws apprunner pause-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-23T12:41:37Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考PauseService中的。

下列程式碼範例會示範如何使用resume-service

AWS CLI

若要繼續服務

下列resume-service範例會繼續執行應用程式執行器服務。

aws apprunner resume-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-23T12:41:37Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "3 GB" } } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ResumeService中的。

下列程式碼範例會示範如何使用start-deployment

AWS CLI

啟動手動部署

下列start-deployment範例會執行手動部署至 App Runner 服務。

aws apprunner start-deployment \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa" }

輸出:

{ "OperationId": "853a7d5b-fc9f-4730-831b-fd8037ab832a" }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考StartDeployment中的。

下列程式碼範例會示範如何使用tag-resource

AWS CLI

若要將標籤新增至應用程式執行器服務

下列tag-resource範例會將兩個標籤新增至應用程式執行器服務。

aws apprunner tag-resource \ --cli-input-json file://input.json

input.json 的內容:

{ "ResourceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "Tags": [ { "Key": "Department", "Value": "Retail" }, { "Key": "CustomerId", "Value": "56439872357912" } ] }

此命令不會產生輸出。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考TagResource中的。

下列程式碼範例會示範如何使用untag-resource

AWS CLI

從應用程式執行器服務移除標籤

下列untag-resource範例會從應用程式執行器服務移除兩個標籤。

aws apprunner untag-resource \ --cli-input-json file://input.json

input.json 的內容:

{ "ResourceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "TagKeys": [ "Department", "CustomerId" ] }

此命令不會產生輸出。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考UntagResource中的。

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

AWS CLI

更新記憶體大小

下列update-service範例會將應用程式執行器服務的執行個體 (縮放單位) 的記憶體大小更新為 2048 MiB。

當呼叫成功時,應用程式執行器會啟動非同步更新程序。呼叫傳回的Service結構會反映此呼叫所套用的新記憶體值。

aws apprunner update-service \ --cli-input-json file://input.json

input.json 的內容:

{ "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "InstanceConfiguration": { "Memory": "4 GB" } }

輸出:

{ "OperationId": "17fe9f55-7e91-4097-b243-fcabbb69a4cf", "Service": { "CreatedAt": "2020-11-20T19:05:25Z", "UpdatedAt": "2020-11-23T12:41:37Z", "ServiceArn": "arn:aws:apprunner:us-east-1:123456789012:service/python-app/8fe1e10304f84fd2b0df550fe98a71fa", "ServiceId": "8fe1e10304f84fd2b0df550fe98a71fa", "ServiceName": "python-app", "ServiceUrl": "psbqam834h.us-east-1.awsapprunner.com", "SourceConfiguration": { "AuthenticationConfiguration": { "ConnectionArn": "arn:aws:apprunner:us-east-1:123456789012:connection/my-github-connection/e7656250f67242d7819feade6800f59e" }, "AutoDeploymentsEnabled": true, "CodeRepository": { "CodeConfiguration": { "CodeConfigurationValues": { "BuildCommand": "pip install -r requirements.txt", "Port": "8080", "Runtime": "PYTHON_3", "RuntimeEnvironmentVariables": [ { "NAME": "Jane" } ], "StartCommand": "python server.py" }, "ConfigurationSource": "Api" }, "RepositoryUrl": "https://github.com/my-account/python-hello", "SourceCodeVersion": { "Type": "BRANCH", "Value": "main" } } }, "Status": "OPERATION_IN_PROGRESS", "InstanceConfiguration": { "CPU": "1 vCPU", "Memory": "4 GB" } } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考UpdateService中的。