private static void ProcessYamlServerlessTemplateResourcesBased()

in Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/Runtime/LambdaDefaultsConfigFileParser.cs [202:259]


        private static void ProcessYamlServerlessTemplateResourcesBased(LambdaConfigInfo configInfo, YamlMappingNode resources)
        {
            if (resources == null)
                return;

            foreach (var resource in resources.Children)
            {
                var resourceBody = (YamlMappingNode) resource.Value;
                var type = resourceBody.Children.ContainsKey("Type")
                    ? ((YamlScalarNode) resourceBody.Children["Type"])?.Value
                    : null;


                if (!string.Equals("AWS::Serverless::Function", type, StringComparison.Ordinal) &&
                    !string.Equals("AWS::Lambda::Function", type, StringComparison.Ordinal))
                {
                    continue;
                }

                var properties = resourceBody.Children.ContainsKey("Properties")
                    ? resourceBody.Children["Properties"] as YamlMappingNode
                    : null;
                if (properties == null)
                {
                    continue;
                }

                string handler = null;
                if(properties.Children.ContainsKey("Handler"))
                {
                    handler = ((YamlScalarNode)properties.Children["Handler"])?.Value;
                }

                if (string.IsNullOrEmpty(handler) && properties.Children.ContainsKey("ImageConfig"))
                {
                    var imageConfigNode = properties.Children["ImageConfig"] as YamlMappingNode;
                    if (imageConfigNode.Children.ContainsKey("Command"))
                    {
                        var imageCommandNode = imageConfigNode.Children["Command"] as YamlSequenceNode;
                        // Grab the first element assuming that is the function handler.
                        var en = imageCommandNode.GetEnumerator();
                        en.MoveNext();
                        handler = ((YamlScalarNode)en.Current)?.Value;
                    }
                }

                if (!string.IsNullOrEmpty(handler))
                {
                    var functionInfo = new LambdaFunctionInfo
                    {
                        Name = resource.Key.ToString(),
                        Handler = handler
                    };

                    configInfo.FunctionInfos.Add(functionInfo);
                }
            }
        }