With the various life cycle hook resources in place, the final piece of the puzzle is to create a Lambda function and associated resources that will subscribe to the life cycle hook SNS topic you defined in the previous section and will ultimately perform ECS container instance draining before signalling that the life cycle hook action can continue.
Let's first focus on the Lambda function itself and the associated source code that it will need to execute:
...
...
Resources:
LifecycleHookFunction:
Type: AWS::Lambda::Function
DependsOn:
- LifecycleHookFunctionLogGroup
Properties:
Role: !Sub ${LifecycleFunctionRole.Arn}
FunctionName: !Sub ${AWS::StackName}-lifecycleHooks
Description: !Sub ${AWS::StackName} Autoscaling Lifecycle Hook
Environment:
Variables:
ECS_CLUSTER...