From 949052a38f5f2760c96c0a3bfc293c672e8a42ad Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Tue, 10 Oct 2023 11:48:12 +0200 Subject: [PATCH] chore: add a script to update CF template file --- scripts/updateDeployTemplateInS3.js | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/updateDeployTemplateInS3.js diff --git a/scripts/updateDeployTemplateInS3.js b/scripts/updateDeployTemplateInS3.js new file mode 100644 index 00000000000..7907f2d7a9b --- /dev/null +++ b/scripts/updateDeployTemplateInS3.js @@ -0,0 +1,34 @@ +const S3 = require("aws-sdk/clients/s3"); +const yargs = require("yargs"); +const fs = require("fs"); +const path = require("path"); + +const args = yargs.argv; + +if (!args.source) { + console.error(`Please specify a "--source" parameter!`); + process.exit(1); +} + +(async () => { + const s3 = new S3({ region: process.env["AWS_REGION"] ?? "us-east-1" }); + const templateKey = "cloudformation/DEPLOY_WEBINY_PROJECT_CF_TEMPLATE.yaml"; + + const fileSource = path.resolve(args.source); + + console.log(`Updating key: ${templateKey}`); + console.log(`Source file: ${fileSource}`); + const newBody = fs.readFileSync(fileSource, "utf8"); + + const bucket = "webiny-public"; + const config = { Bucket: bucket, Key: templateKey, Body: newBody, ACL: "public-read" }; + + console.log(`Uploading to "${bucket}" bucket...`); + try { + await s3.putObject(config).promise(); + console.log(`\nSUCCESS: File was updated!`); + } catch (err) { + console.error(`\nERROR: ${err.message}`); + process.exit(1); + } +})();