文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的應用程式執行器範例 AWS CLI
下列程式碼範例示範如何搭配 AWS Command Line Interface App Runner 使用 來執行動作和實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
主題
動作
下列程式碼範例示範如何使用 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" }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 AssociateCustomDomain
。
-
下列程式碼範例示範如何使用 create-auto-scaling-configuration
。
- AWS CLI
-
建立高可用性自動擴展組態
下列
create-auto-scaling-configuration
範例會建立自動擴展組態,並將MinSize
設定為 5,以針對高可用性進行最佳化。透過此組態,App Runner 會嘗試將服務執行個體分散到最多可用區域,最多 5 個,視 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 } }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateAutoScalingConfiguration
。
-
下列程式碼範例示範如何使用 create-connection
。
- AWS CLI
-
建立 a GitHub 連線
下列
create-connection
範例會建立與 private GitHub 程式碼儲存庫的連線。成功呼叫後的連線狀態為PENDING_HANDSHAKE
。這是因為與提供者的身分驗證交握尚未發生。使用 App Runner 主控台完成交握。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" } }
如需詳細資訊,請參閱應用程式執行器開發人員指南中的管理應用程式執行器連線。 AWS
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateConnection
。
-
下列程式碼範例示範如何使用 create-service
。
- AWS CLI
-
範例 1:建立原始程式碼儲存庫服務
下列
create-service
範例會根據 Python 原始程式碼儲存庫建立 App Runner 服務。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 原始程式碼儲存庫建立 App Runner 服務。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
範例會根據儲存在 Elastic Container Registry (ECR) 中的映像建立 App Runner 服務。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:刪除自動擴展組態的最新作用中修訂
下列
delete-auto-scaling-configuration
範例會刪除 App Runner 自動擴展組態的最新作用中修訂。若要刪除最新的作用中修訂,請指定以組態名稱結尾的 Amazon Resource Name (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:刪除自動擴展組態的特定修訂
下列
delete-auto-scaling-configuration
範例會刪除 App Runner 自動擴展組態的特定修訂。若要刪除特定修訂,請指定包含修訂編號的 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 } }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteAutoScalingConfiguration
。
-
下列程式碼範例示範如何使用 delete-connection
。
- AWS CLI
-
若要刪除連線
下列
delete-connection
範例會刪除 App Runner 連線。成功呼叫後的連線狀態為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
範例會刪除 App Runner 服務。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:描述自動擴展組態的最新作用中修訂
下列
describe-auto-scaling-configuration
範例會取得 App Runner 自動擴展組態的最新作用中修訂的說明。若要描述最新的作用中修訂,請指定以組態名稱結尾的 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:描述自動擴展組態的特定修訂
下列
describe-auto-scaling-configuration
範例會取得 App Runner 自動擴展組態特定修訂的說明。若要描述特定修訂,請指定包含修訂編號的 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 } }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeAutoScalingConfiguration
。
-
下列程式碼範例示範如何使用 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" }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeCustomDomains
。
-
下列程式碼範例示範如何使用 describe-service
。
- AWS CLI
-
描述 服務
下列
describe-service
範例會取得 App Runner 服務的描述。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
與 App Runner 服務的關聯。呼叫也會取消與根網域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" }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DisassociateCustomDomain
。
-
下列程式碼範例示範如何使用 list-auto-scaling-configurations
。
- AWS CLI
-
若要取得 App Runner 自動擴展組態的分頁清單
下列
list-auto-scaling-configurations
範例列出您 AWS 帳戶中的所有 App Runner 自動擴展組態。每個回應中最多列出五個自動擴展組態。LatestOnly
AutoScalingConfigurationName
且未指定。其預設值會導致列出所有作用中組態的最新版本。在此範例中,回應包含兩個結果,沒有其他結果,因此不會
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 } ] }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListAutoScalingConfigurations
。
-
下列程式碼範例示範如何使用 list-connections
。
- AWS CLI
-
範例 1:列出所有連線
下列
list-connections
範例會列出 AWS 帳戶中的所有 App Runner 連線。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
-
若要取得 App Runner 服務的分頁清單
下列
list-services
範例列出 AWS 帳戶中的所有 App Runner 服務。每個回應中最多列出兩個 服務。此範例顯示第一個請求。回應包含兩個結果和可用於下一個請求的權杖。當後續回應不包含權杖時,所有 服務都已列出。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
-
列出與 App Runner 服務相關聯的標籤
下列
list-tags-for-resource
範例會列出與 App Runner 服務相關聯的所有標籤。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" } ] }
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListTagsForResource
。
-
下列程式碼範例示範如何使用 pause-service
。
- AWS CLI
-
暫停服務
下列
pause-service
範例會暫停 App Runner 服務。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
範例會繼續 App Runner 服務。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
-
將標籤新增至 App Runner 服務
下列
tag-resource
範例會將兩個標籤新增至 App Runner 服務。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
-
從 App Runner 服務移除標籤
下列
untag-resource
範例會從 App Runner 服務中移除兩個標籤。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
範例會將 App Runner 服務的執行個體 (擴展單位) 記憶體大小更新為 2048 MiB。當呼叫成功時,App Runner 會啟動非同步更新程序。呼叫傳回的
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
。
-