we have ECS commands running in our Pipeline to deploy a Drupal 8 website. We have added commands like this to our CDK code. We have about 5 commands like this running in the CDK code. We execute these commands using Lambda.
'use strict';
const AWS = require('aws-sdk');
const ecs = new AWS.ECS();
const codeDeploy = new AWS.CodeDeploy({ apiVersion: '2014-10-06' });
exports.handler = async (event, context, callback) => {
console.log('Drush execution lambda invoked');
const deploymentId = event.DeploymentId;
const lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
try{
let validationTestResult = 'Failed';
const clusterName = process.env.CLUSTER_NAME;
const containerName = process.env.CONTAINER_NAME;
const taskListParams = {
cluster: clusterName,
desiredStatus: 'RUNNING',
};
const taskList = await ecs.listTasks(taskListParams).promise();
const activeTask = taskList.taskArns[0];
console.log('Active task: ' + activeTask);
.......................
const cimParams = {
command: 'drush cim -y',
interactive: true,
task: activeTask,
cluster: clusterName,
container: containerName
};
await ecs.executeCommand(cimParams, function (err, data) {
if (err) {
console.log(err, err.stack, "FAILED on drush cim -y");
} else {
validationTestResult = 'Succeeded';
console.log(data, "Succeeded on drush cim -y");
}
}).promise();
.............................
// Pass CodeDeploy the prepared validation test results.
await codeDeploy.putLifecycleEventHookExecutionStatus({
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: validationTestResult // status can be 'Succeeded' or 'Failed'
}).promise();
}catch (e) {
console.log(e);
console.log('Drush execution lambda failed');
await codeDeploy.putLifecycleEventHookExecutionStatus({
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Failed' // status can be 'Succeeded' or 'Failed'
}).promise();
}
};
The problem we have is when these commands are executed it says successful, but, we still can't see the changes on the website. If we run the pipeline again for the second time, the changes will be applied successfully.
The commands are not showing any errors or not failing the pipeline, but, the changes will only apply to the site if the pipeline was executed twice.
We are not sure if this is a Drupal/Drush or an ECS issue at this stage.
When we realized that the changes are not applying for the first time, we SSH into the ECS container and manually executed the command drush cim -y
and it applied the changes to the site when we did that. So that tells us this is probably not an issue with the command, but, the ECS execution?
Can anyone see if we are doing anything wrong here ?. Is there a known issue with CDK or ECS commands like this ?.
Most importantly if someone can tell us how to debug ECS commands correctly, that would be great. Because the current level of logs we are having is not enough to find where the problem is.
Thanks in advance for taking the time to read this question.