AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
AWS Proton 使用示例 AWS CLI
以下代码示例向您展示了如何使用with来执行操作和实现常见场景 AWS Proton。 AWS Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 cancel-service-instance-deployment
。
- AWS CLI
-
取消服务实例部署
以下
cancel-service-instance-deployment
示例取消了服务实例部署。aws proton cancel-service-instance-deployment \ --service-instance-name
"instance-one"
\ --service-name"simple-svc"
输出:
{ "serviceInstance": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one", "createdAt": "2021-04-02T21:29:59.962000+00:00", "deploymentStatus": "CANCELLING", "environmentName": "simple-env", "lastDeploymentAttemptedAt": "2021-04-02T21:45:15.406000+00:00", "lastDeploymentSucceededAt": "2021-04-02T21:38:00.823000+00:00", "name": "instance-one", "serviceName": "simple-svc", "spec": "proton: ServiceSpec\npipeline:\n my_sample_pipeline_optional_input: abc\n my_sample_pipeline_required_input: '123'\ninstances:\n- name: my-instance\n environment: MySimpleEnv\n spec:\n my_sample_service_instance_optional_input: def\n my_sample_service_instance_required_input: '456'\n- name: my-other-instance\n environment: MySimpleEnv\n spec:\n my_sample_service_instance_required_input: '789'\n", "templateMajorVersion": "1", "templateMinorVersion": "1", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的 “更新服务实例” 或《Proton 用户指南》中的 “更新服务实例”。 AWS
-
有关API详细信息,请参阅 “CancelServiceInstanceDeployment AWS CLI
命令参考”。
-
以下代码示例演示如何使用 cancel-service-pipeline-deployment
。
- AWS CLI
-
取消服务管道部署
以下
cancel-service-pipeline-deployment
示例取消了服务管道部署。aws proton cancel-service-pipeline-deployment \ --service-name
"simple-svc"
输出:
{ "pipeline": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/pipeline", "createdAt": "2021-04-02T21:29:59.962000+00:00", "deploymentStatus": "CANCELLING", "lastDeploymentAttemptedAt": "2021-04-02T22:02:45.095000+00:00", "lastDeploymentSucceededAt": "2021-04-02T21:39:28.991000+00:00", "templateMajorVersion": "1", "templateMinorVersion": "1", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的 “更新服务管道” 或《Proton 用户指南》中的 “更新服务管道”。 AWS
-
有关API详细信息,请参阅 “CancelServicePipelineDeployment AWS CLI
命令参考”。
-
以下代码示例演示如何使用 create-service
。
- AWS CLI
-
创建服务
以下
create-service
示例创建了一个带有服务管道的服务。aws proton create-service \ --name
"MySimpleService"
\ --template-name"fargate-service"
\ --template-major-version"1"
\ --branch-name"mainline"
\ --repository-connection-arn"arn:aws:codestar-connections:region-id:account-id:connection/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
\ --repository-id"myorg/myapp"
\ --specfile://spec.yaml
spec.yaml
的内容:proton: ServiceSpec pipeline: my_sample_pipeline_required_input: "hello" my_sample_pipeline_optional_input: "bye" instances: - name: "acme-network-dev" environment: "ENV_NAME" spec: my_sample_service_instance_required_input: "hi" my_sample_service_instance_optional_input: "ho"
输出:
{ "service": { "arn": "arn:aws:proton:region-id:123456789012:service/MySimpleService", "createdAt": "2020-11-18T19:50:27.460000+00:00", "lastModifiedAt": "2020-11-18T19:50:27.460000+00:00", "name": "MySimpleService", "repositoryConnectionArn": "arn:aws:codestar-connections:region-id:123456789012connection/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "repositoryId": "myorg/myapp", "status": "CREATE_IN_PROGRESS", "templateName": "fargate-service" } }
有关更多信息,请参阅《 AWS Proton 管理员指南》中的创建服务和《Proton 用户指南》中的创建服务。 AWS
-
有关API详细信息,请参阅 “CreateService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 delete-service
。
- AWS CLI
-
删除服务
以下
delete-service
示例删除服务。aws proton delete-service \ --name
"simple-svc"
输出:
{ "service": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc", "branchName": "mainline", "createdAt": "2020-11-28T22:40:50.512000+00:00", "description": "Edit by updating description", "lastModifiedAt": "2020-11-29T00:30:39.248000+00:00", "name": "simple-svc", "repositoryConnectionArn": "arn:aws:codestar-connections:region-id:123456789012:connection/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "repositoryId": "myorg/myapp", "status": "DELETE_IN_PROGRESS", "templateName": "fargate-service" } }
有关更多信息,请参阅《 AWS Proton 管理员指南》中的删除服务。
-
有关API详细信息,请参阅 “DeleteService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 get-service-instance
。
- AWS CLI
-
获取服务实例详细信息
以下
get-service-instance
示例获取服务实例的详细数据。aws proton get-service-instance \ --name
"instance-one"
\ --service-name"simple-svc"
输出:
{ "serviceInstance": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one", "createdAt": "2020-11-28T22:40:50.512000+00:00", "deploymentStatus": "SUCCEEDED", "environmentName": "simple-env", "lastDeploymentAttemptedAt": "2020-11-28T22:40:50.512000+00:00", "lastDeploymentSucceededAt": "2020-11-28T22:40:50.512000+00:00", "name": "instance-one", "serviceName": "simple-svc", "spec": "proton: ServiceSpec\npipeline:\n my_sample_pipeline_optional_input: hello world\n my_sample_pipeline_required_input: pipeline up\ninstances:\n- name: instance-one\n environment: my-simple-env\n spec:\n my_sample_service_instance_optional_input: Ola\n my_sample_service_instance_required_input: Ciao\n", "templateMajorVersion": "1", "templateMinorVersion": "0", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的查看服务数据或《Proton 用户指南》中的查看服务数据。 AWS
-
有关API详细信息,请参阅 “GetServiceInstance AWS CLI
命令参考”。
-
以下代码示例演示如何使用 get-service
。
- AWS CLI
-
获取服务详情
以下
get-service
示例获取服务的详细数据。aws proton get-service \ --name
"simple-svc"
输出:
{ "service": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc", "branchName": "mainline", "createdAt": "2020-11-28T22:40:50.512000+00:00", "lastModifiedAt": "2020-11-28T22:44:51.207000+00:00", "name": "simple-svc", "pipeline": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/pipeline/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "createdAt": "2020-11-28T22:40:50.512000+00:00", "deploymentStatus": "SUCCEEDED", "lastDeploymentAttemptedAt": "2020-11-28T22:40:50.512000+00:00", "lastDeploymentSucceededAt": "2020-11-28T22:40:50.512000+00:00", "spec": "proton: ServiceSpec\npipeline:\n my_sample_pipeline_required_input: hello\n my_sample_pipeline_optional_input: bye\ninstances:\n- name: instance-svc-simple\n environment: my-simple-env\n spec:\n my_sample_service_instance_required_input: hi\n my_sample_service_instance_optional_input: ho\n", "templateMajorVersion": "1", "templateMinorVersion": "1", "templateName": "svc-simple" }, "repositoryConnectionArn": "arn:aws:codestar-connections:region-id:123456789012:connection/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "repositoryId": "myorg/myapp", "spec": "proton: ServiceSpec\npipeline:\n my_sample_pipeline_required_input: hello\n my_sample_pipeline_optional_input: bye\ninstances:\n- name: instance-svc-simple\n environment: my-simple-env\n spec:\n my_sample_service_instance_required_input: hi\n my_sample_service_instance_optional_input: ho\n", "status": "ACTIVE", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的查看服务数据或《Proton 用户指南》中的查看服务数据。 AWS
-
有关API详细信息,请参阅 “GetService AWS CLI
命令参考”。
-
以下代码示例演示如何使用 list-service-instances
。
- AWS CLI
-
示例 1:列出所有服务实例
以下
list-service-instances
示例列出了服务实例。aws proton list-service-instances
输出:
{ "serviceInstances": [ { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one", "createdAt": "2020-11-28T22:40:50.512000+00:00", "deploymentStatus": "SUCCEEDED", "environmentArn": "arn:aws:proton:region-id:123456789012:environment/simple-env", "lastDeploymentAttemptedAt": "2020-11-28T22:40:50.512000+00:00", "lastDeploymentSucceededAt": "2020-11-28T22:40:50.512000+00:00", "name": "instance-one", "serviceName": "simple-svc", "templateMajorVersion": "1", "templateMinorVersion": "0", "templateName": "fargate-service" } ] }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的查看服务实例数据或《Proton 用户指南》中的查看服务实例数据。 AWS
示例 2:列出指定的服务实例
以下
get-service-instance
示例获取了一个服务实例。aws proton get-service-instance \ --name
"instance-one"
\ --service-name"simple-svc"
输出:
{ "serviceInstance": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one", "createdAt": "2020-11-28T22:40:50.512000+00:00", "deploymentStatus": "SUCCEEDED", "environmentName": "simple-env", "lastDeploymentAttemptedAt": "2020-11-28T22:40:50.512000+00:00", "lastDeploymentSucceededAt": "2020-11-28T22:40:50.512000+00:00", "name": "instance-one", "serviceName": "simple-svc", "spec": "proton: ServiceSpec\npipeline:\n my_sample_pipeline_optional_input: hello world\n my_sample_pipeline_required_input: pipeline up\ninstances:\n- name: instance-one\n environment: my-simple-env\n spec:\n my_sample_service_instance_optional_input: Ola\n my_sample_service_instance_required_input: Ciao\n", "templateMajorVersion": "1", "templateMinorVersion": "0", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的查看服务实例数据或《Proton 用户指南》中的查看服务实例数据。 AWS
-
有关API详细信息,请参阅 “ListServiceInstances AWS CLI
命令参考”。
-
以下代码示例演示如何使用 update-service-instance
。
- AWS CLI
-
将服务实例更新到新的次要版本
以下
update-service-instance
示例将服务实例更新为其服务模板的新次要版本,该模板添加了一个名为 “my-other-instance” 的新实例,其中包含新的必填输入。aws proton update-service-instance \ --service-name
"simple-svc"
\ --spec"file://service-spec.yaml
" \ --template-major-version"1"
\ --template-minor-version"1"
\ --deployment-type"MINOR_VERSION"
\ --name"instance-one"
service-spec.yaml
的内容:proton: ServiceSpec pipeline: my_sample_pipeline_optional_input: "abc" my_sample_pipeline_required_input: "123" instances: - name: "instance-one" environment: "simple-env" spec: my_sample_service_instance_optional_input: "def" my_sample_service_instance_required_input: "456" - name: "my-other-instance" environment: "simple-env" spec: my_sample_service_instance_required_input: "789"
输出:
{ "serviceInstance": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/service-instance/instance-one", "createdAt": "2021-04-02T21:29:59.962000+00:00", "deploymentStatus": "IN_PROGRESS", "environmentName": "arn:aws:proton:region-id:123456789012:environment/simple-env", "lastDeploymentAttemptedAt": "2021-04-02T21:38:00.823000+00:00", "lastDeploymentSucceededAt": "2021-04-02T21:29:59.962000+00:00", "name": "instance-one", "serviceName": "simple-svc", "templateMajorVersion": "1", "templateMinorVersion": "0", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的 “更新服务实例” 或《Proton 用户指南》中的 “更新服务实例”。 AWS
-
有关API详细信息,请参阅 “UpdateServiceInstance AWS CLI
命令参考”。
-
以下代码示例演示如何使用 update-service-pipeline
。
- AWS CLI
-
更新服务管道
以下
update-service-pipeline
示例将服务管道更新为其服务模板的新次要版本。aws proton update-service-pipeline \ --service-name
"simple-svc"
\ --spec"file://service-spec.yaml"
\ --template-major-version"1"
\ --template-minor-version"1"
\ --deployment-type"MINOR_VERSION"
输出:
{ "pipeline": { "arn": "arn:aws:proton:region-id:123456789012:service/simple-svc/pipeline/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "createdAt": "2021-04-02T21:29:59.962000+00:00", "deploymentStatus": "IN_PROGRESS", "lastDeploymentAttemptedAt": "2021-04-02T21:39:28.991000+00:00", "lastDeploymentSucceededAt": "2021-04-02T21:29:59.962000+00:00", "spec": "proton: ServiceSpec\n\npipeline:\n my_sample_pipeline_optional_input: \"abc\"\n my_sample_pipeline_required_input: \"123\"\n\ninstances:\n - name: \"my-instance\"\n environment: \"MySimpleEnv\"\n spec:\n my_sample_service_instance_optional_input: \"def\"\n my_sample_service_instance_required_input: \"456\"\n - name: \"my-other-instance\"\n environment: \"MySimpleEnv\"\n spec:\n my_sample_service_instance_required_input: \"789\"\n", "templateMajorVersion": "1", "templateMinorVersion": "0", "templateName": "svc-simple" } }
有关更多信息,请参阅《Pro AWS ton 管理员指南》中的 “更新服务管道” 或《Proton 用户指南》中的 “更新服务管道”。 AWS
-
有关API详细信息,请参阅 “UpdateServicePipeline AWS CLI
命令参考”。
-
以下代码示例演示如何使用 update-service
。
- AWS CLI
-
更新服务
以下
update-service
示例编辑服务描述。aws proton update-service \ --name
"MySimpleService"
\ --description"Edit by updating description"
输出:
{ "service": { "arn": "arn:aws:proton:region-id:123456789012:service/MySimpleService", "branchName": "mainline", "createdAt": "2021-03-12T22:39:42.318000+00:00", "description": "Edit by updating description", "lastModifiedAt": "2021-03-12T22:44:21.975000+00:00", "name": "MySimpleService", "repositoryConnectionArn": "arn:aws:codestar-connections:region-id:123456789012:connection/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "repositoryId": "myorg/myapp", "status": "ACTIVE", "templateName": "fargate-service" } }
有关更多信息,请参阅《 AWS Proton 管理员指南》中的编辑服务或《Proton 用户指南》中的编辑服务。 AWS
-
有关API详细信息,请参阅 “UpdateService AWS CLI
命令参考”。
-