lib/wolf_core/infrastructure/lambda_function_data_source.rb



module WolfCore
  module LambdaFunctionDataSource
    module_function

    def init
      client_config = {
        access_key_id: ENV.fetch('AWS_KEY_ID', nil),
        secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
        region: ENV.fetch('AWS_REGION', nil),
        endpoint: ENV.fetch('AWS_LAMBDA_FUNCTION_ENDPOINT', nil),
      }

      client_config = client_config.compact
      return if client_config.empty?

      @@client = Aws::Lambda::Client.new(client_config)
    end

    def client
      @@client
    end

    def invoke(function_name:, payload:)
      parsed_payload = JSON.generate(payload)
      @@client.invoke({
        function_name: function_name,
        invocation_type: 'Event',
        log_type: 'Tail',
        payload: parsed_payload
      })
    end
  end
end