lib/jets/commands/call/base_guesser.rb in jets-1.9.23 vs lib/jets/commands/call/base_guesser.rb in jets-1.9.24

- old
+ new

@@ -3,10 +3,12 @@ # method_name # error_message # class Jets::Commands::Call class BaseGuesser + include Jets::AwsServices + # provided_function_name: # admin/related_pages_controller-list_all # admin-related-pages-controller-list-all def initialize(provided_function_name) @provided_function_name = provided_function_name @@ -26,8 +28,33 @@ # and dont want the namespace to be included twice @provided_function_name = @provided_function_name.sub("#{Jets.config.project_namespace}-", "") code_path = class_name.underscore.gsub('/','-') function_name = [Jets.config.project_namespace, code_path, method_name].join('-') + generated_function_name(function_name) + end + + def generated_function_name(function_name) + if function_name.size > Jets::MAX_FUNCTION_NAME_SIZE # name generated by CloudFormation + logical_id = @class_name.gsub('::','') + app_stack_arn = lookup(parent_stack[:outputs], logical_id) + + resources = stack_resources(app_stack_arn) + resource = resources.find { |r| r.logical_resource_id == method_name.camelize + "LambdaFunction" } # method_name only contains the method + resource.physical_resource_id # actual function name + else + function_name + end + end + + # Class variable caches + @@stack_resources = {} + def stack_resources(stack_name) + @@stack_resources[stack_name] ||= cfn.describe_stack_resources(stack_name: stack_name).stack_resources + end + + @@parent_stack = nil + def parent_stack + @@parent_stack ||= cfn.describe_stacks(stack_name: Jets::Naming.parent_stack_name).stacks.first end end end