Class: Lambda

Inherits:
Mapper show all
Defined in:
lib/aws_recon/collectors/lambda.rb

Overview

Collect Lambda resources

Constant Summary

Constants inherited from Mapper

Mapper::SINGLE_REGION_SERVICES

Instance Method Summary collapse

Methods inherited from Mapper

#initialize

Constructor Details

This class inherits a constructor from Mapper

Instance Method Details

#collectObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aws_recon/collectors/lambda.rb', line 7

def collect
  resources = []

  #
  # list_functions
  #
  @client.list_functions.each_with_index do |response, page|
    log(response.context.operation_name, page)

    response.functions.each do |function|
      struct = OpenStruct.new(function)
      struct.type = 'function'
      struct.arn = function.function_arn
      struct.vpc_config = function.vpc_config.to_h
      struct.tracing_config = function.tracing_config.to_h
      struct.layers = function.layers ? function.layers.map(&:to_h) : []
      struct.policy = @client.get_policy({ function_name: function.function_name }).policy.parse_policy

    rescue Aws::Lambda::Errors::ResourceNotFoundException => e
      log_error(e.code)
    ensure
      resources.push(struct.to_h)
    end
  end

  #
  # list_layers
  #
  @client.list_layers.each_with_index do |response, page|
    log(response.context.operation_name, page)

    response.layers.each do |layer|
      struct = OpenStruct.new(layer)
      struct.type = 'layer'
      struct.arn = layer.layer_arn
      struct.latest_matching_version = layer.latest_matching_version.to_h

      # list_layer_versions
      struct.versions = @client.list_layer_versions({ layer_name: layer.layer_name }).layer_versions.map(&:to_h)
      log(response.context.operation_name, 'list_layer_versions')

      resources.push(struct.to_h)
    end
  end

  resources
end