Reputation: 23
I made a aws ecs fargate blue/green continuos deployment using aws codepipeline. It is working properly, but I need to have a test URL before new code version turn to prod. I enabled Test listener
option in codedeploy deployment group
then tried to run pipeline, but the test stage didn't wait nothing ... then I changed Deployment settings -> Traffic rerouting to Specify when to reroute traffic (5 minutes)
. Then tried to run pipeline again, then the test stage waited 5 minutes, then we could do the manual tests but then a new issue came after 5 minutes:
The deployment timed out while waiting for a notification to continue. This time out period is 5 minutes.
I found a possible solution using appspec.yml hooks
to tell the deployment to continue, then I created a lambda function with properly permissions and changed my appspec.yml
to:
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: "<TASK_DEFINITION>"
LoadBalancerInfo:
ContainerName: "****"
ContainerPort: 5231
Hooks:
- AfterAllowTestTraffic: "ARN_LAMBDA_FUNCTION"
Lambda function:
const aws = require('aws-sdk');
const codedeploy = new aws.CodeDeploy({apiVersion: '2014-10-06'});
exports.handler = (event, context, callback) => {
//Read the DeploymentId from the event payload.
var deploymentId = event.DeploymentId;
//Read the LifecycleEventHookExecutionId from the event payload
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
/*
Enter validation tests here.
*/
// Prepare the validation test results with the deploymentId and
// the lifecycleEventHookExecutionId for CodeDeploy.
var params = {
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
};
// Pass CodeDeploy the prepared validation test results.
codedeploy.putLifecycleEventHookExecutionStatus(params, function(err, data) {
console.log("Err => ", err);
console.log("Data => ",data);
if (err) {
// Validation failed.
callback('Validation test failed');
} else {
console.log("success!");
// Validation succeeded.
callback(null, 'Validation test succeeded');
}
});
};
Then tried to run pipeline again ... lambda function was executed and putLifecycleEventHookExecutionStatus
returned lifecycleEventHookExecutionId
, but the deployment returned the same error as above.
What am I doing wrong?
Upvotes: 0
Views: 171