- Newest
- Most votes
- Most comments
The issue with your lifecycle hook Lambda function is related to the response format. When using lifecycle hooks with Amazon ECS blue/green deployments, the Lambda function must return a specific response structure.
Based on the error message "HookStatus must not be null," it appears that ECS is not correctly parsing the response from your Lambda function. The correct response format should be a JSON object with a hookStatus key that has one of these values: SUCCEEDED, FAILED, or IN_PROGRESS.
Your code is almost correct, but there are a few potential issues:
-
Make sure your Lambda function has enough execution time. Since you're sleeping for 120 seconds, ensure your Lambda timeout is set to more than 2 minutes.
-
The response format should be exactly as follows:
{
"hookStatus": "SUCCEEDED"
}
-
Unlike CodeDeploy hooks which require calling
PutLifecycleEventHookExecutionStatus(), ECS blue/green deployments use the direct Lambda response to determine the hook status. -
If you want to implement a polling mechanism, you can return
"hookStatus": "IN_PROGRESS"along with an optionalcallBackDelayto specify when ECS should invoke your function again (default is 30 seconds if not specified).
Also, ensure that your ECS service has the proper IAM permissions to invoke the Lambda function. The IAM role needs the lambda:InvokeFunction permission for your Lambda function.
If you're still experiencing issues, try simplifying your Lambda function to just return the success status without any sleep or try/catch blocks to isolate the problem:
def lambda_handler(event, context):
return {"hookStatus": "SUCCEEDED"}
Sources
Lifecycle hooks for Amazon ECS service deployments - Amazon Elastic Container Service
Permissions required for Lambda functions in Amazon ECS blue/green deployments - Amazon Elastic Container Service
Migrate CodeDeploy blue/green deployments to Amazon ECS blue/green deployments - Amazon Elastic Container Service
Lambda timeout was set to less than my execution time, hence getting stopped early and no return code.
Relevant content
- asked 10 months ago
- asked 2 years ago
- asked 2 years ago
