AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
App Runner 示例使用 AWS CLI
以下代码示例向您展示了如何使用 with App Runner 来执行操作和实现常见场景。 AWS Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 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详细信息,请参阅 “AssociateCustomDomain AWS CLI
命令参考”。
-
以下代码示例演示如何使用 create-auto-scaling-configuration
。
- AWS CLI
-
创建高可用性 auto Scaling 配置
以下
create-auto-scaling-configuration
示例通过将设置MinSize
为 5 来创建针对高可用性进行优化的 auto Scaling 配置。使用此配置,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 } }
-
有关API详细信息,请参阅 “CreateAutoScalingConfiguration AWS CLI
命令参考”。
-
以下代码示例演示如何使用 create-connection
。
- AWS CLI
-
创建 GitHub 连接
以下
create-connection
示例创建了与私有 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" } }
有关更多信息,请参阅《App Runner 开发者指南》中的管理AWS App Runner 连接。
-
有关API详细信息,请参阅 “CreateConnection AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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
示例基于存储在弹性容器注册表 (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详细信息,请参阅 “CreateService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 delete-auto-scaling-configuration
。
- AWS CLI
-
示例 1:删除 auto Scaling 配置的最新活动版本
以下
delete-auto-scaling-configuration
示例删除了 App Runner 自动缩放配置的最新活动版本。要删除最新的有效修订版,请指定一个以配置名称结尾的 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 Scaling 配置的特定修订版
以下
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详细信息,请参阅 “DeleteAutoScalingConfiguration AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “DeleteConnection AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “DeleteService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 describe-auto-scaling-configuration
。
- AWS CLI
-
示例 1:描述 auto Scaling 配置的最新活动版本
以下
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:描述 auto Scaling 配置的特定版本
以下
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详细信息,请参阅 “DescribeAutoScalingConfiguration AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “DescribeCustomDomains AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “DescribeService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “DisassociateCustomDomain AWS CLI
命令参考”。
-
以下代码示例演示如何使用 list-auto-scaling-configurations
。
- AWS CLI
-
要获取 App Runner 自动缩放配置的分页列表
以下
list-auto-scaling-configurations
示例列出了您 AWS 账户中的所有 App Runner 自动缩放配置。每个响应中最多列出五个 auto Scaling 配置。AutoScalingConfigurationName
并且LatestOnly
未指定。它们的默认值会导致列出所有活动配置的最新版本。在此示例中,响应包含两个结果,但没有其他结果,因此
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详细信息,请参阅 “ListAutoScalingConfigurations AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “ListConnections AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “ListOperations AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “ListServices AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “ListTagsForResource AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “PauseService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “ResumeService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “StartDeployment AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “TagResource AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “UntagResource AWS CLI
命令参考”。
-
以下代码示例演示如何使用 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详细信息,请参阅 “UpdateService AWS CLI
命令参考”。
-