|
| 1 | +const nodeCloud = require("../../lib"); |
| 2 | +const optionsProvider = { |
| 3 | + overrideProviders: false |
| 4 | +}; |
| 5 | +const ncProviders = nodeCloud.getProviders(optionsProvider); |
| 6 | +const options = { |
| 7 | + apiVersion: "2010-12-01" |
| 8 | +}; |
| 9 | + |
| 10 | +const beanstalkModule = ncProviders.aws.PaaS(options); |
| 11 | + |
| 12 | +function createApp() { |
| 13 | + const applicationDetails = { |
| 14 | + ApplicationName: "node-cloud-app", |
| 15 | + Description: "Node cloud platform as a service" |
| 16 | + }; |
| 17 | + |
| 18 | + beanstalkModule.create(applicationDetails).then( |
| 19 | + result => { |
| 20 | + console.log("Output : ", result); |
| 21 | + }, |
| 22 | + error => { |
| 23 | + console.error("Error :", error); |
| 24 | + } |
| 25 | + ); |
| 26 | +} |
| 27 | + |
| 28 | +function createAppEnvironment() { |
| 29 | + const environmentDetails = { |
| 30 | + ApplicationName: "node-cloud-app", |
| 31 | + CNAMEPrefix: "node-cloud-app", |
| 32 | + EnvironmentName: "node-cloud-app-env", |
| 33 | + SolutionStackName: "64bit Amazon Linux 2018.03 v2.9.10 running Python 3.6" |
| 34 | + }; |
| 35 | + |
| 36 | + beanstalkModule.createEnvironment(environmentDetails).then( |
| 37 | + result => { |
| 38 | + console.log("Output : ", result); |
| 39 | + }, |
| 40 | + error => { |
| 41 | + console.error("Error :", error); |
| 42 | + } |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +function deleteEnvironment() { |
| 47 | + const environmentDetails = { |
| 48 | + EnvironmentName: "node-cloud-app-env" |
| 49 | + }; |
| 50 | + |
| 51 | + beanstalkModule.terminateEnvironment(environmentDetails).then( |
| 52 | + result => { |
| 53 | + console.log("Output : ", result); |
| 54 | + }, |
| 55 | + error => { |
| 56 | + console.error("Error :", error); |
| 57 | + } |
| 58 | + ); |
| 59 | +} |
| 60 | + |
| 61 | +function deleteApp() { |
| 62 | + const appDetails = { |
| 63 | + ApplicationName: "node-cloud-app" |
| 64 | + }; |
| 65 | + |
| 66 | + beanstalkModule.delete(appDetails).then( |
| 67 | + result => { |
| 68 | + console.log("Output : ", result); |
| 69 | + }, |
| 70 | + error => { |
| 71 | + console.error("Error :", error); |
| 72 | + } |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +function updateAppDescription() { |
| 77 | + const appDetails = { |
| 78 | + ApplicationName: "node-cloud-app", |
| 79 | + Description: "with love Node cloud" |
| 80 | + }; |
| 81 | + |
| 82 | + beanstalkModule.update(appDetails).then( |
| 83 | + result => { |
| 84 | + console.log("Output : ", result); |
| 85 | + }, |
| 86 | + error => { |
| 87 | + console.error("Error :", error); |
| 88 | + } |
| 89 | + ); |
| 90 | +} |
| 91 | + |
| 92 | +function updateAppEnvironment() { |
| 93 | + var environmentDetails = { |
| 94 | + EnvironmentName: "node-cloud-app-env", |
| 95 | + OptionSettings: [ |
| 96 | + { |
| 97 | + Namespace: "aws:elb:healthcheck", |
| 98 | + OptionName: "Interval", |
| 99 | + Value: "15" |
| 100 | + } |
| 101 | + ] |
| 102 | + }; |
| 103 | + beanstalkModule.updateEnvironment(environmentDetails).then( |
| 104 | + result => { |
| 105 | + console.log("Output : ", result); |
| 106 | + }, |
| 107 | + error => { |
| 108 | + console.error("Error :", error); |
| 109 | + } |
| 110 | + ); |
| 111 | +} |
| 112 | + |
| 113 | +function getApplications() { |
| 114 | + const apps = { |
| 115 | + ApplicationNames: ["node-cloud-app"] |
| 116 | + }; |
| 117 | + beanstalkModule.describe(apps).then( |
| 118 | + result => { |
| 119 | + console.log("Output : ", result); |
| 120 | + }, |
| 121 | + error => { |
| 122 | + console.error("Error :", error); |
| 123 | + } |
| 124 | + ); |
| 125 | +} |
| 126 | + |
| 127 | +function getPlatformVersions() { |
| 128 | + const params = { |
| 129 | + Filters: [{ Type: "PlatformStatus", Operator: "=", Values: ["Ready"] }] |
| 130 | + }; |
| 131 | + |
| 132 | + beanstalkModule.listVersions(params).then( |
| 133 | + result => { |
| 134 | + console.log("Output : ", result); |
| 135 | + }, |
| 136 | + error => { |
| 137 | + console.error("Error :", error); |
| 138 | + } |
| 139 | + ); |
| 140 | +} |
| 141 | + |
| 142 | +function restartApp() { |
| 143 | + const params = { |
| 144 | + EnvironmentName: "node-cloud-app-env" |
| 145 | + }; |
| 146 | + |
| 147 | + beanstalkModule.restart(params).then( |
| 148 | + result => { |
| 149 | + console.log("Output : ", result); |
| 150 | + }, |
| 151 | + error => { |
| 152 | + console.error("Error :", error); |
| 153 | + } |
| 154 | + ); |
| 155 | +} |
| 156 | + |
| 157 | +function rebuildEnv() { |
| 158 | + const params = { |
| 159 | + EnvironmentName: "node-cloud-app-env" |
| 160 | + }; |
| 161 | + |
| 162 | + beanstalkModule.rebuildEnvironment(params).then( |
| 163 | + result => { |
| 164 | + console.log("Output : ", result); |
| 165 | + }, |
| 166 | + error => { |
| 167 | + console.error("Error :", error); |
| 168 | + } |
| 169 | + ); |
| 170 | +} |
| 171 | + |
| 172 | +function getEvents() { |
| 173 | + const params = { |
| 174 | + EnvironmentName: "node-cloud-app-env" |
| 175 | + }; |
| 176 | + |
| 177 | + beanstalkModule.describeEvents(params).then( |
| 178 | + result => { |
| 179 | + console.log("Output : ", result); |
| 180 | + }, |
| 181 | + error => { |
| 182 | + console.error("Error :", error); |
| 183 | + } |
| 184 | + ); |
| 185 | +} |
| 186 | + |
| 187 | +function getConfigDetails() { |
| 188 | + const appData = { |
| 189 | + ApplicationName: "node-cloud-app", |
| 190 | + EnvironmentName: "node-cloud-app-env" |
| 191 | + }; |
| 192 | + |
| 193 | + beanstalkModule.describeConfigSettings(appData).then( |
| 194 | + result => { |
| 195 | + console.log("Output : ", result); |
| 196 | + }, |
| 197 | + error => { |
| 198 | + console.error("Error :", error); |
| 199 | + } |
| 200 | + ); |
| 201 | +} |
| 202 | + |
| 203 | +function getAccountAttributes() { |
| 204 | + // sends attributes related to AWS Elastic Beanstalk that are associated with the calling AWS account |
| 205 | + beanstalkModule.describeAccountAttributes().then( |
| 206 | + result => { |
| 207 | + console.log("Output : ", result); |
| 208 | + }, |
| 209 | + error => { |
| 210 | + console.error("Error :", error); |
| 211 | + } |
| 212 | + ); |
| 213 | +} |
| 214 | + |
| 215 | +function composeEnv() { |
| 216 | + const params = { |
| 217 | + ApplicationName: "node-cloud-app", |
| 218 | + VersionLabels: ["v1"] |
| 219 | + }; |
| 220 | + |
| 221 | + beanstalkModule.composeEnvironments(params).then( |
| 222 | + result => { |
| 223 | + console.log("Output : ", result); |
| 224 | + }, |
| 225 | + error => { |
| 226 | + console.error("Error :", error); |
| 227 | + } |
| 228 | + ); |
| 229 | +} |
| 230 | + |
| 231 | +function checkDNS() { |
| 232 | + const params = { |
| 233 | + CNAMEPrefix: "e-ihtb3is3yb" // CNAME of Application URL |
| 234 | + }; |
| 235 | + |
| 236 | + beanstalkModule.checkDNSAvailability(params).then( |
| 237 | + result => { |
| 238 | + console.log("Output : ", result); |
| 239 | + }, |
| 240 | + error => { |
| 241 | + console.error("Error :", error); |
| 242 | + } |
| 243 | + ); |
| 244 | +} |
| 245 | + |
| 246 | +function createStorageBucket() { |
| 247 | + /* Creating a bucket in Amazon S3 to store application versions, logs, and other files |
| 248 | + used by Elastic Beanstalk environments. If the storage location already exists it will return |
| 249 | + the bucket name but does not create a new bucket.*/ |
| 250 | + beanstalkModule.createStorageLocation({}).then( |
| 251 | + result => { |
| 252 | + console.log("Output : ", result); |
| 253 | + }, |
| 254 | + error => { |
| 255 | + console.error("Error :", error); |
| 256 | + } |
| 257 | + ); |
| 258 | +} |
| 259 | + |
| 260 | +function createConfigTemplate() { |
| 261 | + const params = { |
| 262 | + ApplicationName: "node-cloud-app", |
| 263 | + TemplateName: "test-template", |
| 264 | + EnvironmentId: "e-trsu5mk6aw", |
| 265 | + Description: "Testing config template", |
| 266 | + Tags: [ |
| 267 | + { |
| 268 | + Key: "project", |
| 269 | + Value: "NodeCloud" |
| 270 | + } |
| 271 | + ] |
| 272 | + }; |
| 273 | + |
| 274 | + beanstalkModule.createConfigTemplate(params).then( |
| 275 | + result => { |
| 276 | + console.log("Output : ", result); |
| 277 | + }, |
| 278 | + error => { |
| 279 | + console.error("Error :", error); |
| 280 | + } |
| 281 | + ); |
| 282 | +} |
| 283 | + |
| 284 | +function deleteConfigTemplate() { |
| 285 | + const params = { |
| 286 | + ApplicationName: "node-cloud-app", |
| 287 | + TemplateName: "test-template" |
| 288 | + }; |
| 289 | + |
| 290 | + beanstalkModule.deleteConfigTemplate(params).then( |
| 291 | + result => { |
| 292 | + console.log("Output : ", result); |
| 293 | + }, |
| 294 | + error => { |
| 295 | + console.error("Error :", error); |
| 296 | + } |
| 297 | + ); |
| 298 | +} |
0 commit comments