

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

# 正在处理的应用程序修订版 CodeDeploy
<a name="application-revisions"></a>

在中 CodeDeploy，修订版包含 CodeDeploy 将部署到您的实例或将在您的实例上运行的脚本 CodeDeploy 的源文件版本。

您计划修订，向修订版添加 AppSpec 文件，然后将修订推送到 Amazon S3 或 GitHub。在推送修订之后，您可以部署它。

**Topics**
+ [规划修订](application-revisions-plan.md)
+ [添加 AppSpec 文件](application-revisions-appspec-file.md)
+ [选择存储库类型](application-revisions-repository-type.md)
+ [推送修订](application-revisions-push.md)
+ [查看应用程序修订详细信息](application-revisions-view-details.md)
+ [注册应用程序修订](application-revisions-register.md)

# 为 CodeDeploy 规划修订
<a name="application-revisions-plan"></a>

良好的计划使部署修订变得轻松多了。

对于向 AWS Lambda 或 Amazon ECS 计算平台进行的部署，修订与 AppSpec 文件相同。以下信息不适用。有关更多信息，请参阅 [将应用程序规范文件添加到修订版中 CodeDeploy](application-revisions-appspec-file.md)。

对于向 EC2/本地计算平台进行的部署，首先在开发计算机上创建空的根目录（文件夹）。这是您将存储要部署到实例的源文件（如文本和二进制文件、可执行文件、包等）或要在实例上运行的脚本的位置。

例如，在 Linux、macOS 或 Unix 上的 `/tmp/` 根文件夹，或 Windows 上的 `c:\temp` 根文件夹中：

```
/tmp/ or c:\temp (root folder)
  |--content (subfolder)
  |    |--myTextFile.txt
  |    |--mySourceFile.rb
  |    |--myExecutableFile.exe
  |    |--myInstallerFile.msi
  |    |--myPackage.rpm
  |    |--myImageFile.png
  |--scripts (subfolder)
  |    |--myShellScript.sh
  |    |--myBatchScript.bat 
  |    |--myPowerShellScript.ps1 
  |--appspec.yml
```

根文件夹也应包含应用程序规范文件（AppSpec 文件），如此处所示。有关更多信息，请参阅 [将应用程序规范文件添加到修订版中 CodeDeploy](application-revisions-appspec-file.md)。

# 将应用程序规范文件添加到修订版中 CodeDeploy
<a name="application-revisions-appspec-file"></a>

本主题介绍如何向部署中添加 AppSpec 文件。它还包括用于为 AWS Lambda 和 EC2/本地部署创建 AppSpec 文件的模板。

**Topics**
+ [为 Amazon ECS 部署添加 AppSpec 文件](#add-appspec-file-ecs)
+ [为 AWS Lambda 部署添加 AppSpec 文件](#add-appspec-file-lambda)
+ [为 EC2/本地部署添加 AppSpec 文件](#add-appspec-file-server)

## 为 Amazon ECS 部署添加 AppSpec 文件
<a name="add-appspec-file-ecs"></a>

对于向 Amazon ECS 计算平台进行的部署：
+ 该 AppSpec 文件指定了用于部署的 Amazon ECS 任务定义、用于路由流量的容器名称和端口映射，以及部署生命周期事件之后运行的可选 Lambda 函数。
+ 修订版与 AppSpec 文件相同。
+ 可以使用 JSON 或 YAML 写入 AppSpec 文件。
+ 创建部署时，可以将文件另存为文本文件或直接输入到控制台中。 AppSpec 有关更多信息，请参阅 [创建 Amazon ECS 计算平台部署（控制台）](deployments-create-console-ecs.md)。

**创建 AppSpec 文件**

1. 将 JSON 或 YAML 模板复制到文本编辑器或控制台的 AppSpec 编辑器中。

1. 根据需要修改模板。

1. 使用 JSON 或 YAML 验证器来验证您的文件。 AppSpec 如果您使用 AppSpec编辑器，则在选择 “**创建部署**” 时会对文件进行验证。

1. 如果您使用文本编辑器，请保存该文件。如果您使用创建部署， AWS CLI 请引用该文件（如果该 AppSpec 文件位于您的硬盘或 Amazon S3 存储桶中）。如果您使用控制台，则必须将 AppSpec 文件推送到 Amazon S3。

### 带说明的 Amazon ECS 部署的 YAML AppSpec 文件模板
<a name="app-spec-template-yaml-ecs"></a>

以下是 Amazon ECS 部署 AppSpec 文件的 YAML 模板，其中包含所有可用选项。有关在 `hooks` 部分中使用的生命周期事件的信息，请参阅[AppSpec 亚马逊 ECS 部署的 “挂钩” 部分](reference-appspec-file-structure-hooks.md#appspec-hooks-ecs)。

```
# This is an appspec.yml template file for use with an Amazon ECS deployment in CodeDeploy.
# The lines in this template that start with the hashtag are 
#   comments that can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "CodeDeploy User Guide" at
#   https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# In the Resources section, you must specify the following: the Amazon ECS service, task definition name, 
# and the name and port of the load balancer to route traffic,
# target version, and (optional) the current version of your AWS Lambda function. 
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "" # Specify the ARN of your task definition (arn:aws:ecs:region:account-id:task-definition/task-definition-family-name:task-definition-revision-number)
        LoadBalancerInfo: 
          ContainerName: "" # Specify the name of your Amazon ECS application's container
          ContainerPort: "" # Specify the port for your container where traffic reroutes 
# Optional properties
        PlatformVersion: "" # Specify the version of your Amazon ECS Service
        NetworkConfiguration:
          AwsvpcConfiguration:
            Subnets: ["",""] # Specify one or more comma-separated subnets in your Amazon ECS service
            SecurityGroups: ["",""] # Specify one or more comma-separated security groups in your Amazon ECS service
            AssignPublicIp: "" # Specify "ENABLED" or "DISABLED"             
# (Optional) In the Hooks section, specify a validation Lambda function to run during 
# a lifecycle event. 
Hooks:
# Hooks for Amazon ECS deployments are:
    - BeforeInstall: "" # Specify a Lambda function name or ARN
    - AfterInstall: "" # Specify a Lambda function name or ARN
    - AfterAllowTestTraffic: "" # Specify a Lambda function name or ARN
    - BeforeAllowTraffic: "" # Specify a Lambda function name or ARN
    - AfterAllowTraffic: "" # Specify a Lambda function name or ARN
```

### 亚马逊 ECS 部署模板的 JSON AppSpec 文件
<a name="app-spec-template-json-ecs"></a>

以下是 Amazon ECS 部署 AppSpec 文件的 JSON 模板，其中包含所有可用选项。有关模板说明，请参阅上一部分中 YAML 版本中的注释。有关在 `hooks` 部分中使用的生命周期事件的信息，请参阅[AppSpec 亚马逊 ECS 部署的 “挂钩” 部分](reference-appspec-file-structure-hooks.md#appspec-hooks-ecs)。

```
{
	"version": 0.0,
	"Resources": [
		{
			"TargetService": {
				"Type": "AWS::ECS::Service",
				"Properties": {
    			"TaskDefinition": "",
    			"LoadBalancerInfo": {
    				"ContainerName": "",
    				"ContainerPort":
    			},
    			"PlatformVersion": "",
    			"NetworkConfiguration": {
    				"AwsvpcConfiguration": {
    					"Subnets": [
    						"",
    						""
    					],
    					"SecurityGroups": [
    						"",
    						""
    					],
    					"AssignPublicIp": ""
    				}
    			}
  			}				
			}
		}
	],
	"Hooks": [
		{
			"BeforeInstall": ""
		},
		{
			"AfterInstall": ""
		},
		{
			"AfterAllowTestTraffic": ""
		},
		{
			"BeforeAllowTraffic": ""
		},
		{
			"AfterAllowTraffic": ""
		}
	]
}
```

## 为 AWS Lambda 部署添加 AppSpec 文件
<a name="add-appspec-file-lambda"></a>

要部署到 AWS Lambda 计算平台，请执行以下操作：
+ 该 AppSpec 文件包含有关要部署和用于部署验证的 Lambda 函数的说明。
+ 修订版与 AppSpec 文件相同。
+ 可以使用 JSON 或 YAML 写入 AppSpec 文件。
+ 创建部署时，可以将文件另存为文本文件或直接输入到控制台 AppSpec 编辑器中。 AppSpec 有关更多信息，请参阅 [创建 L AWS ambda 计算平台部署（控制台）](deployments-create-console-lambda.md)。

要创建 AppSpec 文件，请执行以下操作：

1. 将 JSON 或 YAML 模板复制到文本编辑器或控制台的 AppSpec 编辑器中。

1. 根据需要修改模板。

1. 使用 JSON 或 YAML 验证器来验证您的文件。 AppSpec 如果您使用 AppSpec编辑器，则在选择 “**创建部署**” 时会对文件进行验证。

1. 如果您使用文本编辑器，请保存该文件。如果您使用创建部署， AWS CLI 请引用该文件（如果该 AppSpec 文件位于您的硬盘或 Amazon S3 存储桶中）。如果您使用控制台，则必须将 AppSpec 文件推送到 Amazon S3。



### 带有说明的 AWS Lambda 部署的 YAML AppSpec 文件模板
<a name="app-spec-template-yaml-lambda"></a>

有关在 hooks 部分中使用的生命周期事件的信息，请参阅[AppSpec AWS Lambda 部署的 “挂钩” 部分](reference-appspec-file-structure-hooks.md#appspec-hooks-lambda)。

```
# This is an appspec.yml template file for use with an AWS Lambda deployment in CodeDeploy.
# The lines in this template starting with the hashtag symbol are 
#   instructional comments and can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "CodeDeploy User Guide" at
#   https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# In the Resources section specify the name, alias, 
# target version, and (optional) the current version of your AWS Lambda function. 
Resources:
  - MyFunction: # Replace "MyFunction" with the name of your Lambda function 
      Type: AWS::Lambda::Function
      Properties:
        Name: "" # Specify the name of your Lambda function
        Alias: "" # Specify the alias for your Lambda function
        CurrentVersion: "" # Specify the current version of your Lambda function
        TargetVersion: "" # Specify the version of your Lambda function to deploy
# (Optional) In the Hooks section, specify a validation Lambda function to run during 
# a lifecycle event. Replace "LifeCycleEvent" with BeforeAllowTraffic
# or AfterAllowTraffic. 
Hooks:
    - LifeCycleEvent: "" # Specify a Lambda validation function between double-quotes.
```

### AWS Lambda 部署模板 AppSpec 的 JSON 文件
<a name="app-spec-template-json-lambda"></a>

在以下模板中，将 “MyFunction” 替换为您的 AWS Lambda 函数名称。在可选的 Hooks 部分中，将生命周期事件替换为 BeforeAllowTraffic 或 AfterAllowTraffic。

有关在 Hooks 部分中使用的生命周期事件的信息，请参阅[AppSpec AWS Lambda 部署的 “挂钩” 部分](reference-appspec-file-structure-hooks.md#appspec-hooks-lambda)。

```
{
 	"version": 0.0,
 	"Resources": [{
 		"MyFunction": {
 			"Type": "AWS::Lambda::Function",
 			"Properties": {
 				"Name": "",
 				"Alias": "",
 				"CurrentVersion": "",
 				"TargetVersion": ""
 			}
 		}
 	}],
 	"Hooks": [{
 			"LifeCycleEvent": ""
 		}
 	]
 }
```

## 为 EC2/本地部署添加 AppSpec 文件
<a name="add-appspec-file-server"></a>

如果没有 AppSpec 文件， CodeDeploy 则无法将应用程序修订版中的源文件映射到其目的地，也无法运行脚本以部署到 EC2/本地计算平台。

每个修订版只能包含一个 AppSpec 文件。

要向修订版中添加 AppSpec 文件，请执行以下操作：

1. 将模板复制到文本编辑器。

1. 根据需要修改模板。

1. 使用 YAML 验证器检查文件的有效性。 AppSpec 

1. 在修订的根目录中将文件另存为 `appspec.yml`。

1. 运行以下命令之一，验证是否已将 AppSpec 文件放在根目录中：
   + 对于 Linux、macOS 或 Unix：

     ```
     find /path/to/root/directory -name appspec.yml
     ```

     如果在那里找不到 AppSpec 文件，则不会有输出。
   + 对于 Windows：

     ```
     dir path\to\root\directory\appspec.yml
     ```

     如果**文件未存储在那里，则会显示 “找**不到 AppSpec 文件” 错误。

1. 将修订版推送到 Amazon S3 或 GitHub。

   有关说明，请参阅[将修订推送 CodeDeploy 到 Amazon S3（仅限 EC2/本地部署）](application-revisions-push.md)。

### AppSpec 带说明的 EC2/本地部署的文件模板
<a name="app-spec-template-server"></a>

**注意**  
 部署到 Windows Server 实例不支持 `runas` 元素。如果您要部署到 Windows 服务器实例，请不要将其包含在 AppSpec 文件中。

```
# This is an appspec.yml template file for use with an EC2/On-Premises deployment in CodeDeploy.
# The lines in this template starting with the hashtag symbol are 
#   instructional comments and can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "CodeDeploy User Guide" at
#   https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# Specify "os: linux" if this revision targets Amazon Linux, 
#   Red Hat Enterprise Linux (RHEL), or Ubuntu Server  
#   instances.
# Specify "os: windows" if this revision targets Windows Server instances.
# (You cannot specify both "os: linux" and "os: windows".)
os: linux 
# os: windows
# During the Install deployment lifecycle event (which occurs between the 
#   BeforeInstall and AfterInstall events), copy the specified files 
#   in "source" starting from the root of the revision's file bundle 
#   to "destination" on the Amazon EC2 instance.
# Specify multiple "source" and "destination" pairs if you want to copy 
#   from multiple sources or to multiple destinations.
# If you are not copying any files to the Amazon EC2 instance, then remove the
#   "files" section altogether. A blank or incomplete "files" section
#   may cause associated deployments to fail.
files:
  - source: 
    destination:
  - source:
    destination:
# For deployments to Amazon Linux, Ubuntu Server, or RHEL instances,
#   you can specify a "permissions" 
#   section here that describes special permissions to apply to the files 
#   in the "files" section as they are being copied over to 
#   the Amazon EC2 instance.
#   For more information, see the documentation.
# If you are deploying to Windows Server instances,
#   then remove the 
#   "permissions" section altogether. A blank or incomplete "permissions"
#   section may cause associated deployments to fail.
permissions:
  - object:
    pattern:
    except:
    owner:
    group:
    mode: 
    acls:
      -
    context:
      user:
      type:
      range:
    type:
      -
# If you are not running any commands on the Amazon EC2 instance, then remove 
#   the "hooks" section altogether. A blank or incomplete "hooks" section
#   may cause associated deployments to fail.
hooks:
# For each deployment lifecycle event, specify multiple "location" entries 
#   if you want to run multiple scripts during that event.
# You can specify "timeout" as the number of seconds to wait until failing the deployment 
#   if the specified scripts do not run within the specified time limit for the 
#   specified event. For example, 900 seconds is 15 minutes. If not specified, 
#   the default is 1800 seconds (30 minutes).
#   Note that the maximum amount of time that all scripts must finish executing 
#   for each individual deployment lifecycle event is 3600 seconds (1 hour). 
#   Otherwise, the deployment will stop and CodeDeploy will consider the deployment
#   to have failed to the Amazon EC2 instance. Make sure that the total number of seconds 
#   that are specified in "timeout" for all scripts in each individual deployment 
#   lifecycle event does not exceed a combined 3600 seconds (1 hour).
# For deployments to Amazon Linux, Ubuntu Server, or RHEL instances,
#   you can specify "runas" in an event to
#   run as the specified user. For more information, see the documentation.
#   If you are deploying to Windows Server instances,
#   remove "runas" altogether.
# If you do not want to run any commands during a particular deployment
#   lifecycle event, remove that event declaration altogether. Blank or 
#   incomplete event declarations may cause associated deployments to fail.
# During the ApplicationStop deployment lifecycle event, run the commands 
#   in the script specified in "location" starting from the root of the 
#   revision's file bundle.
  ApplicationStop:
    - location: 
      timeout:
      runas:
    - location: 
      timeout:
      runas: 
# During the BeforeInstall deployment lifecycle event, run the commands 
#   in the script specified in "location".
  BeforeInstall:
    - location: 
      timeout:
      runas: 
    - location: 
      timeout:
      runas:
# During the AfterInstall deployment lifecycle event, run the commands 
#   in the script specified in "location".
  AfterInstall:
    - location:     
      timeout: 
      runas:
    - location: 
      timeout:
      runas:
# During the ApplicationStart deployment lifecycle event, run the commands 
#   in the script specified in "location".
  ApplicationStart:
    - location:     
      timeout: 
      runas:
    - location: 
      timeout:
      runas:
# During the ValidateService deployment lifecycle event, run the commands 
#   in the script specified in "location".
  ValidateService:
    - location:     
      timeout: 
      runas:
    - location: 
      timeout:
      runas:
```

# 选择 CodeDeploy 存储库类型
<a name="application-revisions-repository-type"></a>

CodeDeploy 需要的文件的存储位置称为“存储库”**。对存储库的使用取决于您的部署使用哪个计算平台。
+ **EC2/本地**：要将您的应用程序代码部署到一个或多个实例，必须将您的代码打包到一个存档文件，并将代码放置到 CodeDeploy 可在部署过程中访问它的存储库。您应将可部署内容和一个 AppSpec 文件打包到一个存档文件，然后将它上传到 CodeDeploy 支持的某个存储库类型。
+ **AWS Lambda** 和 **Amazon ECS**：部署需要 AppSpec 文件，在部署过程中可以通过下列方式之一访问它：
  +  从 Amazon S3 存储桶。
  +  从直接键入控制台中的 AppSpec 编辑器内的文本。有关更多信息，请参阅[创建 L AWS ambda 计算平台部署（控制台）](deployments-create-console-lambda.md)和[创建 Amazon ECS 计算平台部署（控制台）](deployments-create-console-ecs.md)。
  +  如果您使用 AWS CLI，则可以引用位于您的硬盘驱动器上或网络驱动器上的 AppSpec 文件。有关更多信息，请参阅[创建 L AWS ambda 计算平台部署 (CLI)](deployments-create-lambda-cli.md)和[创建 Amazon ECS 计算平台部署（CLI）](deployments-create-ecs-cli.md)。

CodeDeploy 当前支持以下存储库类型：


|  |  |  | 
| --- |--- |--- |
| 存储库类型 | 存储库详细信息 | 支持的计算平台 | 
| Amazon S3 () | [Amazon Simple Storage Service](https://docs.aws.amazon.com/AmazonS3/latest/userguide/)（Amazon S3）是 AWS 解决方案，用于安全、可扩展的对象存储。Amazon S3 将数据作为对象存储在存储桶 中。对象由文件和描述该文件的任何可选元数据组成。要将对象存储到 Amazon S3 中，请将文件上传到存储桶中。上传文件时，可以设置对象的权限和元数据。了解更多：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codedeploy/latest/userguide/application-revisions-repository-type.html) | 使用以下计算平台的部署可以将修订存储在 Amazon S3 存储桶中。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codedeploy/latest/userguide/application-revisions-repository-type.html) | 
| GitHub | 您可以将应用程序修订存储在 [GitHub](http://www.github.com) 存储库中。只要 GitHub 存储库中的源代码发生更改，您就可以触发源自该存储库的部署。了解更多：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codedeploy/latest/userguide/application-revisions-repository-type.html) | 只有 EC2/本地部署可以将修订存储在 GitHub 存储库中。 | 
| Bitbucket |  您可以使用 [Bitbucket Pipelines](https://bitbucket.org/product/features/pipelines) 中的 [CodeDeploy 管道](https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/aws-code-deploy)将代码部署到 EC2 实例的部署组。Bitbucket 管道提供持续集成和持续部署（CI/CD）功能，包括 [Bitbucket 部署](https://confluence.atlassian.com/bitbucket/bitbucket-deployments-940695276.html)。CodeDeploy 管道首先将构件推送到您指定的 S3 存储桶，然后从存储桶部署代码构件。 了解更多： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/codedeploy/latest/userguide/application-revisions-repository-type.html)  | 只有 EC2/本地部署可以将修订存储在 BitBucket 存储库中。 | 

**注意**  
AWS Lambda 部署仅适用于 Amazon S3 存储库。

# 将修订推送 CodeDeploy 到 Amazon S3（仅限 EC2/本地部署）
<a name="application-revisions-push"></a>

按照中所述计划修订版[为 CodeDeploy 规划修订](application-revisions-plan.md)并按照中所述向修订版添加 AppSpec 文件后[将应用程序规范文件添加到修订版中 CodeDeploy](application-revisions-appspec-file.md)，就可以捆绑组件文件并将修订推送到 Amazon S3 了。对于部署到 Amazon EC2 实例，在推送修订之后，您可以使用 CodeDeploy 将修订从 Amazon S3 部署到实例。

**注意**  
CodeDeploy 也可以用来部署已推送到的修订版 GitHub。有关更多信息，请参阅您的 GitHub 文档。

我们假定您已遵循 [入门 CodeDeploy](getting-started-codedeploy.md)中的说明来设置 AWS CLI。这对于调用稍后描述的 **push** 命令来说特别重要。

请确保您拥有 Amazon S3 存储桶。遵循[创建存储桶](https://docs.aws.amazon.com/AmazonS3/latest/userguide/CreatingABucket.html)中的说明。

如果要部署到 Amazon EC2 实例，则必须创建目标 Amazon S3 存储桶或者它必须存在于目标实例所在的区域中。例如，如果您要将修订部署到美国东部（弗吉尼亚州北部）区域的某些实例和美国西部（俄勒冈州）区域的其他实例，那么您必须在美国东部（弗吉尼亚州北部）区域的一个存储桶中部署一个修订副本，在美国西部（俄勒冈州）区域的另一个存储桶中部署同一修订的另一个副本。在此方案中，您随后需要分别在美国东部（弗吉尼亚州北部）区域和美国西部（俄勒冈州）区域中各创建一个单独的部署，即使两个区域和存储桶中的修订相同也是如此。

您必须拥有上传到 Amazon S3 存储桶的权限。您可以通过 Amazon S3 存储桶策略指定这些权限。例如，在以下 Amazon S3 存储桶策略中，使用通配符 (\$1) 允许 AWS 账户将文件上传`111122223333`到 Amazon S3 存储桶中名为`amzn-s3-demo-bucket`的任何目录：

```
{
    "Statement": [
        {
            "Action": [
                "s3:PutObject"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
            "Principal": {
                "AWS": [
                    "111122223333"
                ]
            }
        }
    ]
}
```

要查看您的 AWS 账户 ID，请参阅[查找您的 AWS 账户 ID](https://docs.aws.amazon.com/IAM/latest/UserGuide/console_account-alias.html#FindingYourAWSId)。

要了解如何生成和附加 Amazon S3 存储桶策略，请参阅[存储桶策略示例](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html)。

调用 **push** 命令的用户必须至少具有将修订上传到每个目标 Amazon S3 存储桶的权限。例如，以下策略允许用户将修订上传到名为 `amzn-s3-demo-bucket` 的 Amazon S3 存储桶中的任意位置：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
        }
    ]
}
```

------

要了解如何创建和附加 IAM policy，请参阅[使用策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/ManagingPolicies.html#AddingPermissions_Console)。

## 使用推送修订版 AWS CLI
<a name="push-with-cli"></a>

**注意**  
 该`push`命令将应用程序工件和 AppSpec 文件捆绑到修订版中。此修订的文件格式是压缩的 ZIP 文件。该命令不能用于 AWS Lambda 或 Amazon ECS 部署，因为每个部署都需要一个 JSON 格式或 YAML 格式文件的修订版。 AppSpec 

调用 **push** 命令以便为部署绑定和推送修订。它的参数包括：
+  **--application-name**：（字符串）必需。要应用程序修订关联的 CodeDeploy 应用程序的名称。
+  **--s3-location**：（字符串）必需。要上传到 Amazon S3 的应用程序修订的位置的相关信息。您必须指定一个 Amazon S3 存储桶和一个键。关键是修订的名称。 CodeDeploy 在上传内容之前对其进行压缩。采用格式 `s3://amzn-s3-demo-bucket/your-key.zip`。
+  **--ignore-hidden-files** 或 **--no-ignore-hidden-files**：（布尔值）可选。使用 `--no-ignore-hidden-files` 标志（默认值）会将隐藏文件绑定和上传到 Amazon S3。使用 `--ignore-hidden-files` 标志不会将隐藏文件绑定和上传到 Amazon S3。
+  **--source**（字符串）可选。要部署的内容以及开发计算机上要压缩并上传到 Amazon S3 AppSpec 的文件的位置。该位置被指定为相对于当前目录的路径。如果未指定相对路径或者对路径使用了单个句点（“.”），则使用当前目录。
+  **--description**（字符串）可选。用于概述应用程序修订的注释。如果未指定，则使用默认字符串 “按 AWS CLI '时间'UTC上传”，其中'时间'是协调世界时 (UTC) 中的当前系统时间。

您可以使用推送 Amazon EC2 部署的修订。 AWS CLI 示例推送命令如下所示：

在 Linux、macOS 或 Unix 中：

```
aws deploy push \
  --application-name WordPress_App \
  --description "This is a revision for the application WordPress_App" \
  --ignore-hidden-files \
  --s3-location s3://amzn-s3-demo-bucket/WordPressApp.zip \
  --source .
```

 在 Windows 中：

```
aws deploy push --application-name WordPress_App --description "This is a revision for the application WordPress_App" --ignore-hidden-files --s3-location s3://amzn-s3-demo-bucket/WordPressApp.zip --source .
```

 此命令执行以下操作：
+  将已绑定的文件与名为 `WordPress_App` 的应用程序关联。
+  将描述附加到修订。
+  忽略隐藏文件。
+  为修订 `WordPressApp.zip` 命名并将其推送到名为 `amzn-s3-demo-bucket` 的存储桶。
+  将根目录中的所有文件绑定到修订。

推送成功后，您可以使用 AWS CLI 或 CodeDeploy 控制台从 Amazon S3 部署修订。要部署此修订版，请执行以下 AWS CLI操作：

 在 Linux、macOS 或 Unix 中：

```
aws deploy create-deployment \
  --application-name WordPress_App \ 
  --deployment-config-name your-deployment-config-name \ 
  --deployment-group-name your-deployment-group-name \ 
  --s3-location bucket=amzn-s3-demo-bucket,key=WordPressApp.zip,bundleType=zip
```

 在 Windows 中：

```
aws deploy create-deployment --application-name WordPress_App --deployment-config-name your-deployment-config-name --deployment-group-name your-deployment-group-name --s3-location bucket=amzn-s3-demo-bucket,key=WordPressApp.zip,bundleType=zip
```

 有关更多信息，请参阅 [使用创建部署 CodeDeploy](deployments-create.md)。

# 使用查看应用程序修订详情 CodeDeploy
<a name="application-revisions-view-details"></a>

您可以使用 CodeDeploy 控制台 AWS CLI、或，查看有关在 CodeDeploy APIs 您的 AWS 账户中为指定应用程序注册的所有应用程序修订的详细信息。

有关注册修订的信息，请参阅[在 Amazon S3 中注册应用程序修订版 CodeDeploy](application-revisions-register.md)。

**Topics**
+ [查看应用程序修订详细信息（控制台）](#application-revisions-view-details-console)
+ [查看应用程序修订详细信息（CLI）](#application-revisions-view-details-cli)

## 查看应用程序修订详细信息（控制台）
<a name="application-revisions-view-details-console"></a>

要查看应用程序修订详细信息，请执行以下操作：

1. 登录 AWS 管理控制台 并在 [https://console.aws.amazon.com/codede](https://console.aws.amazon.com/codedeploy) ploy 上打开 CodeDeploy 控制台。
**注意**  
使用您在[入门 CodeDeploy](getting-started-codedeploy.md)中设置的同一用户登录。

1. 在导航窗格中，展开 **Deploy（部署）**，然后选择 **Applications（应用程序）**。
**注意**  
如果未显示任何条目，请确保选择了正确的区域。在导航栏的区域选择器中，选择[区域和终端节点中列出的区域](https://docs.aws.amazon.com/general/latest/gr/rande.html#codedeploy_region)之一*AWS 一般参考*。 CodeDeploy 仅在这些地区支持。

1. 选择具有您要查看的修订的应用程序的名称。

1. 在 **Application details（应用程序详细信息）**页面上，选择 **Revisions（修订）**选项卡，然后查看为应用程序注册的修订的列表。选择一个修订，然后选择 **View details（查看详细信息）**。

## 查看应用程序修订详细信息（CLI）
<a name="application-revisions-view-details-cli"></a>

要使用查看应用程序修订版，请调用****get-application-revision****命令或****list-application-revisions****命令。 AWS CLI 

**注意**  
 参考仅 GitHub 适用于 EC2/本地部署的部署。 AWS Lambda 部署修订版不适用于 GitHub。

要查看有关单个应用程序修订的详细信息，请调用 [get-application-revision](https://docs.aws.amazon.com/cli/latest/reference/deploy/get-application-revision.html) 命令，并指定：
+ 应用程序名称。要获取应用程序名称，请调用 [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) 命令。
+ 对于存储在中的修订版 GitHub， GitHub 存储库名称和引用已推送到存储库的应用程序修订的提交 ID。
+ 对于存储在 Amazon S3 中的修订版，包含修订的 Amazon S3 存储桶名称；上传的存档文件的名称和文件类型；以及可选的存档文件的 Amazon S3 版本标识符和 ETag。如果在调用期间指定了版本标识符或两者 [register-application-revision](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-application-revision.html)，则必须在此处指定这些标识符。 ETag

要查看有关多个应用程序修订的详细信息，请调用 [list-application-revisions](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-application-revisions.html) 命令，并指定：
+ 应用程序名称。要获取应用程序名称，请调用 [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) 命令。
+ （可选）要仅查看 Amazon S3 应用程序修订的详细信息，则指定包含修订的 Amazon S3 存储桶名称。
+ （可选）要仅查看 Amazon S3 应用程序修订的详细信息，则指定限制对 Amazon S3 应用程序修订的搜索的前缀字符串。（如果未指定， CodeDeploy 将列出所有匹配的 Amazon S3 应用程序版本。）
+ （可选）是否基于每个修订是否为部署组的目标修订来列出修订详细信息。（如果未指定， CodeDeploy 将列出所有匹配的修订版。）
+ （可选）列名称和对修订详细信息列表进行排序的顺序。（如果未指定， CodeDeploy 将按任意顺序列出结果。）

您可以列出所有修订或仅列出存储在 Amazon S3 中的修订。您不能只列出存储在中的修订版 GitHub。

# 在 Amazon S3 中注册应用程序修订版 CodeDeploy
<a name="application-revisions-register"></a>

如果您已调用 [push](https://docs.aws.amazon.com/cli/latest/reference/deploy/push.html) 命令将应用程序修订推送到 Amazon S3，则无需注册修订。但是，如果您通过其他方式将修订版上传到 Amazon S3，并希望修订版显示在 CodeDeploy 控制台中或通过中 AWS CLI，请先按照以下步骤注册该修订版。

如果您已将应用程序修订推送到 GitHub 存储库，并希望该修订版显示在 CodeDeploy 控制台中或通过中 AWS CLI，则还必须按照以下步骤操作。

您只能使用 AWS CLI 或在 Amazon S3 中注册应用程序修订版或 GitHub。 CodeDeploy APIs 

**Topics**
+ [使用 CodeDeploy (CLI) 在 Amazon S3 中注册修订版](#application-revisions-register-s3)
+ [在 CodeDeploy (CLI) 中 GitHub 注册修订版](#application-revisions-register-github)

## 使用 CodeDeploy (CLI) 在 Amazon S3 中注册修订版
<a name="application-revisions-register-s3"></a>

1. 将修订上传到 Amazon S3。

1. 调用 [register-application-revision](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-application-revision.html) 命令，在命令中指定：
   + 应用程序名称。要查看应用程序名称的列表，请调用 [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) 命令。
   + 有关要注册的修订的信息：
     + 包含修订的 Amazon S3 存储桶的名称。
     + 已上传修订的名称和文件类型。对于 AWS Lambda 部署，修订版是用 JSON 或 YAML 编写的 AppSpec 文件。对于 EC2/本地部署，修订版包含 CodeDeploy 将部署到您的实例的源文件版本或将在您的实例上运行的 CodeDeploy 脚本。
**注意**  
Windows Server 实例不支持 tar 和压缩的 tar 存档文件格式（.tar 和.tar.gz）。
     + （可选）修订的 Amazon S3 版本标识符。（如果未指定版本标识符， CodeDeploy 将使用最新的版本。）
     + （可选）修订版的 ETag。（如果 ETag 未指定， CodeDeploy 将跳过对象验证。）
   + （可选）您要与修订关联的任何描述。

可以在命令行中，在 **register-application-revision** 调用中使用以下语法来指定有关 Amazon S3 中修订的信息。（`version` 和 `eTag` 为可选项。）

对于 EC2/本地部署的修订文件：

```
--s3-location bucket=string,key=string,bundleType=tar|tgz|zip,version=string,eTag=string
```

要获取 AWS Lambda 部署的修订文件，请执行以下操作：

```
--s3-location bucket=string,key=string,bundleType=JSON|YAML,version=string,eTag=string
```

## 在 CodeDeploy (CLI) 中 GitHub 注册修订版
<a name="application-revisions-register-github"></a>

**注意**  
AWS Lambda 部署不适用于 GitHub。

1. 将修订版上传到您的 GitHub 存储库。

1. 调用 [register-application-revision](https://docs.aws.amazon.com/cli/latest/reference/deploy/register-application-revision.html) 命令，在命令中指定：
   + 应用程序名称。要查看应用程序名称的列表，请调用 [list-applications](https://docs.aws.amazon.com/cli/latest/reference/deploy/list-applications.html) 命令。
   + 有关要注册的修订的信息：
     + 分配给包含修订的存储库的 GitHub 用户名或组名，后跟正斜杠 (`/`)，后跟存储库名称。
     + 引用存储库中修订的提交的 ID。
   + （可选）您要与修订关联的任何描述。

 GitHub 可以在命令行中使用以下语法作为**register-application-revision**调用的一部分，在命令行上指定有关版本的信息：

```
--github-location repository=string,commitId=string
```