Skip to content

Commit

Permalink
fix(AWS Deploy): Respect existing YAML CF templates (#11521)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgraffis committed Nov 16, 2022
1 parent c4902f3 commit 20d79a2
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js
Expand Up @@ -2,6 +2,7 @@

const ServerlessError = require('../../../../serverless-error');
const { log, progress } = require('@serverless/utils/log');
const jsyaml = require('js-yaml');

const mainProgress = progress.get('main');

Expand Down Expand Up @@ -75,15 +76,32 @@ module.exports = {
TemplateStage: 'Original',
});

const templateBody = getTemplateResult.TemplateBody
? JSON.parse(getTemplateResult.TemplateBody)
: {};
let templateBody;

if (getTemplateResult.TemplateBody) {
try {
templateBody = JSON.parse(getTemplateResult.TemplateBody);
} catch (error) {
try {
templateBody = jsyaml.load(getTemplateResult.TemplateBody);
} catch (error2) {
throw new ServerlessError(
'Could not parse CloudFormation template',
'CLOUDFORMATION_TEMPLATE_PARSE_FAILED'
);
}
}
} else {
templateBody = {};
}

if (!templateBody.Resources) {
templateBody.Resources = {};
}
if (!templateBody.Outputs) {
templateBody.Outputs = {};
}

Object.assign(
templateBody.Resources,
this.serverless.service.provider.coreCloudFormationTemplate.Resources
Expand Down

0 comments on commit 20d79a2

Please sign in to comment.