1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 3x 3x 3x 3x 1x 6x 6x 1x 5x 5x 5x 5x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 6x 6x 14x 14x 14x 14x 14x 14x 14x 14x 14x 6x 6x 6x 6x 6x 6x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 9x 9x 8x 8x 8x 8x 18x 18x 8x 9x 9x 1x 9x 1x 9x 9x 9x 5x 9x 6x 6x 9x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 5x 9x 1x 9x 9x 9x 9x 3x 6x 2x 4x 3x 1x 1x 1x 9x 9x 9x 1x 1x 1x | 'use strict'; var inquirer = require('inquirer'); var fs = require('fs-extra'); const yamlSchema = require('../../aws-operations/mobile-yaml-schema'); const yamlOps = require('../../aws-operations/mobile-yaml-ops'); const pathManager = require('../../utils/awsmobilejs-path-manager.js') var pathLib = require('path'); var databaseOps = require('./database-ops'); var functionGeneration = require('./lib/function-generation'); const { spawnSync } = require('child_process'); var cloudLogicFolder = ''; var lambdaPackageFolder = getCloudLambdaPackagePath(); const lambdaDynamoPackageFolder = getCloudLambdaDynamoPackagePath(); // lambda function name size restriction const sizeNameLimit = 20; // save project info var _projectInfo = {} function getCloudLambdaPackagePath() { return pathLib.normalize(pathLib.join(__dirname, '../backend-templates/cloud-api/lambda-package')); } function getCloudLambdaDynamoPackagePath() { return pathLib.normalize(pathLib.join(__dirname, '../backend-templates/cloud-api/dynamo-api')); } function npmInstall(folder) { var npmInstall = spawnSync('npm', ['install'], { cwd: folder, env: process.env, stdio: ['pipe', 'pipe', 'ignore'] }); npmInstall.on('exit', function (code) { console.log('npm install process exited with code ' + code.toString()); }); } var startQuestionary = (currentDefinition) => new Promise( function (resolve, reject) { var apiDefinition = { name: '', signInRequired: false, paths: {} }; var cloudLogicDefinition = { newApi: apiDefinition, projectDefinition: currentDefinition, summary: [] }; console.log('Welcome to CloudLogic wizard'); console.log('You will be asked a series of questions to create your API'); resolve(cloudLogicDefinition); } ); var startEditing = (currentDefinition) => new Promise( function (resolve, reject) { var cloudLogicDefinition = { newApi: currentDefinition.apiDefinition, projectDefinition: currentDefinition, summary: [] }; resolve(cloudLogicDefinition); } ); var startQuestionaryDynamoApi = (currentDefinition) => new Promise( function (resolve, reject) { var cloudLogicDefinition = { newApi: currentDefinition.apiDefinition, projectDefinition: currentDefinition, summary: [] }; resolve(cloudLogicDefinition); } ); var askApiName = (cloudLogicDefinition) => { var apiNameQuestion = { type: 'input', name: 'apiName', message: 'API name', validate: function (value) { var pass = value.length > 0; let yamlDef = cloudLogicDefinition.projectDefinition.yamlDefinition; // Check if API already exists if (yamlDef.features.cloudlogic && yamlDef.features.cloudlogic.components && yamlDef.features.cloudlogic.components[value]) { return 'API ' + value + ' already exists'; } if (pass) { return true; } return 'Please enter a valid API name'; } }; return inquirer.prompt(apiNameQuestion).then(answers => { cloudLogicDefinition.newApi.name = answers.apiName; return cloudLogicDefinition; }); } var askRequiredSignIn = (cloudLogicDefinition) => { // If project has signin enabled ask if the api is only for signin users var signInEnabled = cloudLogicDefinition.projectDefinition.yamlDefinition.features['sign-in'] && cloudLogicDefinition.projectDefinition.yamlDefinition.features['sign-in']['attributes'] && cloudLogicDefinition.projectDefinition.yamlDefinition.features['sign-in']['attributes']['enabled']; if (!signInEnabled) { return Promise.resolve(cloudLogicDefinition); } else { var signInRequiredQuestion = { type: 'confirm', name: 'requiredSignin', message: 'Restrict API access to signed-in users', default: cloudLogicDefinition.newApi.signInRequired } return inquirer.prompt(signInRequiredQuestion).then(answers => { cloudLogicDefinition.newApi.signInRequired = answers.requiredSignin; return cloudLogicDefinition; }); } } var validatePathName = (name, cloudLogicDefinition) => { var err = null; if (name.length === 0 || name.substring(name.length - 1) === '/') { return 'Each sub-path must begin with a letter or number.'; } // Set / as a first character of path name if (name.substring(0, 1) !== '/') { return 'Path must begin with / e.g. /items'; } if (/[^a-zA-Z0-9\-\/]/.test(name)) { return 'You can use the following characters: a-z A-Z 0-9 - /'; } // If the are is something like /asasd//asa must be detected // Splitting the string with / to find empty sub-path let split = name.split('/'); for (let i = 1; i < split.length; i++) { let val = split[i]; if (val.length === 0) { return 'Each sub-path must begin with a letter or number'; } } // Checking if there is already that path created on the API if (cloudLogicDefinition.newApi.paths[name]) { return 'Path name already exists' } // Create subpath from the beginning to find a match on existing paths var subpath = ''; for (let i = 1; i < split.length - 1; i++) { subpath = subpath + '/' + split[i]; if (cloudLogicDefinition.newApi.paths[subpath]) { return 'A different path already matches this sub-path: ' + subpath; } } return err; } var askPaths = (cloudLogicDefinition) => { let defaultLambdaFunctionName = cloudLogicDefinition.newApi.name; Iif (defaultLambdaFunctionName.length > sizeNameLimit) { defaultLambdaFunctionName = defaultLambdaFunctionName.substring(0, sizeNameLimit); } var pathQuestions = [ { type: 'input', name: 'pathName', message: 'HTTP path name', default: '/items', validate: function (value) { var err = validatePathName(value, cloudLogicDefinition); if (err) { return err; } return true; } }, { type: 'input', name: 'functionName', message: 'Lambda function name (This will be created if it does not already exists)', default: defaultLambdaFunctionName, validate: function (value) { var pass = value.length > 0; if (pass) { return true; } if (value.length > sizeNameLimit) { return 'Please enter a shorter function name (Max length ' + sizeNameLimit + ')' } if (/[^a-zA-Z0-9]/.test(name)) { return 'You can use the following characters: a-z A-Z 0-9'; } return 'Please enter a valid function name'; } }, { type: 'confirm', name: 'addAnotherPath', message: 'Add another HTTP path', default: false } ]; return inquirer.prompt(pathQuestions).then(answers => { var path = { name: answers.functionName, codeFilename: 'uploads/' + answers.functionName + '.zip', handler: 'lambda.handler', enableCORS: true, runtime: 'nodejs6.10', environment: {} }; cloudLogicDefinition.newApi.paths[answers.pathName] = path; cloudLogicDefinition.newApi.paths[answers.pathName + '/{proxy+}'] = path; Iif (answers.addAnotherPath) { return askPaths(cloudLogicDefinition); } return (cloudLogicDefinition); }); } var addApi = (cloudLogicDefinition) => { cloudLogicDefinition.projectDefinition.cloudlogic.apis[cloudLogicDefinition.newApi.name] = cloudLogicDefinition.newApi; // Create folder for each lambda function Object.keys(cloudLogicDefinition.newApi.paths).map(pathKey => { let path = cloudLogicDefinition.newApi.paths[pathKey]; cloudLogicFolder = pathLib.join(_projectInfo.ProjectPath, 'awsmobilejs/backend/cloud-api') var functionFolder = pathLib.join(cloudLogicFolder, path.name) + '/'; Eif (!fs.existsSync(functionFolder)) { fs.mkdirSync(functionFolder); console.log('Adding lambda function code on: \n' + functionFolder); functionGeneration.createLambdaFunctionFolder(lambdaPackageFolder, functionFolder, pathKey); console.log('To test the api from the command line (after awsmobile push) use this commands'); console.log('awsmobile cloud-api invoke', cloudLogicDefinition.newApi.name, '<method> <path> [init]'); } }); // Update yaml with api configuration let yaml = createYamlStructure(cloudLogicDefinition.projectDefinition); let backendProjectYamlFilePath = pathManager.getBackendSpecProjectYmlFilePath(_projectInfo.ProjectPath); yamlOps.writeYamlFileSync(yaml, backendProjectYamlFilePath); // printing all info about the api cloudLogicDefinition.summary.map(text => { console.log(text); }) cloudLogicDefinition.yamlDefinition = yaml; return cloudLogicDefinition; } const checktableNotValid = (table) => { // Tables with binary or binary stream are not supported yet let status = null; Object.keys(table.attributes).map(attrKey => { const attrType = databaseOps.getTypeCode(table.attributes[attrKey]); Iif (attrType === 'BS' || attrType === 'B') { status = 'Currently crud API generation is not supporting binary types, column ' + attrKey; } }); return status; } var addDynamoApi = (cloudLogicDefinition) => { return new Promise(function (resolve, reject) { const table_name = cloudLogicDefinition.projectDefinition.table_name; const tableNotValid = checktableNotValid(cloudLogicDefinition.projectDefinition.nosql.tables[table_name]); Iif (tableNotValid) { reject(tableNotValid); } cloudLogicDefinition.projectDefinition.cloudlogic.apis[cloudLogicDefinition.newApi.name] = cloudLogicDefinition.newApi; const hasUserId = !cloudLogicDefinition.projectDefinition.nosql.tables[table_name].write; // Create folder for each lambda function Object.keys(cloudLogicDefinition.newApi.paths).map(pathKey => { cloudLogicFolder = pathLib.join(_projectInfo.ProjectPath, 'awsmobilejs/backend/cloud-api') let path = cloudLogicDefinition.newApi.paths[pathKey]; var functionFolder = pathLib.join(cloudLogicFolder, path.name) + '/'; Eif (!fs.existsSync(functionFolder)) { fs.mkdirSync(functionFolder); console.log('Adding lambda function code on: \n' + functionFolder); functionGeneration.createLambdaFunctionCrudApi(lambdaDynamoPackageFolder, functionFolder, cloudLogicDefinition, path, table_name, hasUserId); console.log('To test the api from the command line (after awsmobile push) use this commands'); console.log('awsmobile cloud-api invoke', cloudLogicDefinition.newApi.name, '<method> <path> [init]'); } }); // Update yaml with api configuration let yaml = createYamlStructure(cloudLogicDefinition.projectDefinition); let backendProjectYamlFilePath = pathManager.getBackendSpecProjectYmlFilePath(_projectInfo.ProjectPath); yamlOps.writeYamlFileSync(yaml, backendProjectYamlFilePath); // printing all info about the api cloudLogicDefinition.summary.map(text => { console.log(text); }) cloudLogicDefinition.yamlDefinition = yaml; resolve(cloudLogicDefinition); }); } var createYamlStructure = (projectDefinition) => { var apis = {}; Object.keys(projectDefinition.cloudlogic.apis).map(apiKey => { let api = projectDefinition.cloudlogic.apis[apiKey] var attributes = { name: api.name, 'requires-signin': api.signInRequired }; var paths = {}; Object.keys(api.paths).map(pathKey => { let path = api.paths[pathKey]; paths[pathKey] = new yamlSchema.dressObject({ name: path.name, codeFilename: path.codeFilename, handler: path.handler, enableCORS: path.enableCORS, runtime: path.runtime, environment: path.environment, 'backend-class': 'Function' }); }); apis[api.name] = new yamlSchema.dressObject({ attributes, paths, 'backend-class': 'API' } ); }); // In case the feature was not enabled projectDefinition['yamlDefinition']['features']['cloudlogic'] = new yamlSchema.dressObject({ components: apis, 'backend-class': 'CloudLogic' }); if (Object.keys(projectDefinition['yamlDefinition']['features']['cloudlogic']['components']).length === 0) { delete projectDefinition['yamlDefinition']['features']['cloudlogic']; } return projectDefinition['yamlDefinition']; } var createApiJsonStructure = (yamlDefinition) => { var jsonApiStructure = {}; var components = {}; if (yamlDefinition['features'] && yamlDefinition['features']['cloudlogic'] && yamlDefinition['features']['cloudlogic']['components']) { components = yamlDefinition['features']['cloudlogic']['components']; } Object.keys(components).map(apiKey => { var currentApi = { name: apiKey, signInRequired: components[apiKey]['attributes']['requires-signin'], paths: components[apiKey]['paths'] } jsonApiStructure[apiKey] = currentApi; }); return jsonApiStructure; } function createApi(currentDefinition) { return new Promise(function (resolve, reject) { startQuestionary(currentDefinition) .then(askApiName) .then(askRequiredSignIn) .then(askPaths) .then(addApi) .then(resolve) .catch(reject); }); } function deleteApi(currentDefinition) { var apiList = Array.from(Object.keys(currentDefinition.cloudlogic.apis)); Iif (apiList.length === 0) { console.log('No API left'); return; } var deleteQuestion = [ { type: 'list', name: 'apiKey', message: 'Select API to be deleted', choices: apiList }, { type: 'confirm', name: 'confirmDelete', message: 'Are you sure you want to delete the API', default: false }]; return inquirer.prompt(deleteQuestion).then(answers => { Iif (!answers.confirmDelete) { console.log('No API deleted'); } else { delete currentDefinition.cloudlogic.apis[answers.apiKey]; let yaml = createYamlStructure(currentDefinition); let backendProjectYamlFilePath = pathManager.getBackendSpecProjectYmlFilePath(_projectInfo.ProjectPath); yamlOps.writeYamlFileSync(yaml, backendProjectYamlFilePath); currentDefinition.yamlDefinition = yaml; return currentDefinition; } }); } function deletePath(cloudLogicDefinition) { var pathList = Array.from(Object.keys(cloudLogicDefinition.newApi.paths)); var deleteQuestion = [ { type: 'list', name: 'pathKey', message: 'Select Path to be deleted', choices: pathList }, { type: 'confirm', name: 'confirmPathDelete', message: 'Are you sure you want to delete the Path', default: false }]; return inquirer.prompt(deleteQuestion).then(answers => { if (!answers['confirmPathDelete']) { Promise.reject('No Path deleted'); } else { delete cloudLogicDefinition.newApi.paths[answers['pathKey']]; return (cloudLogicDefinition); } }); } function editApi(currentDefinition) { return new Promise(function (resolve, reject) { var apiList = Array.from(Object.keys(currentDefinition.cloudlogic.apis)); Iif (apiList.length === 0) { console.log('No API left'); return; } let optionsChoices = [ { name: 'Add path', value: 'add-path' }, { name: 'Remove path', value: 'remove-path' } ]; const signInEnabled = currentDefinition.yamlDefinition.features['sign-in'] && currentDefinition.yamlDefinition.features['sign-in']['attributes'] && currentDefinition.yamlDefinition.features['sign-in']['attributes']['enabled']; Eif (signInEnabled) { optionsChoices.push({ name: 'Configure API access to signed-in users', value: 'signed-in' }); } var editQuestion = [ { type: 'list', name: 'apiKeyEdit', message: 'Select API to be edited', choices: apiList }, { type: 'list', name: 'editOptions', message: 'Select from one of the choices below.', choices: optionsChoices } ]; return inquirer.prompt(editQuestion).then(answers => { currentDefinition.apiDefinition = currentDefinition.cloudlogic.apis[answers.apiKeyEdit]; if (answers['editOptions'] === 'signed-in') { resolve(editSignInRestriction(currentDefinition)); } else Eif (answers['editOptions'] === 'add-path') { resolve(addPathExistingApi(currentDefinition)); } else if (answers['editOptions'] === 'remove-path') { resolve(deletePathExistingApi(currentDefinition)); } }); }); } function deletePathExistingApi(currentDefinition) { return new Promise(function (resolve, reject) { startEditing(currentDefinition) .then(deletePath) .then(addApi) .then(resolve); }); } function editSignInRestriction(currentDefinition) { return new Promise(function (resolve, reject) { startEditing(currentDefinition) .then(askRequiredSignIn) .then(addApi) .then(resolve); }); } function addPathExistingApi(currentDefinition) { return new Promise(function (resolve, reject) { startEditing(currentDefinition) .then(askPaths) .then(addApi) .then(resolve); }); } function dynamoApi(currentDefinition) { return new Promise(function (resolve, reject) { var tableList = Array.from(Object.keys(currentDefinition.nosql.tables)); var dynamoApiQuestion = [ { type: 'list', name: 'dynamoKey', message: 'Select Amazon DynamoDB table to connect to a CRUD API', choices: tableList }]; return inquirer.prompt(dynamoApiQuestion).then(answers => { var prefixApiName = answers.dynamoKey; Iif (currentDefinition.cloudlogic.apis[prefixApiName + 'CRUD']) { console.log('Api already exists: ' + prefixApiName + 'CRUD'); return; } var apiDefinition = { name: prefixApiName + 'CRUD', signInRequired: false, paths: {} } var lambdaFunctionName = prefixApiName.replace(/\-/g, ''); lambdaFunctionName = lambdaFunctionName.replace(/\./g, ''); lambdaFunctionName = lambdaFunctionName.replace(/\_/g, ''); Iif (lambdaFunctionName.length > sizeNameLimit) { lambdaFunctionName = lambdaFunctionName.substring(lambdaFunctionName.length - sizeNameLimit); } apiDefinition.paths['/' + prefixApiName] = { name: lambdaFunctionName, codeFilename: 'uploads/' + lambdaFunctionName + '.zip', handler: 'lambda.handler', enableCORS: true, runtime: 'nodejs6.10', environment: {} } apiDefinition.paths['/' + prefixApiName + '/{proxy+}'] = { name: lambdaFunctionName, codeFilename: 'uploads/' + lambdaFunctionName + '.zip', handler: 'lambda.handler', enableCORS: true, runtime: 'nodejs6.10', environment: {} } currentDefinition.apiDefinition = apiDefinition; currentDefinition.table_name = answers.dynamoKey; resolve(dynamoApi2(currentDefinition)); }); }); } function dynamoApi2(currentDefinition) { return new Promise(function (resolve, reject) { startQuestionaryDynamoApi(currentDefinition) .then(askRequiredSignIn) .then(addDynamoApi) .then(resolve); }); } function main() { return new Promise(function (resolve, reject) { var currentDefinition = { cloudlogic: { apis: {} }, yamlDefinition: {}, nosql: {} } let backendProjectYamlFilePath = pathManager.getBackendSpecProjectYmlFilePath(_projectInfo.ProjectPath); let yamlDefinition = yamlOps.readYamlFileSync(backendProjectYamlFilePath); currentDefinition.cloudlogic.apis = createApiJsonStructure(yamlDefinition); currentDefinition.nosql.tables = databaseOps.createTableJsonStructure(yamlDefinition); currentDefinition.yamlDefinition = yamlDefinition; // No Api on the project always add /*if (Object.keys(currentDefinition.cloudlogic.apis).length === 0) { return createApi(currentDefinition); }*/ let optionsChoices = [ { name: 'Create a new API', value: 'add' } ]; if (Object.keys(currentDefinition.cloudlogic.apis).length > 0) { optionsChoices.push({ name: 'Remove an API from the project', value: 'del' }, { name: 'Edit an API from the project', value: 'edit' }); } if (Object.keys(currentDefinition.nosql.tables).length > 0) { optionsChoices.push({ name: 'Create CRUD API for an existing Amazon DynamoDB table', value: 'dynamo' }); } var optionsQuestion = { type: 'list', name: 'apiOptions', message: 'Select from one of the choices below.', choices: optionsChoices }; console.log("\n\n" + "This feature will create an API using Amazon API Gateway and AWS Lambda. You can optionally have the lambda function perform CRUD operations against your Amazon DynamoDB table." + "\n\n"); return inquirer.prompt(optionsQuestion).then(answers => { if (answers.apiOptions === 'add') { resolve(createApi(currentDefinition)); } else if (answers.apiOptions === 'del') { resolve(deleteApi(currentDefinition)); } else if (answers.apiOptions === 'edit') { resolve(editApi(currentDefinition)); } else Eif (answers.apiOptions === 'dynamo') { resolve(dynamoApi(currentDefinition)); } }); }); } exports.specify = function (projectInfo) { _projectInfo = JSON.parse(JSON.stringify(projectInfo)); // clone projectInfo return new Promise(function (resolve, reject) { main() .then(resolve) .catch(reject); }) } exports.onFeatureTurnOn = function (projectInfo, cloudProjectSpec) { _projectInfo = projectInfo cloudLogicFolder = pathLib.join(projectInfo.ProjectPath, 'awsmobilejs/backend/cloud-api') let pathKey = '/items'; var functionFolder = pathLib.join(cloudLogicFolder, 'sampleLambda') + '/'; if (!fs.existsSync(functionFolder)) { fs.mkdirSync(functionFolder); console.log('Adding lambda function code on \n' + functionFolder + '\n'); functionGeneration.createLambdaFunctionFolder(lambdaPackageFolder, functionFolder, pathKey); console.log('\nTo test the api from the command line (after awsmobile push) use this commands'); console.log('awsmobile cloud-api invoke', 'sampleCloudApi', '<method> /items [init]\n\n'); } } exports.onFeatureTurnOff = function (projectInfo, cloudProjectSpec) { _projectInfo = JSON.parse(JSON.stringify(projectInfo)); // clone projectInfo } exports.invoke = function (projectInfo, args) { const invokeApi = require('./cloud-api/invoke'); _projectInfo = JSON.parse(JSON.stringify(projectInfo)); // clone projectInfo cloudLogicFolder = pathLib.join(projectInfo.ProjectPath, 'awsmobilejs/backend/cloud-api') invokeApi.invoke(projectInfo, args); } |