

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 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 檔案相同。
+ AppSpec 檔案可以使用 JSON 或 YAML 撰寫。
+ AppSpec 檔案可以儲存為文字檔案，或在建立部署時直接輸入主控台。如需詳細資訊，請參閱[建立 Amazon ECS 運算平台部署 （主控台）](deployments-create-console-ecs.md)。

**建立 AppSpec 檔案**

1. 將 JSON 或 YAML 範本複製到文字編輯器或主控台中的 AppSpec 編輯器中。

1. 可視需要修改範本。

1. 使用 JSON 或 YAML 驗證器來驗證您的 AppSpec 檔案。如果您使用 AppSpec 編輯器，則會在您選擇 **Create deployment (建立部署)** 時驗證檔案。

1. 如果您是使用文字編輯器，請儲存該檔案。如果您使用 AWS CLI 建立部署，請在您的硬碟或 Amazon S3 儲存貯體中參考 AppSpec 檔案。如果您使用 主控台，則必須將 AppSpec 檔案推送至 Amazon S3。

### Amazon ECS 部署的 YAML AppSpec 檔案範本，內含說明
<a name="app-spec-template-yaml-ecs"></a>

以下是 AppSpec 檔案的 YAML 範本，用於具有所有可用選項的 Amazon ECS 部署。如需在 `hooks` 區段中使用之生命週期事件的相關資訊，請參閱[Amazon ECS 部署的 AppSpec 'hooks' 區段](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
```

### Amazon ECS 部署範本的 JSON AppSpec 檔案
<a name="app-spec-template-json-ecs"></a>

以下是 AppSpec 檔案的 JSON 範本，適用於具有所有可用選項的 Amazon ECS 部署。如需範本指示，請參閱上一節中 YAML 版本的註釋。如需在 `hooks` 區段中使用之生命週期事件的相關資訊，請參閱[Amazon ECS 部署的 AppSpec 'hooks' 區段](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>

針對 Lambda AWS 運算平台的部署：
+ AppSpec 檔案包含有關要部署和用於部署驗證的 Lambda 函數的說明。
+ 修訂版與 AppSpec 檔案相同。
+ AppSpec 檔案可以使用 JSON 或 YAML 撰寫。
+ AppSpec 檔案可以儲存為文字檔案，或在建立部署時直接輸入主控台 AppSpec 編輯器。如需詳細資訊，請參閱[建立 AWS Lambda 運算平台部署 （主控台）](deployments-create-console-lambda.md)。

若要建立 AppSpec 檔案：

1. 將 JSON 或 YAML 範本複製到文字編輯器或主控台中的 AppSpec 編輯器中。

1. 可視需要修改範本。

1. 使用 JSON 或 YAML 驗證器來驗證您的 AppSpec 檔案。如果您使用 AppSpec 編輯器，則會在您選擇 **Create deployment (建立部署)** 時驗證檔案。

1. 如果您是使用文字編輯器，請儲存該檔案。如果您使用 AWS CLI 建立部署，請在您的硬碟或 Amazon S3 儲存貯體中參考 AppSpec 檔案。如果您使用 主控台，則必須將 AppSpec 檔案推送至 Amazon S3。



### 部署的 YAML AppSpec 檔案範本 AWS Lambda ，內含說明
<a name="app-spec-template-yaml-lambda"></a>

如需在關聯區段中使用生命週期事件的資訊，請參閱 [AWS Lambda 部署的 AppSpec 'hooks' 區段](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 部署範本的 JSON AppSpec 檔案
<a name="app-spec-template-json-lambda"></a>

在下列範本中，將 "MyFunction" 替換為您的 AWS Lambda 函數名稱。在選用的關聯區段中，將生命週期事件替換為 BeforeAllowTraffic 或 AfterAllowTraffic。

如需在關聯區段中使用生命週期事件的資訊，請參閱 [AWS Lambda 部署的 AppSpec 'hooks' 區段](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)。

### EC2/現場部署的 AppSpec 檔案範本，內含說明
<a name="app-spec-template-server"></a>

**注意**  
 部署至 Windows Server 執行個體不支援 `runas`元素。如果您要部署到 Windows Server 執行個體，請勿將其包含在 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 編輯器內的文字。如需詳細資訊，請參閱[建立 AWS Lambda 運算平台部署 （主控台）](deployments-create-console-lambda.md)及[建立 Amazon ECS 運算平台部署 （主控台）](deployments-create-console-ecs.md)。
  +  如果您使用 AWS CLI，您可以參考硬碟或網路磁碟機上的 AppSpec 檔案。如需詳細資訊，請參閱[建立 AWS Lambda 運算平台部署 (CLI)](deployments-create-lambda-cli.md)及[建立 Amazon ECS 運算平台部署 (CLI)](deployments-create-ecs-cli.md)。

CodeDeploy 目前支援下列儲存庫類型：


|  |  |  | 
| --- |--- |--- |
| 儲存庫類型 | 儲存庫詳細資訊 | 支援的運算平台 | 
| Amazon Simple Storage Service (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_tw/codedeploy/latest/userguide/application-revisions-repository-type.html) | 使用下列運算平台的部署可以將修訂版存放在 Amazon S3 儲存貯體中。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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_tw/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) `111122223333` 可讓 AWS 帳戶將檔案上傳至名為 的 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 儲存貯體的許可。例如，以下政策允許使用者在名為 的 Amazon S3 儲存貯體中的任何位置上傳修訂`amzn-s3-demo-bucket`：

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

****  

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

------

若要了解如何建立和連接 IAM 政策，請參閱[使用政策](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** (字串) 選用。用於總結應用程式修訂的評論。如果未指定，則會使用預設字串 "Uploaded by AWS CLI 'time' UTC"，其中 'time' 是國際標準時間 (UTC) 的目前系統時間。

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

在 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 您的帳戶註冊指定應用程式的所有應用程式修訂的詳細資訊。

如需註冊修訂的詳細資訊，請參閱[使用 CodeDeploy 在 Amazon S3 中註冊應用程式修訂版](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：//[https://console.aws.amazon.com/codedeploy](https://console.aws.amazon.com/codedeploy) 開啟 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>

若要使用 AWS CLI 來檢視應用程式修訂版，請呼叫 ****get-application-revision****命令或 ****list-application-revisions****命令。

**注意**  
 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 中的修訂。

# 使用 CodeDeploy 在 Amazon S3 中註冊應用程式修訂版
<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 或 CodeDeploy APIs 在 Amazon S3 或 GitHub 中註冊應用程式修訂版。

**Topics**
+ [在 Amazon S3 中向 CodeDeploy (CLI) 註冊修訂版](#application-revisions-register-s3)
+ [在 GitHub 中向 CodeDeploy (CLI) 註冊修訂](#application-revisions-register-github)

## 在 Amazon S3 中向 CodeDeploy (CLI) 註冊修訂版
<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 會略過物件驗證。)
   + 您希望將其與修訂建立關聯的任何描述。

可以在命令列上指定 Amazon S3 中修訂的相關資訊，使用此語法做為**register-application-revision**呼叫的一部分。(`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
```

## 在 GitHub 中向 CodeDeploy (CLI) 註冊修訂
<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，此 ID 會參考儲存庫中的修訂。
   + 您希望將其與修訂建立關聯的任何描述。

可以在命令列上，使用此語法做為 **register-application-revision** 呼叫的一部分，來指定 GitHub 中修訂的資訊：

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