Skip to content

Commit 4882b4c

Browse files
fix: code
1 parent c9b38a7 commit 4882b4c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/cloudFormation.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { AwsCredentials } from './awsCredentials.js';
77
import { AwsConfiguration } from './types/awsConfiguration.js';
88
import { Logger } from './logger.js';
9+
import * as yaml from 'yaml';
910

1011
let cloudFormationClient: CloudFormationClient;
1112

@@ -30,7 +31,17 @@ async function getCloudFormationStackTemplate(
3031
throw new Error(`No template found for stack ${stackName}`);
3132
}
3233

33-
const cfTemplate = JSON.parse(response.TemplateBody);
34+
let cfTemplate: any;
35+
try {
36+
cfTemplate = JSON.parse(response.TemplateBody);
37+
} catch (parseError: any) {
38+
if (parseError.message.includes('is not valid JSON')) {
39+
// If the template is not JSON, try parsing it as YAML
40+
cfTemplate = yaml.parse(response.TemplateBody);
41+
} else {
42+
throw parseError;
43+
}
44+
}
3445
return cfTemplate;
3546
} catch (error: any) {
3647
if (error.name === 'ValidationError') {

0 commit comments

Comments
 (0)