From 65d9ecba5b11d100b24c60cef143337673d4695b Mon Sep 17 00:00:00 2001 From: Sachin Panemangalore Date: Wed, 3 Nov 2021 19:16:32 -0700 Subject: [PATCH] addressed PR comments --- .../identify-walkthrough.js | 18 +++++++++--------- .../service-walkthroughs/s3-resource-api.ts | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/amplify-category-predictions/provider-utils/awscloudformation/prediction-category-walkthroughs/identify-walkthrough.js b/packages/amplify-category-predictions/provider-utils/awscloudformation/prediction-category-walkthroughs/identify-walkthrough.js index b20c98594ef..d35ca9bf218 100644 --- a/packages/amplify-category-predictions/provider-utils/awscloudformation/prediction-category-walkthroughs/identify-walkthrough.js +++ b/packages/amplify-category-predictions/provider-utils/awscloudformation/prediction-category-walkthroughs/identify-walkthrough.js @@ -1,8 +1,9 @@ +import { JSONUtilities, stateManager, pathManager } from 'amplify-cli-core'; import { addTextractPolicies, generateLambdaAccessForRekognition, generateStorageAccessForRekognition, - removeTextractPolicies, + removeTextractPolicies } from '../assets/identifyCFNGenerate'; import identifyAssets from '../assets/identifyQuestions'; import regionMapper from '../assets/regionMapping'; @@ -14,7 +15,7 @@ import { invokeS3GetResourceName, invokeS3GetUserInputs, invokeS3RegisterAdminTrigger, - invokeS3RemoveAdminLambdaTrigger, + invokeS3RemoveAdminLambdaTrigger } from './storage-api'; const { ResourceDoesNotExistError, ResourceAlreadyExistsError, exitOnNextTick } = require('amplify-cli-core'); const inquirer = require('inquirer'); @@ -508,15 +509,14 @@ async function postCFNGenUpdateLambdaResourceInPredictions(context, predictionsR `${predictionsResourceName}-template.json`, ); let identifyCFNFile; - identifyCFNFile = context.amplify.readJsonFile(identifyCFNFilePath); + identifyCFNFile = JSONUtilities.readJson(identifyCFNFilePath); identifyCFNFile = generateLambdaAccessForRekognition(identifyCFNFile, functionName, s3ResourceName); - const identifyCFNString = JSON.stringify(identifyCFNFile, null, 4); - fs.writeFileSync(identifyCFNFilePath, identifyCFNString, 'utf8'); + const indentifyCFNFile = JSON.stringify(identifyCFNFile, null, 4); + JSONUtilities.writeJson(identifyCFNFilePath, indentifyCFNFile); - const amplifyMetaFilePath = path.join(projectBackendDirPath, amplifyMetaFilename); - const amplifyMetaFile = context.amplify.readJsonFile(amplifyMetaFilePath); - const dependsOnResources = amplifyMetaFile.predictions[predictionsResourceName].dependsOn; + const amplifyMeta = stateManager.getMeta(); + const dependsOnResources = amplifyMeta.predictions[predictionsResourceName].dependsOn; dependsOnResources.push({ category: functionCategory, resourceName: functionName, @@ -533,7 +533,7 @@ async function postCFNGenUpdateLambdaResourceInPredictions(context, predictionsR } async function createNewFunction(context, predictionsResourceName, s3ResourceName) { - const targetDir = context.amplify.pathManager.getBackendDirPath(); + const targetDir = pathManager.getBackendDirPath(); const [shortId] = uuid().split('-'); const functionName = `RekognitionIndexFacesTrigger${shortId}`; const pluginDir = __dirname; diff --git a/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/s3-resource-api.ts b/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/s3-resource-api.ts index 9beb922600f..bf264e8b346 100644 --- a/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/s3-resource-api.ts +++ b/packages/amplify-category-storage/src/provider-utils/awscloudformation/service-walkthroughs/s3-resource-api.ts @@ -136,7 +136,6 @@ export async function s3RemoveStorageLambdaTrigger(context: $TSContext, s3Resour s3ResourceName: string, adminLambdaTrigger: S3UserInputTriggerFunctionParams, ) { - console.log("s3RegisterAdminTrigger : s3ResourceName: ", s3ResourceName , " adminLambdaTrigger: ", adminLambdaTrigger ); let cliInputsState = new S3InputState(s3ResourceName, undefined); //Check if migration is required if (!cliInputsState.cliInputFileExists()) {