public async Task TransformTemplateAsync()

in src/Amazon.Lambda.Tools/TemplateProcessor/TemplateProcessorManager.cs [69:130]


        public async Task<string> TransformTemplateAsync(string templateDirectory, string templateBody, string[] args)
        {
            // Remove Project Location switch from arguments list since this should not be used for code base.
            string[] modifiedArguments = RemoveProjectLocationArgument(args);

            // If templateDirectory is actually pointing the CloudFormation template then grab its root.
            if (File.Exists(templateDirectory))
                templateDirectory = Path.GetDirectoryName(templateDirectory);
            
            // Maintain a cache of local paths to S3 Keys so if the same local path is referred to for
            // multiple Lambda functions it is only built and uploaded once.
            var cacheOfLocalPathsToS3Keys = new Dictionary<string, UpdateResourceResults>();
            
            var parser = CreateTemplateParser(templateBody);

            foreach(var updatableResource in parser.UpdatableResources())
            {
                this.Logger?.WriteLine($"Processing CloudFormation resource {updatableResource.Name}");

                foreach (var field in updatableResource.Fields)
                {
                    var localPath = field.GetLocalPath();
                    if (localPath == null)
                        continue;

                    UpdateResourceResults updateResults;
                    if (!cacheOfLocalPathsToS3Keys.TryGetValue(localPath, out updateResults))
                    {
                        this.Logger?.WriteLine(
                            $"Initiate packaging of {field.GetLocalPath()} for resource {updatableResource.Name}");
                        updateResults = await ProcessUpdatableResourceAsync(templateDirectory, field, modifiedArguments);
                        cacheOfLocalPathsToS3Keys[localPath] = updateResults;
                    }
                    else
                    {
                        this.Logger?.WriteLine(
                            $"Using previous upload artifact s3://{this.S3Bucket}/{updateResults.S3Key} for resource {updatableResource.Name}");
                    }

                    if(updatableResource.UploadType == CodeUploadType.Zip)
                    {
                        field.SetS3Location(this.S3Bucket, updateResults.S3Key);
                    }
                    else if(updatableResource.UploadType == CodeUploadType.Image)
                    {
                        field.SetImageUri(updateResults.ImageUri);
                    }
                    else
                    {
                        throw new LambdaToolsException($"Unknown upload type for setting resource: {updatableResource.UploadType}", LambdaToolsException.LambdaErrorCode.ServerlessTemplateParseError);
                    }

                    if (!string.IsNullOrEmpty(updateResults.DotnetShareStoreEnv))
                    {
                        field.Resource.SetEnvironmentVariable(LambdaConstants.ENV_DOTNET_SHARED_STORE, updateResults.DotnetShareStoreEnv);
                    }
                }
            }

            var newTemplate = parser.GetUpdatedTemplate();
            return newTemplate;
        }