Class: Lambda::MicroVMs::FunctionClient

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda/microvms/function_client.rb

Overview

Thin wrapper over stable Aws::Lambda::Client function APIs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region: nil, profile: nil, sdk: nil) ⇒ FunctionClient

Returns a new instance of FunctionClient.



11
12
13
# File 'lib/lambda/microvms/function_client.rb', line 11

def initialize(region: nil, profile: nil, sdk: nil, **)
  @sdk = sdk || build_sdk(region: region, profile: profile, **)
end

Instance Attribute Details

#sdkObject (readonly)

Returns the value of attribute sdk.



9
10
11
# File 'lib/lambda/microvms/function_client.rb', line 9

def sdk
  @sdk
end

Instance Method Details

#create_function(name:, role_arn:, handler:, runtime:, zip_file:, **params) ⇒ Object

Create a Lambda function from a zip file using supported AWS APIs.

Parameters:

  • name (String)

    function name

  • role_arn (String)

    IAM role ARN

  • handler (String)

    handler name

  • runtime (String)

    Lambda runtime identifier

  • zip_file (String)

    path to deployment zip

  • params (Hash)

    additional create_function parameters

Returns:

  • (Object)

    raw SDK response



24
25
26
27
28
29
30
31
32
33
# File 'lib/lambda/microvms/function_client.rb', line 24

def create_function(name:, role_arn:, handler:, runtime:, zip_file:, **params) # rubocop:disable Metrics/ParameterLists
  sdk.create_function(
    **params,
    function_name: name,
    role: role_arn,
    handler: handler,
    runtime: runtime,
    code: { zip_file: File.binread(zip_file) }
  )
end

#invoke(function_name:, payload: nil, **params) ⇒ Object

Invoke a Lambda function and parse JSON payloads when possible.

Parameters:

  • function_name (String)

    function name or ARN

  • payload (Object) (defaults to: nil)

    request payload

  • params (Hash)

    additional invoke parameters

Returns:

  • (Object)

    parsed response payload or raw response body



51
52
53
54
# File 'lib/lambda/microvms/function_client.rb', line 51

def invoke(function_name:, payload: nil, **params)
  response = sdk.invoke(**params, function_name: function_name, payload: encode_payload(payload))
  parse_payload(response.payload)
end

#update_function_code(function_name:, zip_file:, **params) ⇒ Object

Update Lambda function code from a zip file.

Parameters:

  • function_name (String)

    function name or ARN

  • zip_file (String)

    path to deployment zip

  • params (Hash)

    additional update_function_code parameters

Returns:

  • (Object)

    raw SDK response



41
42
43
# File 'lib/lambda/microvms/function_client.rb', line 41

def update_function_code(function_name:, zip_file:, **params)
  sdk.update_function_code(**params, function_name: function_name, zip_file: File.binread(zip_file))
end