Sha256: 15836b0055d94a70542c6069fba18d98a6f6ed3e0fa237013db7587653f7dfe5

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

class Jets::CLI
  class Functions < Base
    def run
      functions = all
      puts functions.sort
    end

    def all
      functions = []
      nested_stack_resources.each do |resource|
        stack_name = resource.physical_resource_id
        # Custom resource stacks may not have output with function name.
        # So use describe_stack_resources to get the function names.
        resources = cfn.describe_stack_resources(stack_name: stack_name).stack_resources
        resources.each do |r|
          if r.resource_type == "AWS::Lambda::Function"
            functions << r.physical_resource_id if r.physical_resource_id # race condition. can be nil for a brief moment while provisioning
          end
        end
      end
      unless @options[:full]
        functions = functions.map { |f| f.sub("#{Jets.project.namespace}-", "") }
      end
      functions
    end

    def nested_stack_resources
      stack_name = Jets::Names.parent_stack_name
      resp = cfn.describe_stack_resources(stack_name: stack_name)
      resp.stack_resources.select { |r| r.resource_type == "AWS::CloudFormation::Stack" }
    rescue Aws::CloudFormation::Errors::ValidationError => e
      if e.message.include?("does not exist")
        abort "The stack #{stack_name} does not exist.  Have you deployed yet?".color(:red)
      else
        raise
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/cli/functions.rb
jets-6.0.4 lib/jets/cli/functions.rb
jets-6.0.3 lib/jets/cli/functions.rb
jets-6.0.2 lib/jets/cli/functions.rb