

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

# 第 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 文件文件中。采用您在[步骤 3：创建生命周期挂钩 Lambda 函数](tutorial-ecs-with-hooks-create-hooks.md)中记下的 Lambda 函数的 ARN，在 `AfterAllowTestTraffic` 之后更新 ARN。

------
#### [ 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 存储桶。