Guest User

Untitled

a guest
Jun 18th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. const { config, STS } = require("aws-sdk");
  2. const { execSync } = require("child_process");
  3.  
  4. const sts = new STS();
  5.  
  6. if (!config.region) {
  7. console.log("Set `$AWS_REGION` environment variable.");
  8. process.exit(1);
  9. }
  10.  
  11. let Bucket;
  12.  
  13. sts
  14. .getCallerIdentity()
  15. .promise()
  16. .then(callerIdentity => {
  17. process.env["AWS_DEFAULT_REGION"] = config.region;
  18.  
  19. Bucket = `cfn.${callerIdentity.Account}.${config.region}`;
  20.  
  21. const packageCommand = [
  22. "aws",
  23. "cloudformation",
  24. "package",
  25. "--template-file",
  26. "template.cfn.json",
  27. "--s3-bucket",
  28. Bucket,
  29. "--output-template-file",
  30. ".cfn/packaged.json",
  31. "--use-json"
  32. ].join(" ");
  33.  
  34. console.log(packageCommand);
  35. execSync(packageCommand, { stdio: "inherit" });
  36.  
  37. const deployCommand = [
  38. "aws",
  39. "cloudformation",
  40. "deploy",
  41. "--template-file",
  42. ".cfn/packaged.json",
  43. "--capabilities",
  44. "CAPABILITY_IAM",
  45. "--stack-name",
  46. require("../package.json").name
  47. ].join(" ");
  48.  
  49. console.log(deployCommand);
  50. execSync(deployCommand, { stdio: "inherit" });
  51. })
  52. .catch(error => {
  53. console.log(error);
  54. process.exit(1);
  55. });
Add Comment
Please, Sign In to add comment