-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a script to update CF template file
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
})(); |