CodeDeploy 使用示例 AWS CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

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

CodeDeploy 使用示例 AWS CLI

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

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

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

主题

操作

以下代码示例演示如何使用 add-tags-to-on-premises-instances

AWS CLI

向本地实例添加标签

以下add-tags-to-on-premises-instances示例将同一本地实例标签 AWS CodeDeploy 中的两个本地实例关联到两个本地实例。它不会向注册本地实例 AWS CodeDeploy。

aws deploy add-tags-to-on-premises-instances \ --instance-names AssetTag12010298EX AssetTag23121309EX \ --tags Key=Name,Value=CodeDeployDemo-OnPrem

此命令不生成任何输出。

以下代码示例演示如何使用 batch-get-application-revisions

AWS CLI

检索有关应用程序修订的信息

以下batch-get-application-revisions示例检索存储在存储 GitHub 库中的有关指定修订的信息。

aws deploy batch-get-application-revisions \ --application-name my-codedeploy-application \ --revisions "[{\"gitHubLocation\": {\"commitId\": \"fa85936EXAMPLEa31736c051f10d77297EXAMPLE\",\"repository\": \"my-github-token/my-repository\"},\"revisionType\": \"GitHub\"}]"

输出:

{ "revisions": [ { "genericRevisionInfo": { "description": "Application revision registered by Deployment ID: d-A1B2C3111", "lastUsedTime": 1556912355.884, "registerTime": 1556912355.884, "firstUsedTime": 1556912355.884, "deploymentGroups": [] }, "revisionLocation": { "revisionType": "GitHub", "gitHubLocation": { "commitId": "fa85936EXAMPLEa31736c051f10d77297EXAMPLE", "repository": "my-github-token/my-repository" } } } ], "applicationName": "my-codedeploy-application", "errorMessage": "" }

有关更多信息,请参阅 “AWS CodeDeploy API参考BatchGetApplicationRevisions中的。

以下代码示例演示如何使用 batch-get-applications

AWS CLI

获取有关多个应用程序的信息

以下batch-get-applications示例显示了与用户 AWS 账户关联的多个应用程序的相关信息。

aws deploy batch-get-applications --application-names WordPress_App MyOther_App

输出:

{ "applicationsInfo": [ { "applicationName": "WordPress_App", "applicationId": "d9dd6993-f171-44fa-a811-211e4EXAMPLE", "createTime": 1407878168.078, "linkedToGitHub": false }, { "applicationName": "MyOther_App", "applicationId": "8ca57519-31da-42b2-9194-8bb16EXAMPLE", "createTime": 1407453571.63, "linkedToGitHub": false } ] }

以下代码示例演示如何使用 batch-get-deployment-groups

AWS CLI

检索有关一个或多个部署组的信息

以下batch-get-deployment-groups示例检索与指定 CodeDeploy 应用程序关联的两个部署组的相关信息。

aws deploy batch-get-deployment-groups \ --application-name my-codedeploy-application \ --deployment-group-names "[\"my-deployment-group-1\",\"my-deployment-group-2\"]"

输出:

{ "deploymentGroupsInfo": [ { "deploymentStyle": { "deploymentOption": "WITHOUT_TRAFFIC_CONTROL", "deploymentType": "IN_PLACE" }, "autoRollbackConfiguration": { "enabled": false }, "onPremisesTagSet": { "onPremisesTagSetList": [] }, "serviceRoleArn": "arn:aws:iam::123456789012:role/CodeDeployServiceRole", "lastAttemptedDeployment": { "endTime": 1556912366.415, "status": "Failed", "createTime": 1556912355.884, "deploymentId": "d-A1B2C3111" }, "autoScalingGroups": [], "deploymentGroupName": "my-deployment-group-1", "ec2TagSet": { "ec2TagSetList": [ [ { "Type": "KEY_AND_VALUE", "Value": "my-EC2-instance", "Key": "Name" } ] ] }, "deploymentGroupId": "a1b2c3d4-5678-90ab-cdef-11111example", "triggerConfigurations": [], "applicationName": "my-codedeploy-application", "computePlatform": "Server", "deploymentConfigName": "CodeDeployDefault.AllAtOnce" }, { "deploymentStyle": { "deploymentOption": "WITHOUT_TRAFFIC_CONTROL", "deploymentType": "IN_PLACE" }, "autoRollbackConfiguration": { "enabled": false }, "onPremisesTagSet": { "onPremisesTagSetList": [] }, "serviceRoleArn": "arn:aws:iam::123456789012:role/CodeDeployServiceRole", "autoScalingGroups": [], "deploymentGroupName": "my-deployment-group-2", "ec2TagSet": { "ec2TagSetList": [ [ { "Type": "KEY_AND_VALUE", "Value": "my-EC2-instance", "Key": "Name" } ] ] }, "deploymentGroupId": "a1b2c3d4-5678-90ab-cdef-22222example", "triggerConfigurations": [], "applicationName": "my-codedeploy-application", "computePlatform": "Server", "deploymentConfigName": "CodeDeployDefault.AllAtOnce" } ], "errorMessage": "" }

有关更多信息,请参阅 “AWS CodeDeploy API参考BatchGetDeploymentGroups中的。

以下代码示例演示如何使用 batch-get-deployment-targets

AWS CLI

检索与部署关联的目标

以下batch-get-deployment-targets示例返回与指定部署关联的其中一个目标的相关信息。

aws deploy batch-get-deployment-targets \ --deployment-id "d-1A2B3C4D5" \ --target-ids "i-01a2b3c4d5e6f1111"

输出:

{ "deploymentTargets": [ { "deploymentTargetType": "InstanceTarget", "instanceTarget": { "lifecycleEvents": [ { "startTime": 1556918592.162, "lifecycleEventName": "ApplicationStop", "status": "Succeeded", "endTime": 1556918592.247, "diagnostics": { "scriptName": "", "errorCode": "Success", "logTail": "", "message": "Succeeded" } }, { "startTime": 1556918593.193, "lifecycleEventName": "DownloadBundle", "status": "Succeeded", "endTime": 1556918593.981, "diagnostics": { "scriptName": "", "errorCode": "Success", "logTail": "", "message": "Succeeded" } }, { "startTime": 1556918594.805, "lifecycleEventName": "BeforeInstall", "status": "Succeeded", "endTime": 1556918681.807, "diagnostics": { "scriptName": "", "errorCode": "Success", "logTail": "", "message": "Succeeded" } } ], "targetArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-01a2b3c4d5e6f1111", "deploymentId": "d-1A2B3C4D5", "lastUpdatedAt": 1556918687.504, "targetId": "i-01a2b3c4d5e6f1111", "status": "Succeeded" } } ] }

有关更多信息,请参阅 “AWS CodeDeploy API参考BatchGetDeploymentTargets中的。

以下代码示例演示如何使用 batch-get-deployments

AWS CLI

获取有关多个部署的信息

以下batch-get-deployments示例显示了与用户 AWS 账户关联的多个部署的相关信息。

aws deploy batch-get-deployments --deployment-ids d-A1B2C3111 d-A1B2C3222

输出:

{ "deploymentsInfo": [ { "applicationName": "WordPress_App", "status": "Failed", "deploymentOverview": { "Failed": 0, "InProgress": 0, "Skipped": 0, "Succeeded": 1, "Pending": 0 }, "deploymentConfigName": "CodeDeployDefault.OneAtATime", "creator": "user", "deploymentGroupName": "WordPress_DG", "revision": { "revisionType": "S3", "s3Location": { "bundleType": "zip", "version": "uTecLusEXAMPLEFXtfUcyfV8bEXAMPLE", "bucket": "CodeDeployDemoBucket", "key": "WordPressApp.zip" } }, "deploymentId": "d-A1B2C3111", "createTime": 1408480721.9, "completeTime": 1408480741.822 }, { "applicationName": "MyOther_App", "status": "Failed", "deploymentOverview": { "Failed": 1, "InProgress": 0, "Skipped": 0, "Succeeded": 0, "Pending": 0 }, "deploymentConfigName": "CodeDeployDefault.OneAtATime", "creator": "user", "errorInformation": { "message": "Deployment failed: Constraint default violated: No hosts succeeded.", "code": "HEALTH_CONSTRAINTS" }, "deploymentGroupName": "MyOther_DG", "revision": { "revisionType": "S3", "s3Location": { "bundleType": "zip", "eTag": "\"dd56cfdEXAMPLE8e768f9d77fEXAMPLE\"", "bucket": "CodeDeployDemoBucket", "key": "MyOtherApp.zip" } }, "deploymentId": "d-A1B2C3222", "createTime": 1409764576.589, "completeTime": 1409764596.101 } ] }

以下代码示例演示如何使用 batch-get-on-premises-instances

AWS CLI

获取有关一个或多个本地实例的信息

以下batch-get-on-premises-instances示例获取有关两个本地实例的信息。

aws deploy batch-get-on-premises-instances --instance-names AssetTag12010298EX AssetTag23121309EX

输出:

{ "instanceInfos": [ { "iamUserArn": "arn:aws:iam::123456789012:user/AWS/CodeDeploy/AssetTag12010298EX", "tags": [ { "Value": "CodeDeployDemo-OnPrem", "Key": "Name" } ], "instanceName": "AssetTag12010298EX", "registerTime": 1425579465.228, "instanceArn": "arn:aws:codedeploy:us-west-2:123456789012:instance/AssetTag12010298EX_4IwLNI2Alh" }, { "iamUserArn": "arn:aws:iam::123456789012:user/AWS/CodeDeploy/AssetTag23121309EX", "tags": [ { "Value": "CodeDeployDemo-OnPrem", "Key": "Name" } ], "instanceName": "AssetTag23121309EX", "registerTime": 1425595585.988, "instanceArn": "arn:aws:codedeploy:us-west-2:80398EXAMPLE:instance/AssetTag23121309EX_PomUy64Was" } ] }

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

AWS CLI

无需等待指定的等待时间即可开始重新路由流量。

以下continue-deployment示例开始重新路由来自原始环境中的实例的流量,这些实例已准备好开始将流量转移到替代环境中的实例。

aws deploy continue-deployment \ --deployment-id "d-A1B2C3111" \ --deployment-wait-type "READY_WAIT"

此命令不生成任何输出。

有关更多信息,请参阅 “AWS CodeDeploy API参考ContinueDeployment中的。

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

AWS CLI

创建应用程序

以下create-application示例创建了一个应用程序并将其与用户的 AWS 账户关联。

aws deploy create-application --application-name MyOther_App

输出:

{ "applicationId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE" }

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

AWS CLI

创建自定义部署配置

以下create-deployment-config示例创建自定义部署配置并将其与用户的 AWS 账户关联。

aws deploy create-deployment-config \ --deployment-config-name ThreeQuartersHealthy \ --minimum-healthy-hosts type=FLEET_PERCENT,value=75

输出:

{ "deploymentConfigId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE" }

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

AWS CLI

创建部署组

以下create-deployment-group示例创建了一个部署组并将其与指定的应用程序和用户 AWS 帐户相关联。

aws deploy create-deployment-group \ --application-name WordPress_App \ --auto-scaling-groups CodeDeployDemo-ASG \ --deployment-config-name CodeDeployDefault.OneAtATime \ --deployment-group-name WordPress_DG \ --ec2-tag-filters Key=Name,Value=CodeDeployDemo,Type=KEY_AND_VALUE \ --service-role-arn arn:aws:iam::123456789012:role/CodeDeployDemoRole

输出:

{ "deploymentGroupId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE" }

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

AWS CLI

示例 1:使用 EC2 /Lon CodeDeploy dSP 计算平台创建部署

以下create-deployment示例创建了一个部署并将其与用户的 AWS 账户相关联。

aws deploy create-deployment \ --application-name WordPress_App \ --deployment-config-name CodeDeployDefault.OneAtATime \ --deployment-group-name WordPress_DG \ --description "My demo deployment" \ --s3-location bucket=CodeDeployDemoBucket,bundleType=zip,eTag=dd56cfdEXAMPLE8e768f9d77fEXAMPLE,key=WordPressApp.zip

输出:

{ "deploymentId": "d-A1B2C3111" }

示例 2:使用 Amazon ECS 计算平台创建 CodeDeploy 部署

以下create-deployment示例使用以下两个文件来部署 Amazon ECS 服务。

create-deployment.json 文件的内容:

{ "applicationName": "ecs-deployment", "deploymentGroupName": "ecs-deployment-dg", "revision": { "revisionType": "S3", "s3Location": { "bucket": "ecs-deployment-bucket", "key": "appspec.yaml", "bundleType": "YAML" } } }

反过来,该文件会appspec.yaml从名ecs-deployment-bucket为的 S3 存储桶中检索以下文件。

version: 0.0 Resources: - TargetService: Type: AWS::ECS::Service Properties: TaskDefinition: "arn:aws:ecs:region:123456789012:task-definition/ecs-task-def:2" LoadBalancerInfo: ContainerName: "sample-app" ContainerPort: 80 PlatformVersion: "LATEST"

命令:

aws deploy create-deployment \ --cli-input-json file://create-deployment.json \ --region us-east-1

输出:

{ "deploymentId": "d-1234ABCDE" }

有关更多信息,请参阅 “AWS CodeDeploy API参考CreateDeployment中的。

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

AWS CLI

删除应用程序

以下delete-application示例删除与用户 AWS 账户关联的指定应用程序。

aws deploy delete-application --application-name WordPress_App

此命令不生成任何输出。

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

AWS CLI

删除部署配置

以下delete-deployment-config示例删除了与用户 AWS 账户关联的自定义部署配置。

aws deploy delete-deployment-config --deployment-config-name ThreeQuartersHealthy

此命令不生成任何输出。

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

AWS CLI

删除部署组

以下delete-deployment-group示例删除与指定应用程序关联的部署组。

aws deploy delete-deployment-group \ --application-name WordPress_App \ --deployment-group-name WordPress_DG

输出:

{ "hooksNotCleanedUp": [] }

以下代码示例演示如何使用 delete-git-hub-account-token

AWS CLI

删除 GitHub 账户连接

以下delete-git-hub-account-token示例删除了指定 GitHub 账户的连接。

aws deploy delete-git-hub-account-token --token-name my-github-account

输出:

{ "tokenName": "my-github-account" }

有关更多信息,请参阅 “AWS CodeDeploy API参考DeleteGitHubAccountToken中的。

以下代码示例演示如何使用 deregister-on-premises-instance

AWS CLI

取消注册本地实例

以下deregister-on-premises-instance示例向取消注册本地实例 AWS CodeDeploy,但它不会删除与该实例关联的IAM用户,也不会在本地实例标签中取消与 AWS CodeDeploy 该实例的关联。它也不会从实例中卸载 AWS CodeDeploy 代理,也不会从实例中删除本地配置文件。

aws deploy deregister-on-premises-instance --instance-name AssetTag12010298EX

此命令不生成任何输出。

以下代码示例演示如何使用 deregister

AWS CLI

取消注册本地实例

以下deregister示例向注销本地实例。 AWS CodeDeploy它不会删除与实例关联的IAM用户。它会在本地标签 AWS CodeDeploy 中取消与实例的关联。它不会从实例中卸载 AWS CodeDeploy 代理,也不会从实例中删除本地配置文件。

aws deploy deregister \ --instance-name AssetTag12010298EX \ --no-delete-iam-user \ --region us-west-2

输出:

Retrieving on-premises instance information... DONE IamUserArn: arn:aws:iam::80398EXAMPLE:user/AWS/CodeDeploy/AssetTag12010298EX Tags: Key=Name,Value=CodeDeployDemo-OnPrem Removing tags from the on-premises instance... DONE Deregistering the on-premises instance... DONE Run the following command on the on-premises instance to uninstall the codedeploy-agent: aws deploy uninstall
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 “取消注册”。

以下代码示例演示如何使用 get-application-revision

AWS CLI

获取有关应用程序修订的信息

以下get-application-revision示例显示与指定应用程序关联的应用程序修订版的相关信息。

aws deploy get-application-revision \ --application-name WordPress_App \ --s3-location bucket=CodeDeployDemoBucket,bundleType=zip,eTag=dd56cfdEXAMPLE8e768f9d77fEXAMPLE,key=WordPressApp.zip

输出:

{ "applicationName": "WordPress_App", "revisionInfo": { "description": "Application revision registered by Deployment ID: d-A1B2C3111", "registerTime": 1411076520.009, "deploymentGroups": "WordPress_DG", "lastUsedTime": 1411076520.009, "firstUsedTime": 1411076520.009 }, "revision": { "revisionType": "S3", "s3Location": { "bundleType": "zip", "eTag": "dd56cfdEXAMPLE8e768f9d77fEXAMPLE", "bucket": "CodeDeployDemoBucket", "key": "WordPressApp.zip" } } }

以下代码示例演示如何使用 get-application

AWS CLI

获取有关应用程序的信息

以下get-application示例显示与用户 AWS 账户关联的应用程序的相关信息。

aws deploy get-application --application-name WordPress_App

输出:

{ "application": { "applicationName": "WordPress_App", "applicationId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "createTime": 1407878168.078, "linkedToGitHub": false } }

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

AWS CLI

获取有关部署配置的信息

以下get-deployment-config示例显示与用户 AWS 账户关联的部署配置的相关信息。

aws deploy get-deployment-config --deployment-config-name ThreeQuartersHealthy

输出:

{ "deploymentConfigInfo": { "deploymentConfigId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "minimumHealthyHosts": { "type": "FLEET_PERCENT", "value": 75 }, "createTime": 1411081164.379, "deploymentConfigName": "ThreeQuartersHealthy" } }

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

AWS CLI

查看有关部署组的信息

以下get-deployment-group示例显示与指定应用程序关联的部署组的相关信息。

aws deploy get-deployment-group \ --application-name WordPress_App \ --deployment-group-name WordPress_DG

输出:

{ "deploymentGroupInfo": { "applicationName": "WordPress_App", "autoScalingGroups": [ "CodeDeployDemo-ASG" ], "deploymentConfigName": "CodeDeployDefault.OneAtATime", "ec2TagFilters": [ { "Type": "KEY_AND_VALUE", "Value": "CodeDeployDemo", "Key": "Name" } ], "deploymentGroupId": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "serviceRoleArn": "arn:aws:iam::123456789012:role/CodeDeployDemoRole", "deploymentGroupName": "WordPress_DG" } }

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

AWS CLI

获取有关部署实例的信息

以下get-deployment-instance示例显示与指定部署关联的部署实例的相关信息。

aws deploy get-deployment-instance --deployment-id d-QA4G4F9EX --instance-id i-902e9fEX

输出:

{ "instanceSummary": { "instanceId": "arn:aws:ec2:us-east-1:80398EXAMPLE:instance/i-902e9fEX", "lifecycleEvents": [ { "status": "Succeeded", "endTime": 1408480726.569, "startTime": 1408480726.437, "lifecycleEventName": "ApplicationStop" }, { "status": "Succeeded", "endTime": 1408480728.016, "startTime": 1408480727.665, "lifecycleEventName": "DownloadBundle" }, { "status": "Succeeded", "endTime": 1408480729.744, "startTime": 1408480729.125, "lifecycleEventName": "BeforeInstall" }, { "status": "Succeeded", "endTime": 1408480730.979, "startTime": 1408480730.844, "lifecycleEventName": "Install" }, { "status": "Failed", "endTime": 1408480732.603, "startTime": 1408480732.1, "lifecycleEventName": "AfterInstall" }, { "status": "Skipped", "endTime": 1408480732.606, "lifecycleEventName": "ApplicationStart" }, { "status": "Skipped", "endTime": 1408480732.606, "lifecycleEventName": "ValidateService" } ], "deploymentId": "d-QA4G4F9EX", "lastUpdatedAt": 1408480733.152, "status": "Failed" } }

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

AWS CLI

返回有关部署目标的信息

以下get-deployment-target示例返回与指定部署关联的部署目标的相关信息。

aws deploy get-deployment-target \ --deployment-id "d-A1B2C3111" \ --target-id "i-a1b2c3d4e5f611111"

输出:

{ "deploymentTarget": { "deploymentTargetType": "InstanceTarget", "instanceTarget": { "lastUpdatedAt": 1556918687.504, "targetId": "i-a1b2c3d4e5f611111", "targetArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-a1b2c3d4e5f611111", "status": "Succeeded", "lifecycleEvents": [ { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "ApplicationStop", "startTime": 1556918592.162, "endTime": 1556918592.247 }, { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "DownloadBundle", "startTime": 1556918593.193, "endTime": 1556918593.981 }, { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "BeforeInstall", "startTime": 1556918594.805, "endTime": 1556918681.807 }, { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "Install", "startTime": 1556918682.696, "endTime": 1556918683.005 }, { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "AfterInstall", "startTime": 1556918684.135, "endTime": 1556918684.216 }, { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "ApplicationStart", "startTime": 1556918685.211, "endTime": 1556918685.295 }, { "status": "Succeeded", "diagnostics": { "errorCode": "Success", "message": "Succeeded", "logTail": "", "scriptName": "" }, "lifecycleEventName": "ValidateService", "startTime": 1556918686.65, "endTime": 1556918686.747 } ], "deploymentId": "d-A1B2C3111" } } }

有关更多信息,请参阅 “AWS CodeDeploy API参考GetDeploymentTarget中的。

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

AWS CLI

获取有关部署的信息

以下get-deployment示例显示与用户 AWS 账户关联的部署的相关信息。

aws deploy get-deployment --deployment-id d-A1B2C3123

输出:

{ "deploymentInfo": { "applicationName": "WordPress_App", "status": "Succeeded", "deploymentOverview": { "Failed": 0, "InProgress": 0, "Skipped": 0, "Succeeded": 1, "Pending": 0 }, "deploymentConfigName": "CodeDeployDefault.OneAtATime", "creator": "user", "description": "My WordPress app deployment", "revision": { "revisionType": "S3", "s3Location": { "bundleType": "zip", "eTag": "\"dd56cfdEXAMPLE8e768f9d77fEXAMPLE\"", "bucket": "CodeDeployDemoBucket", "key": "WordPressApp.zip" } }, "deploymentId": "d-A1B2C3123", "deploymentGroupName": "WordPress_DG", "createTime": 1409764576.589, "completeTime": 1409764596.101, "ignoreApplicationStopFailures": false } }

以下代码示例演示如何使用 get-on-premises-instance

AWS CLI

获取有关本地实例的信息

以下get-on-premises-instance示例检索有关指定本地实例的信息。

aws deploy get-on-premises-instance --instance-name AssetTag12010298EX

输出:

{ "instanceInfo": { "iamUserArn": "arn:aws:iam::123456789012:user/AWS/CodeDeploy/AssetTag12010298EX", "tags": [ { "Value": "CodeDeployDemo-OnPrem", "Key": "Name" } ], "instanceName": "AssetTag12010298EX", "registerTime": 1425579465.228, "instanceArn": "arn:aws:codedeploy:us-east-1:123456789012:instance/AssetTag12010298EX_4IwLNI2Alh" } }

以下代码示例演示如何使用 install

AWS CLI

安装本地实例

以下install示例将本地配置文件从实例上的指定位置复制到 AWS CodeDeploy 代理希望在实例上找到该文件的位置。它还会在实例上安装 AWS CodeDeploy 代理。它不会创建任何IAM用户,也不会向该实例注册本地实例 AWS CodeDeploy,也不会 AWS CodeDeploy 为该实例关联任何本地实例标签。

aws deploy install \ --override-config \ --config-file C:\temp\codedeploy.onpremises.yml \ --region us-west-2 \ --agent-installer s3://aws-codedeploy-us-west-2/latest/codedeploy-agent.msi

输出:

Creating the on-premises instance configuration file... DONE Installing the AWS CodeDeploy Agent... DONE
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 “安装”。

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

AWS CLI

获取有关应用程序修订的信息

以下list-application-revisions示例显示与指定应用程序关联的所有应用程序修订版的相关信息。

aws deploy list-application-revisions \ --application-name WordPress_App \ --s-3-bucket CodeDeployDemoBucket \ --deployed exclude \ --s-3-key-prefix WordPress_ \ --sort-by lastUsedTime \ --sort-order descending

输出:

{ "revisions": [ { "revisionType": "S3", "s3Location": { "version": "uTecLusvCB_JqHFXtfUcyfV8bEXAMPLE", "bucket": "CodeDeployDemoBucket", "key": "WordPress_App.zip", "bundleType": "zip" } }, { "revisionType": "S3", "s3Location": { "version": "tMk.UxgDpMEVb7V187ZM6wVAWEXAMPLE", "bucket": "CodeDeployDemoBucket", "key": "WordPress_App_2-0.zip", "bundleType": "zip" } } ] }

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

AWS CLI

获取有关应用程序的信息

以下list-applications示例显示与用户 AWS 账户关联的所有应用程序的相关信息。

aws deploy list-applications

输出:

{ "applications": [ "WordPress_App", "MyOther_App" ] }

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

AWS CLI

获取有关部署配置的信息

以下list-deployment-configs示例显示与用户 AWS 账户关联的所有部署配置的相关信息。

aws deploy list-deployment-configs

输出:

{ "deploymentConfigsList": [ "ThreeQuartersHealthy", "CodeDeployDefault.AllAtOnce", "CodeDeployDefault.HalfAtATime", "CodeDeployDefault.OneAtATime" ] }

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

AWS CLI

获取有关部署组的信息

以下list-deployment-groups示例显示与指定应用程序关联的所有部署组的相关信息。

aws deploy list-deployment-groups --application-name WordPress_App

输出:

{ "applicationName": "WordPress_App", "deploymentGroups": [ "WordPress_DG", "WordPress_Beta_DG" ] }

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

AWS CLI

获取有关部署实例的信息

以下list-deployment-instances示例显示与指定部署关联的所有部署实例的相关信息。

aws deploy list-deployment-instances \ --deployment-id d-A1B2C3111 \ --instance-status-filter Succeeded

输出:

{ "instancesList": [ "i-EXAMPLE11", "i-EXAMPLE22" ] }

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

AWS CLI

检索与部署关联IDs的目标列表

以下list-deployment-targets示例检索与状态为 “失败” 或 “” 的部署IDs关联的目标列表InProgress。

aws deploy list-deployment-targets \ --deployment-id "d-A1B2C3111" \ --target-filters "{\"TargetStatus\":[\"Failed\",\"InProgress\"]}"

输出:

{ "targetIds": [ "i-0f1558aaf90e5f1f9" ] }

有关更多信息,请参阅 “AWS CodeDeploy API参考ListDeploymentTargets中的。

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

AWS CLI

获取有关部署的信息

以下list-deployments示例显示与指定应用程序和部署组关联的所有部署的相关信息。

aws deploy list-deployments \ --application-name WordPress_App \ --create-time-range start=2014-08-19T00:00:00,end=2014-08-20T00:00:00 \ --deployment-group-name WordPress_DG \ --include-only-statuses Failed

输出:

{ "deployments": [ "d-EXAMPLE11", "d-EXAMPLE22", "d-EXAMPLE33" ] }

以下代码示例演示如何使用 list-git-hub-account-token-names

AWS CLI

列出已存储的 GitHub 账户连接的名称

以下list-git-hub-account-token-names示例列出了与当前 AWS 用户 GitHub 账户的已存储连接的名称。

aws deploy list-git-hub-account-token-names

输出:

{ "tokenNameList": [ "my-first-token", "my-second-token", "my-third-token" ] }

有关更多信息,请参阅 “AWS CodeDeploy API参考ListGitHubAccountTokenNames中的。

以下代码示例演示如何使用 list-on-premises-instances

AWS CLI

获取有关一个或多个本地实例的信息

以下list-on-premises-instances示例检索在中注册的实例的可用本地实例名称列表,这些实例还具有 AWS CodeDeploy 与该实例关联的 AWS CodeDeploy 指定本地实例标签。

aws deploy list-on-premises-instances \ --registration-status Registered \ --tag-filters Key=Name,Value=CodeDeployDemo-OnPrem,Type=KEY_AND_VALUE

输出:

{ "instanceNames": [ "AssetTag12010298EX" ] }

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

AWS CLI

列出资源(应用程序)的标签

以下list-tags-for-resource示例列出了应用于 testApp 中名为的应用程序的标签 CodeDeploy。

aws deploy list-tags-for-resource \ --resource-arn arn:aws:codedeploy:us-west-2:111122223333:application:testApp

输出:

{ "Tags": [ { "Key": "Type", "Value": "testType" }, { "Key": "Name", "Value": "testName" } ] }

有关更多信息,请参阅《AWS CodeDeploy 用户指南》 CodeDeploy中的为部署组添加实例标签

以下代码示例演示如何使用 push

AWS CLI

将 AWS CodeDeploy 兼容的应用程序修订捆绑并部署到 Amazon S3

以下push示例将应用程序修订捆绑并部署到 Amazon S3,然后将该应用程序修订与指定的应用程序关联起来。

aws deploy push \ --application-name WordPress_App \ --description "This is my deployment" \ --ignore-hidden-files \ --s3-location s3://CodeDeployDemoBucket/WordPressApp.zip \ --source /tmp/MyLocalDeploymentFolder/

输出描述了如何使用create-deployment命令创建使用上传的应用程序修订版的部署。

To deploy with this revision, run: aws deploy create-deployment --application-name WordPress_App --deployment-config-name <deployment-config-name> --deployment-group-name <deployment-group-name> --s3-location bucket=CodeDeployDemoBucket,key=WordPressApp.zip,bundleType=zip,eTag="cecc9b8EXAMPLE50a6e71fdb88EXAMPLE",version=LFsJAUdEXAMPLEfvKtvi79L8EXAMPLE
  • 有关API详细信息,请参阅 Push in AWS CLI 命令参考

以下代码示例演示如何使用 register-application-revision

AWS CLI

注册有关已上传的应用程序修订版的信息

以下register-application-revision示例使用注册了存储在 Amazon S3 中的已上传应用程序修订的信息。 AWS CodeDeploy

aws deploy register-application-revision \ --application-name WordPress_App \ --description "Revised WordPress application" \ --s3-location bucket=CodeDeployDemoBucket,key=RevisedWordPressApp.zip,bundleType=zip,eTag=cecc9b8a08eac650a6e71fdb88EXAMPLE

此命令不生成任何输出。

以下代码示例演示如何使用 register-on-premises-instance

AWS CLI

注册本地实例

以下register-on-premises-instance示例向注册本地实例 AWS CodeDeploy。它不会创建指定的IAM用户,也不会将 AWS CodeDeploy 任何本地实例标签与注册的实例相关联。

aws deploy register-on-premises-instance \ --instance-name AssetTag12010298EX \ --iam-user-arn arn:aws:iam::80398EXAMPLE:user/CodeDeployDemoUser-OnPrem

此命令不生成任何输出。

以下代码示例演示如何使用 register

AWS CLI

注册本地实例

以下register示例向注册本地实例 AWS CodeDeploy,将指定的本地实例标签与注册的实例关联起来,并创建可复制到该实例的本地配置文件。 AWS CodeDeploy 它不会创建IAM用户,也不会在实例上安装 AWS CodeDeploy 代理。

aws deploy register \ --instance-name AssetTag12010298EX \ --iam-user-arn arn:aws:iam::80398EXAMPLE:user/CodeDeployUser-OnPrem \ --tags Key=Name,Value=CodeDeployDemo-OnPrem \ --region us-west-2

输出:

Registering the on-premises instance... DONE Adding tags to the on-premises instance... DONE Copy the on-premises configuration file named codedeploy.onpremises.yml to the on-premises instance, and run the following command on the on-premises instance to install and configure the AWS CodeDeploy Agent: aws deploy install --config-file codedeploy.onpremises.yml
  • 有关API详细信息,请参阅在《AWS CLI 命令参考》中注册

以下代码示例演示如何使用 remove-tags-from-on-premises-instances

AWS CLI

从一个或多个本地实例中移除标签

以下remove-tags-from-on-premises-instances示例取消中指定的本地标签与本地实例 AWS CodeDeploy 的关联。它不会取消注册中的本地实例 AWS CodeDeploy,也不会从实例中卸载 AWS CodeDeploy 代理,也不会从实例中删除本地配置文件,也不会删除与实例关联的IAM用户。

aws deploy remove-tags-from-on-premises-instances \ --instance-names AssetTag12010298EX AssetTag23121309EX \ --tags Key=Name,Value=CodeDeployDemo-OnPrem

此命令不生成任何输出。

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

AWS CLI

尝试停止部署

以下stop-deployment示例尝试停止与用户 AWS 账户关联的正在进行的部署。

aws 部署停止部署——deployment-id d-a1b2c3111

输出:

{ "status": "Succeeded", "statusMessage": "No more commands will be scheduled for execution in the deployment instances" }

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

AWS CLI

为资源(应用程序)添加标签

以下tag-resource示例向名为的应用程序添加了两个标签,其中键名为 Name 和 Type,值 testName 为 an testApp d CodeDeploy。 testType :

aws deploy tag-resource \ --resource-arn arn:aws:codedeploy:us-west-2:111122223333:application:testApp \ --tags Key=Name,Value=testName Key=Type,Value=testType

如果成功,此命令不会产生任何输出。

有关更多信息,请参阅《AWS CodeDeploy 用户指南》 CodeDeploy中的为部署组添加实例标签

以下代码示例演示如何使用 uninstall

AWS CLI

卸载本地实例

以下uninstall示例从本地实例卸载 AWS CodeDeploy 代理并从实例中删除本地配置文件。它不会在中取消注册实例 AWS CodeDeploy,也不会取消中的任何本地实例标签与该实例 AWS CodeDeploy 的关联,也不会删除与该实例关联的IAM用户。

aws deploy uninstall

此命令不生成任何输出。

  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 “卸载”。

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

AWS CLI

从资源(应用程序)中移除标签

以下untag-resource示例从名为的应用程序中删除了两个带有 Name 和 Type 键 testApp 的标签 CodeDeploy。

aws deploy untag-resource \ --resource-arn arn:aws:codedeploy:us-west-2:111122223333:application:testApp \ --tag-keys Name Type

如果成功,此命令不会产生任何输出。

有关更多信息,请参阅《AWS CodeDeploy 用户指南》 CodeDeploy中的为部署组添加实例标签

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

AWS CLI

更改应用程序的详细信息

以下update-application示例更改了与用户 AWS 账户关联的应用程序的名称。

aws deploy update-application \ --application-name WordPress_App \ --new-application-name My_WordPress_App

此命令不生成任何输出。

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

AWS CLI

更改有关部署组的信息

以下update-deployment-group示例更改了与指定应用程序关联的部署组的设置。

aws deploy update-deployment-group \ --application-name WordPress_App \ --auto-scaling-groups My_CodeDeployDemo_ASG \ --current-deployment-group-name WordPress_DG \ --deployment-config-name CodeDeployDefault.AllAtOnce \ --ec2-tag-filters Key=Name,Type=KEY_AND_VALUE,Value=My_CodeDeployDemo \ --new-deployment-group-name My_WordPress_DepGroup \ --service-role-arn arn:aws:iam::80398EXAMPLE:role/CodeDeployDemo-2

此命令不生成任何输出。