Class: Cucloud::LambdaUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/cucloud/lambda_utils.rb

Overview

LambdaUtils - Utilities for woking with Lambda functions

Instance Method Summary collapse

Constructor Details

#initialize(lambda_client = Aws::Lambda::Client.new) ⇒ LambdaUtils

Constructor for LambdaUtils class

Parameters:

  • lambda_client (Aws::Lambda::Client) (defaults to: Aws::Lambda::Client.new)

    AWS Lambda SDK Client



8
9
10
# File 'lib/cucloud/lambda_utils.rb', line 8

def initialize(lambda_client = Aws::Lambda::Client.new)
  @lambda = lambda_client
end

Instance Method Details

#download_source_for_function(function_name, path = '/tmp', version = '$LATEST') ⇒ String

Download the source pacakge for a given lambda function

Parameters:

  • function_name (String)

    Name of the lambda function

  • path (String) (defaults to: '/tmp')

    Local path to write the source pacakge to, defaults to /tmp

  • version (String) (defaults to: '$LATEST')

    Version of the function to download, defaults to $LATEST

Returns:

  • (String)

    Local path to the file



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cucloud/lambda_utils.rb', line 17

def download_source_for_function(function_name, path = '/tmp', version = '$LATEST')
  lambda_function = @lambda.get_function(function_name: function_name,
                                         qualifier: version)

  file_path = path + '/' + function_name + version + '.zip'
  File.open(file_path, 'wb') do |saved_file|
    open(lambda_function[:code][:location], 'rb') do |read_file|
      saved_file.write(read_file.read)
    end
  end
  file_path
end

#get_all_function_names_for_account_regionArray

Return all funtion names for an account

Returns:

  • (Array)

    Array of strings representing the function names



40
41
42
43
# File 'lib/cucloud/lambda_utils.rb', line 40

def 
  funtions_response = @lambda.list_functions
  funtions_response.functions.map { |x| x[:function_name] }
end

#get_all_versions_for_function(function_name) ⇒ Array

Return all versions of a lambda function

Parameters:

  • function_name (String)

    Name of the lambda function

Returns:

  • (Array)

    Array of strings representing the versions of the lambda function



33
34
35
36
# File 'lib/cucloud/lambda_utils.rb', line 33

def get_all_versions_for_function(function_name)
  version_response = @lambda.list_versions_by_function(function_name: function_name)
  version_response.versions.map { |x| x[:version] }
end