CloudFormation-Stack-with-AWS-SDK-JS-V3
Creates/Deploys, Updates and Deletes AWS CloudFormation Stack with AWS SDK for JavaScript/NodeJS V3.
The script can execute the followings:
-
Uses the indicated YAML or JSON CloudFormation input file to create/deploy resources as specified in the input file.
-
Updates the deployed resources.
-
Deletes the deployed resources.
PURPOSE
-
Normally an AWS CloudFormation stack can be deployed via AWS CloudFormation console or AWS CLI.
-
An AWS CloudFormation stack can also be deployed via AWS SDK in any language of choice.
-
This repository contains code for deploying an AWS CloudFormation stack via AWS SDK for JavaScript/NodeJS V3, from any computer.
-
AWS SDK for JavaScript/NodeJS V3 is clean, light weight, fast and it fully supports async-await syntax.
-
The sample stack (keyspace.yaml file) in this repository is for creating/deploying, updating and deleting an AWS Keyspace and Tables (for Apache Cassandra), used in real-time drilling, reservoir and production applications.
DEPLOYING STACK with the NodeJS script
OPTION 1: Clone to Local Computer
AWS
, follow these steps:
To deploy the stack on -
Install NodeJS and @aws-sdk/client-cloudformation (v3) module, assuming Ubuntu OS
- curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -
- sudo apt-get install -y nodejs
- sudo npm install @aws-sdk/client-cloudformation
- curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -
-
Download or clone the following files, from this repo, into the current working directory (CWD):- NodeJS script: index.js
- JSON files: credentials.json and inputConfig.json
- CloudFormation YAML input file: keyspace.yaml
- NodeJS script: index.js
-
Fill in relevant values in inputConfig.json file.- References for inputConfig.json :
- https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudformation/interfaces/createstackcommandinput.html
- https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudformation/interfaces/deletestackcommandinput.html
- https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudformation/interfaces/updatestackcommandinput.html
- References for inputConfig.json :
-
Then run the code, assuming sudo access:- sudo node index.js
- sudo node index.js
OPTION 2: Through GitHub Actions
This option has the benefits of CICD in general. To deploy the stack via GitHub action, follow these steps:
-
Check and fill relevant values in the GitHub Actions YML deployment file.
-
Also fill relevant values in the inputConfig.json file.
- Ensure that the environment (dev, stag or prod) and region in the file correspond to the values in the GitHub Actions YML file.
- Ensure that the environment (dev, stag or prod) and region in the file correspond to the values in the GitHub Actions YML file.
-
Add the actual values for credentials to the GitHub Secrets.
- These include: accessKeyId, secretAccessKey and region.
- This prevents exposure of the credentials.
-
Then enable GitHub Actions Workflow and run the YML file.
License
Copyright © 2015 - present. MongoExpUser
Licensed under the MIT license.