Class: Jets::CLI::Functions

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cli/functions.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods included from Api

#api, #api_key

Constructor Details

This class inherits a constructor from Jets::CLI::Base

Instance Method Details

#allObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jets/cli/functions.rb', line 8

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

#nested_stack_resourcesObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jets/cli/functions.rb', line 27

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

#runObject



3
4
5
6
# File 'lib/jets/cli/functions.rb', line 3

def run
  functions = all
  puts functions.sort
end