

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

# 步驟 4：更新您的 AppSpec 檔案
<a name="tutorial-ecs-with-hooks-create-appspec-file"></a>

 在本節中，您會使用 `Hooks`區段更新 AppSpec 檔案。在 `Hooks`區段中，您可以為`AfterAllowTestTraffic`生命週期掛鉤指定 Lambda 函數。

**更新您的 AppSpec 檔案**

1.  開啟您在 中建立[步驟 2：建立 AppSpec 檔案](tutorial-ecs-create-appspec-file.md)的 AppSpec 檔案[教學課程：將應用程式部署至 Amazon ECS](tutorial-ecs-deployment.md)。

1.  使用您在[步驟 2：更新您的 Amazon ECS 應用程式](tutorial-ecs-with-hooks-update-the-ecs-application.md)中記下的任務定義 ARN 來更新 `TaskDefinition` 屬性。

1. 將 `Hooks`區段複製並貼到您的 AppSpec 檔案。`AfterAllowTestTraffic` 使用您在 中記下的 Lambda 函數 ARN，更新 之後的 ARN[步驟 3：建立 lifecycle hook Lambda 函數](tutorial-ecs-with-hooks-create-hooks.md)。

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

   ```
   {
     "version": 0.0,
     "Resources": [
       {
         "TargetService": {
           "Type": "AWS::ECS::Service",
           "Properties": {
             "TaskDefinition": "arn:aws:ecs:aws-region-id:aws-account-id::task-definition/ecs-demo-task-definition:revision-number",
             "LoadBalancerInfo": {
               "ContainerName": "sample-website",
               "ContainerPort": 80
             }
           }
         }
       }
     ],
     "Hooks": [
       {
         "AfterAllowTestTraffic": "arn:aws:lambda:aws-region-id:aws-account-id:function:AfterAllowTestTraffic"
       }
     ]
   }
   ```

------
#### [ YAML AppSpec ]

   ```
   version: 0.0
   Resources:
     - TargetService:
         Type: AWS::ECS::Service
         Properties:
           TaskDefinition: "arn:aws:ecs:aws-region-id:aws-account-id::task-definition/ecs-demo-task-definition:revision-number"
           LoadBalancerInfo:
             ContainerName: "sample-website"
             ContainerPort: 80
   Hooks:
     - AfterAllowTestTraffic: "arn:aws:lambda:aws-region-id:aws-account-id:function:AfterAllowTestTraffic"
   ```

------

1.  儲存您的 AppSpec 檔案並上傳至其 S3 儲存貯體。