App Runner 示例使用 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

App Runner 示例使用 Amazon CLI

以下代码示例向您展示了如何使用 with App Runner 来执行操作和实现常见场景。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 associate-custom-domain

Amazon 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

Amazon CLI

创建高可用性 auto Scaling 配置

以下create-auto-scaling-configuration示例通过将设置MinSize为 5 来创建针对高可用性进行优化的 auto Scaling 配置。使用此配置,App Runner 会尝试将您的服务实例分布在尽可能多的可用区(最多五个可用区),具体视 Amazon 区域而定。

该调用将返回一个其他设置为默认值的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

Amazon 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 开发者指南》中的管理Amazon App Runner 连接

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateConnection中的。

以下代码示例演示如何使用 create-service

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考CreateService中的。

以下代码示例演示如何使用 delete-auto-scaling-configuration

Amazon 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 } }

以下代码示例演示如何使用 delete-connection

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考DeleteConnection中的。

以下代码示例演示如何使用 delete-service

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考DeleteService中的。

以下代码示例演示如何使用 describe-auto-scaling-configuration

Amazon 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 } }

以下代码示例演示如何使用 describe-custom-domains

Amazon 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

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考DescribeService中的。

以下代码示例演示如何使用 disassociate-custom-domain

Amazon 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" }

以下代码示例演示如何使用 list-auto-scaling-configurations

Amazon CLI

要获取 App Runner 自动缩放配置的分页列表

以下list-auto-scaling-configurations示例列出了您 Amazon 账户中的所有 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 } ] }

以下代码示例演示如何使用 list-connections

Amazon CLI

示例 1:列出所有连接

以下list-connections示例列出了该 Amazon 账户中的所有 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 的详细信息,请参阅Amazon CLI 命令参考ListConnections中的。

以下代码示例演示如何使用 list-operations

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考ListOperations中的。

以下代码示例演示如何使用 list-services

Amazon CLI

获取 App Runner 服务的分页列表

以下list-services示例列出了该 Amazon 账户中的所有 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 的详细信息,请参阅Amazon CLI 命令参考ListServices中的。

以下代码示例演示如何使用 list-tags-for-resource

Amazon 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" } ] }

以下代码示例演示如何使用 pause-service

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考PauseService中的。

以下代码示例演示如何使用 resume-service

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考ResumeService中的。

以下代码示例演示如何使用 start-deployment

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考StartDeployment中的。

以下代码示例演示如何使用 tag-resource

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考TagResource中的。

以下代码示例演示如何使用 untag-resource

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考UntagResource中的。

以下代码示例演示如何使用 update-service

Amazon 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 的详细信息,请参阅Amazon CLI 命令参考UpdateService中的。