Class: Lambda::MicroVMs::FunctionClient
- Inherits:
-
Object
- Object
- Lambda::MicroVMs::FunctionClient
- Defined in:
- lib/lambda/microvms/function_client.rb
Overview
Thin wrapper over stable Aws::Lambda::Client function APIs.
Instance Attribute Summary collapse
-
#sdk ⇒ Object
readonly
Returns the value of attribute sdk.
Instance Method Summary collapse
-
#create_function(name:, role_arn:, handler:, runtime:, zip_file:, **params) ⇒ Object
Create a Lambda function from a zip file using supported AWS APIs.
-
#initialize(region: nil, profile: nil, sdk: nil) ⇒ FunctionClient
constructor
A new instance of FunctionClient.
-
#invoke(function_name:, payload: nil, **params) ⇒ Object
Invoke a Lambda function and parse JSON payloads when possible.
-
#update_function_code(function_name:, zip_file:, **params) ⇒ Object
Update Lambda function code from a zip file.
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
#sdk ⇒ Object (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.
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.
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.
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 |