Skip to content

Commit 31fa6d3

Browse files
committed
Add execution error handling using OperationId from LastOperations
1 parent b6efc22 commit 31fa6d3

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

dist/index.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50330,6 +50330,7 @@ function cleanupChangeSet(cfn, stack, params, failOnEmptyChangeSet, noDeleteFail
5033050330
}
5033150331
function updateStack(cfn, stack, params, failOnEmptyChangeSet, noExecuteChangeSet, noDeleteFailedChangeSet) {
5033250332
return __awaiter(this, void 0, void 0, function* () {
50333+
var _a, _b, _c, _d;
5033350334
core.debug('Creating CloudFormation Change Set');
5033450335
const createResponse = yield cfn.send(new client_cloudformation_1.CreateChangeSetCommand(params));
5033550336
try {
@@ -50339,7 +50340,7 @@ function updateStack(cfn, stack, params, failOnEmptyChangeSet, noExecuteChangeSe
5033950340
StackName: params.StackName
5034050341
});
5034150342
}
50342-
catch (_a) {
50343+
catch (_e) {
5034350344
core.debug('Change set creation waiter failed, getting change set info anyway');
5034450345
// Still try to get change set info even if waiter failed
5034550346
const changeSetInfo = yield getChangeSetInfo(cfn, params.ChangeSetName, params.StackName);
@@ -50358,14 +50359,32 @@ function updateStack(cfn, stack, params, failOnEmptyChangeSet, noExecuteChangeSe
5035850359
StackName: params.StackName
5035950360
}));
5036050361
core.debug('Updating CloudFormation stack');
50361-
yield waitUntilStackOperationComplete({
50362-
client: cfn,
50363-
maxWaitTime: 43200,
50364-
minDelay: 10,
50365-
changeSetId: changeSetInfo.changeSetId
50366-
}, {
50367-
StackName: params.StackName
50368-
});
50362+
try {
50363+
yield waitUntilStackOperationComplete({
50364+
client: cfn,
50365+
maxWaitTime: 43200,
50366+
minDelay: 10,
50367+
changeSetId: changeSetInfo.changeSetId
50368+
}, {
50369+
StackName: params.StackName
50370+
});
50371+
}
50372+
catch (error) {
50373+
// Get execution failure details using OperationId
50374+
const stackResponse = yield cfn.send(new client_cloudformation_1.DescribeStacksCommand({ StackName: params.StackName }));
50375+
const executionOp = (_c = (_b = (_a = stackResponse.Stacks) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.LastOperations) === null || _c === void 0 ? void 0 : _c.find(op => op.OperationType === 'UPDATE_STACK' || op.OperationType === 'CREATE_STACK');
50376+
if (executionOp === null || executionOp === void 0 ? void 0 : executionOp.OperationId) {
50377+
const eventsResponse = yield cfn.send(new client_cloudformation_1.DescribeEventsCommand({
50378+
OperationId: executionOp.OperationId,
50379+
Filters: { FailedEvents: true }
50380+
}));
50381+
if ((_d = eventsResponse.OperationEvents) === null || _d === void 0 ? void 0 : _d.length) {
50382+
const failureEvent = eventsResponse.OperationEvents[0];
50383+
throw new Error(`Stack execution failed: ${failureEvent.ResourceStatusReason || failureEvent.ResourceStatus}`);
50384+
}
50385+
}
50386+
throw error;
50387+
}
5036950388
return { stackId: stack.StackId };
5037050389
});
5037150390
}

src/deploy.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,38 @@ export async function updateStack(
345345
)
346346

347347
core.debug('Updating CloudFormation stack')
348-
await waitUntilStackOperationComplete(
349-
{
350-
client: cfn,
351-
maxWaitTime: 43200,
352-
minDelay: 10,
353-
changeSetId: changeSetInfo.changeSetId
354-
},
355-
{
356-
StackName: params.StackName!
348+
try {
349+
await waitUntilStackOperationComplete(
350+
{
351+
client: cfn,
352+
maxWaitTime: 43200,
353+
minDelay: 10,
354+
changeSetId: changeSetInfo.changeSetId
355+
},
356+
{
357+
StackName: params.StackName!
358+
}
359+
)
360+
} catch (error) {
361+
// Get execution failure details using OperationId
362+
const stackResponse = await cfn.send(new DescribeStacksCommand({ StackName: params.StackName! }))
363+
const executionOp = stackResponse.Stacks?.[0]?.LastOperations?.find(op =>
364+
op.OperationType === 'UPDATE_STACK' || op.OperationType === 'CREATE_STACK'
365+
)
366+
367+
if (executionOp?.OperationId) {
368+
const eventsResponse = await cfn.send(new DescribeEventsCommand({
369+
OperationId: executionOp.OperationId,
370+
Filters: { FailedEvents: true }
371+
}))
372+
373+
if (eventsResponse.OperationEvents?.length) {
374+
const failureEvent = eventsResponse.OperationEvents[0]
375+
throw new Error(`Stack execution failed: ${failureEvent.ResourceStatusReason || failureEvent.ResourceStatus}`)
376+
}
357377
}
358-
)
378+
throw error
379+
}
359380

360381
return { stackId: stack.StackId }
361382
}

0 commit comments

Comments
 (0)