class Fog::AWS::Lambda::Real

Attributes

region[R]

Public Class Methods

new(options={}) click to toggle source

Initialize connection to Lambda

Notes

options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection

Examples

lambda = Lambda.new(
 :aws_access_key_id => your_aws_access_key_id,
 :aws_secret_access_key => your_aws_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

Returns

# File lib/fog/aws/lambda.rb, line 83
def initialize(options={})
  @use_iam_profile    = options[:use_iam_profile]
  @connection_options = options[:connection_options] || {}
  @instrumentor       = options[:instrumentor]
  @instrumentor_name  = options[:instrumentor_name] || 'fog.aws.lambda'

  options[:region] ||= 'us-east-1'
  @region = options[:region]
  @host = options[:host] || "lambda.#{options[:region]}.amazonaws.com"

  @path       = options[:path]        || '/'
  @persistent = options[:persistent]  || false
  @port       = options[:port]        || 443
  @scheme     = options[:scheme]      || 'https'
  @version    = options[:version]     || '2015-03-31'
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)

  setup_credentials(options)
end

Public Instance Methods

add_permission(params={}) click to toggle source

Adds a permission to the access policy associated with the specified AWS Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html

Parameters

  • FunctionName <~String> - Name of the Lambda function whose access policy you are updating by adding a new permission.

  • Action <~String> - AWS Lambda action you want to allow in this statement.

  • Principal <~String> - principal who is getting this permission.

  • SourceAccount <~String> - AWS account ID (without a hyphen) of the source owner.

  • SourceArn <~String> - Amazon Resource Name (ARN) of the source resource to assign permissions.

  • StatemendId. <~String> - unique statement identifier.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'Statement' <~Hash> - permission statement you specified in the request.

# File lib/fog/aws/requests/lambda/add_permission.rb, line 20
def add_permission(params={})
  function_name  = params.delete('FunctionName')
  action         = params.delete('Action')
  principal      = params.delete('Principal')
  source_account = params.delete('SourceAccount')
  source_arn     = params.delete('SourceArn')
  sid            = params.delete('StatementId')

  permission = {
    'Action'      => action,
    'Principal'   => principal,
    'StatementId' => sid
  }
  permission['SourceAccount'] = source_account if source_account
  permission['SourceArn']     = source_arn     if source_arn

  request({
    :method  => 'POST',
    :path    => "/functions/#{function_name}/versions/HEAD/policy",
    :expects => 201,
    :body    => Fog::JSON.encode(permission),
    :parser  => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
create_event_source_mapping(params={}) click to toggle source

Identifies a stream as an event source for a Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_CreateEventSourceMapping.html

Parameters

  • BatchSize <~Integer> - largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.

  • Enabled <~Boolean> - indicates whether AWS Lambda should begin polling the event source.

  • EventSourceArn <~String> - Amazon Resource Name (ARN) of the stream that is the event source

  • FunctionName <~String> - Lambda function to invoke when AWS Lambda detects an event on the stream.

  • StartingPosition <~String> - position in the stream where AWS Lambda should start reading.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'BatchSize' <~Integer> - largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.

      • 'EventSourceArn' <~String> - Amazon Resource Name (ARN) of the stream that is the source of events.

      • 'FunctionArn' <~String> - Lambda function to invoke when AWS Lambda detects an event on the stream.

      • 'LastModified' <~Time> - UTC time string indicating the last time the event mapping was updated.

      • 'LastProcessingResult' <~String> - result of the last AWS Lambda invocation of your Lambda function.

      • 'State' <~String> - state of the event source mapping.

      • 'StateTransitionReason' <~String> - reason the event source mapping is in its current state.

      • 'UUID' <~String> - AWS Lambda assigned opaque identifier for the mapping.

# File lib/fog/aws/requests/lambda/create_event_source_mapping.rb, line 24
def create_event_source_mapping(params={})
  enabled          = params.delete('Enabled')
  batch_size       = params.delete('BatchSize')
  event_source_arn = params.delete('EventSourceArn')
  function_name    = params.delete('FunctionName')
  starting_pos     = params.delete('StartingPosition')

  data = {
    'EventSourceArn'   => event_source_arn,
    'FunctionName'     => function_name,
    'StartingPosition' => starting_pos
  }
  data.merge!('BatchSize' => batch_size) if batch_size
  data.merge!('Enabled'   => enabled)    if !enabled.nil?

  request({
    :method  => 'POST',
    :path    => '/event-source-mappings/',
    :expects => 202,
    :body    => Fog::JSON.encode(data)
  }.merge(params))
end
create_function(params={}) click to toggle source

Creates a new Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html

Parameters

  • Code <~Hash> - code for the Lambda function.

  • Description <~String> - short, user-defined function description.

  • FunctionName <~String> - name you want to assign to the function you are uploading.

  • Handler <~String> - function within your code that Lambda calls to begin execution.

  • MemorySize <~Integer> - amount of memory, in MB, your Lambda function is given.

  • Role <~String> - ARN of the IAM role that Lambda assumes when it executes your function to access any other AWS resources.

  • Runtime <~String> - runtime environment for the Lambda function you are uploading.

  • Timeout <~Integer> - function execution time at which Lambda should terminate the function.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'CodeSize' <~Integer> - size, in bytes, of the function .zip file you uploaded.

      • 'Description' <~String> - user-provided description.

      • 'FunctionArn' <~String> - Amazon Resource Name (ARN) assigned to the function.

      • 'FunctionName' <~String> - name of the function.

      • 'Handler' <~String> - function Lambda calls to begin executing your function.

      • 'LastModified' <~Time> - timestamp of the last time you updated the function.

      • 'MemorySize' <~Integer> - memory size, in MB, you configured for the function.

      • 'Role' <~String> - ARN of the IAM role that Lambda assumes when it executes your function to access any other AWS resources.

      • 'Runtime' <~String> - runtime environment for the Lambda function.

      • 'Timeout' <~Integer> - function execution time at which Lambda should terminate the function.

# File lib/fog/aws/requests/lambda/create_function.rb, line 31
def create_function(params={})
  runtime       = params.delete('Runtime') || 'nodejs'
  code          = params.delete('Code')
  function_name = params.delete('FunctionName')
  handler       = params.delete('Handler')
  role          = params.delete('Role')

  data = {
    'Runtime'      => runtime,
    'Code'         => code,
    'FunctionName' => function_name,
    'Handler'      => handler,
    'Role'         => role
  }

  description = params.delete('Description')
  data.merge!('Description' => description) if description

  memory_size = params.delete('MemorySize')
  data.merge!('MemorySize' => memory_size)  if memory_size

  timeout = params.delete('Timeout')
  data.merge!('Timeout' => timeout) if timeout

  request({
    :method  => 'POST',
    :path    => '/functions',
    :expects => 201,
    :body    => Fog::JSON.encode(data),
    :parser  => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
delete_event_source_mapping(params={}) click to toggle source

Removes an event source mapping. docs.aws.amazon.com/lambda/latest/dg/API_DeleteEventSourceMapping.html

Parameters

  • UUID <~String> - event source mapping ID.

Returns

  • response<~Excon::Response>:

    • body<~String>:

# File lib/fog/aws/requests/lambda/delete_event_source_mapping.rb, line 13
def delete_event_source_mapping(params={})
  mapping_id = params.delete('UUID')
  request({
    :method  => 'DELETE',
    :path    => "/event-source-mappings/#{mapping_id}",
    :expects => 202
  }.merge(params))
end
delete_function(params={}) click to toggle source

Deletes the specified Lambda function code and configuration. docs.aws.amazon.com/lambda/latest/dg/API_DeleteFunction.html

Parameters

  • FunctionName <~String> - Lambda function to delete.

Returns

  • response<~Excon::Response>:

    • body<~String>:

# File lib/fog/aws/requests/lambda/delete_function.rb, line 13
def delete_function(params={})
  function_name = params.delete('FunctionName')
  request({
    :method  => 'DELETE',
    :path    => "/functions/#{function_name}",
    :expects => 204
  }.merge(params))
end
get_event_source_mapping(params={}) click to toggle source

Returns configuration information for the specified event source mapping. docs.aws.amazon.com/lambda/latest/dg/API_GetEventSourceMapping.html

Parameters

  • UUID <~String> - AWS Lambda assigned ID of the event source mapping.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'BatchSize' <~Integer> - largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.

      • 'EventSourceArn' <~String> - Amazon Resource Name (ARN) of the stream that is the source of events.

      • 'FunctionArn' <~String> - Lambda function to invoke when AWS Lambda detects an event on the stream.

      • 'LastModified' <~Time> - UTC time string indicating the last time the event mapping was updated.

      • 'LastProcessingResult' <~String> - result of the last AWS Lambda invocation of your Lambda function.

      • 'State' <~String> - state of the event source mapping.

      • 'StateTransitionReason' <~String> - reason the event source mapping is in its current state.

      • 'UUID' <~String> - AWS Lambda assigned opaque identifier for the mapping.

      • 'Code' <~Hash> - object for the Lambda function location.

      • 'Configuration' <~Hash> - function metadata description.

# File lib/fog/aws/requests/lambda/get_event_source_mapping.rb, line 22
def get_event_source_mapping(params={})
  mapping_id = params.delete('UUID')
  request({
    :method  => 'GET',
    :path    => "/event-source-mappings/#{mapping_id}"
  }.merge(params))
end
get_function(params={}) click to toggle source

Returns the configuration information of the Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html

Parameters

  • FunctionName <~String> - Lambda function name.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'Code' <~Hash> - object for the Lambda function location.

      • 'Configuration' <~Hash> - function metadata description.

# File lib/fog/aws/requests/lambda/get_function.rb, line 16
def get_function(params={})
  function_name = params.delete('FunctionName')
  request({
    :method  => 'GET',
    :path    => "/functions/#{function_name}/versions/HEAD",
    :parser  => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
get_function_configuration(params={}) click to toggle source

Returns the configuration information of the Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html

Parameters

  • FunctionName <~String> - Lambda function name.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'CodeSize' <~Integer> - size, in bytes, of the function .zip file you uploaded.

      • 'Description' <~String> - user-provided description.

      • 'FunctionArn' <~String> - Amazon Resource Name (ARN) assigned to the function.

      • 'FunctionName' <~String> - name of the function.

      • 'Handler' <~String> - function Lambda calls to begin executing your function.

      • 'LastModified' <~Time> - timestamp of the last time you updated the function.

      • 'Memorysize' <~String> - memory size, in MB, you configured for the function.

      • 'Role' <~String> - ARN of the IAM role that Lambda assumes when it executes your function to access any other AWS resources.

      • 'Runtime' <~String> - runtime environment for the Lambda function.

      • 'Timeout' <~Integer> - function execution time at which Lambda should terminate the function.

# File lib/fog/aws/requests/lambda/get_function_configuration.rb, line 24
def get_function_configuration(params={})
  function_name = params.delete('FunctionName')
  request({
    :method  => 'GET',
    :path    => "/functions/#{function_name}/versions/HEAD/configuration",
    :parser  => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
get_policy(params={}) click to toggle source

Returns the access policy, containing a list of permissions granted via the AddPermission API, associated with the specified bucket. docs.aws.amazon.com/lambda/latest/dg/API_GetPolicy.html

Parameters

  • FunctionName <~String> - Function name whose access policy you want to retrieve.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'Policy' <~Hash> - The access policy associated with the specified function.

# File lib/fog/aws/requests/lambda/get_policy.rb, line 15
def get_policy(params={})
  function_name = params.delete('FunctionName')
  request({
    :method  => 'GET',
    :path    => "/functions/#{function_name}/versions/HEAD/policy",
    :parser => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
invoke(params={}) click to toggle source

Invokes a specified Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html

Parameters

  • ClientContext <~Hash> - client-specific information to the Lambda function you are invoking.

  • FunctionName <~String> - Lambda function name.

  • InvocationType <~String> - function invocation type.

  • LogType <~String> - logs format for function calls of “RequestResponse” invocation type.

  • Payload <~Integer> - Lambda function input.

Returns

  • response<~Excon::Response>:

    • body<~Hash> - JSON representation of the object returned by the Lambda function.

# File lib/fog/aws/requests/lambda/invoke.rb, line 17
def invoke(params={})
  headers = {}
  if client_context = params.delete('ClientContext')
    headers['X-Amz-Client-Context'] =
      Base64::encode64(Fog::JSON.encode(client_context))
  end
  if invocation_type = params.delete('InvocationType')
    headers['X-Amz-Invocation-Type'] = invocation_type
  end
  if log_type = params.delete('LogType')
    headers['X-Amz-Log-Type'] = log_type
  end
  payload = Fog::JSON.encode(params.delete('Payload'))
  function_name = params.delete('FunctionName')

  request({
    :method  => 'POST',
    :path    => "/functions/#{function_name}/invocations",
    :headers => headers,
    :body    => payload,
    :expects => [200, 202, 204]
  }.merge(params))
end
list_event_source_mappings(params={}) click to toggle source

Returns a list of event source mappings where you can identify a stream as an event source. docs.aws.amazon.com/lambda/latest/dg/API_ListEventSourceMappings.html

Parameters

  • EventSourceArn <~String> - Amazon Resource Name (ARN) of the stream.

  • FunctionName <~String> - name of the Lambda function.

  • Marker <~String> - opaque pagination token returned from a previous ListEventSourceMappings operation.

  • MaxItems <~Integer> - maximum number of event sources to return in response.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'EventSourceMappings' <~Array> - array of EventSourceMappingConfiguration objects.

      • 'NextMarker' <~String> - present if there are more event source mappings.

# File lib/fog/aws/requests/lambda/list_event_source_mappings.rb, line 17
def list_event_source_mappings(params={})
  event_source_arn = params.delete('EventSourceArn')
  function_name    = params.delete('FunctionName')
  marker           = params.delete('Marker')
  max_items        = params.delete('MaxItems')

  query = {}
  query.merge!('EventSourceArn' => event_source_arn) if event_source_arn
  query.merge!('FunctionName'   => function_name)    if function_name
  query.merge!('Marker'         => marker)           if marker
  query.merge!('MaxItems'       => max_items)        if max_items

  request({
    :method => 'GET',
    :path   => '/event-source-mappings/',
    :query  => query
  }.merge(params))
end
list_functions(params={}) click to toggle source

Returns a list of your Lambda functions. docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html

Parameters

  • Marker <~String> - opaque pagination token returned from a previous ListFunctions operation. If present, indicates where to continue the listing.

  • MaxItems <~Integer> - Specifies the maximum number of AWS Lambda functions to return in response.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'Functions' <~Array> - list of Lambda functions.

      • 'NextMarker' <~String> - present if there are more functions.

# File lib/fog/aws/requests/lambda/list_functions.rb, line 17
def list_functions(params={})
  request({
    :method => 'GET',
    :path   => '/functions/',
    :parser => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
reload() click to toggle source
# File lib/fog/aws/lambda.rb, line 105
def reload
  @connection.reset
end
remove_permission(params={}) click to toggle source

Remove individual permissions from an access policy associated with a Lambda function by providing a Statement ID. docs.aws.amazon.com/lambda/latest/dg/API_RemovePermission.html

Parameters

  • FunctionName <~String> - Lambda function whose access policy you want to remove a permission from.

  • StatementId <~String> - Statement ID of the permission to remove.

Returns

  • response<~Excon::Response>:

    • body<~String>:

# File lib/fog/aws/requests/lambda/remove_permission.rb, line 14
def remove_permission(params={})
  function_name = params.delete('FunctionName')
  statement_id  = params.delete('StatementId')
  request({
    :method  => 'DELETE',
    :path    => "/functions/#{function_name}/versions/HEAD/policy/#{statement_id}",
    :expects => 204
  }.merge(params))
end
update_event_source_mapping(params={}) click to toggle source

Change the parameters of the existing mapping without losing your position in the stream. docs.aws.amazon.com/lambda/latest/dg/API_UpdateEventSourceMapping.html

Parameters

  • UUID <~String> - event source mapping identifier.

  • BatchSize <~Integer> - maximum number of stream records that can be sent to your Lambda function for a single invocation.

  • Enabled <~Boolean> - specifies whether AWS Lambda should actively poll the stream or not.

  • FunctionName <~String> - Lambda function to which you want the stream records sent.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'BatchSize' <~Integer> - largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.

      • 'EventSourceArn' <~String> - Amazon Resource Name (ARN) of the stream that is the source of events.

      • 'FunctionArn' <~String> - Lambda function to invoke when AWS Lambda detects an event on the stream.

      • 'LastModified' <~Time> - UTC time string indicating the last time the event mapping was updated.

      • 'LastProcessingResult' <~String> - result of the last AWS Lambda invocation of your Lambda function.

      • 'State' <~String> - state of the event source mapping.

      • 'StateTransitionReason' <~String> - reason the event source mapping is in its current state.

      • 'UUID' <~String> - AWS Lambda assigned opaque identifier for the mapping.

# File lib/fog/aws/requests/lambda/update_event_source_mapping.rb, line 23
def update_event_source_mapping(params={})
  function_name = params.delete('FunctionName')
  mapping_id    = params.delete('UUID')

  batch_size = params.delete('BatchSize')
  enabled    = params.delete('Enabled')

  update = {}
  update.merge!('BatchSize'    => batch_size)    if batch_size
  update.merge!('Enabled'      => enabled)       if !enabled.nil?
  update.merge!('FunctionName' => function_name) if function_name

  request({
    :method  => 'PUT',
    :path    => "/event-source-mappings/#{mapping_id}",
    :expects => 202,
    :body    => Fog::JSON.encode(update)
  }.merge(params))
end
update_function_code(params={}) click to toggle source

Updates the code for the specified Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionCode.html

Parameters

  • FunctionName <~String> - existing Lambda function name whose code you want to replace.

  • S3Bucket <~String> - Amazon S3 bucket name where the .zip file containing your deployment package is stored.

  • S3Key <~String> - Amazon S3 object (the deployment package) key name you want to upload.

  • S3ObjectVersion <~String> - Amazon S3 object (the deployment package) version you want to upload.

  • ZipFile <~String> - Based64-encoded .zip file containing your packaged source code.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'CodeSize' <~Integer> - size, in bytes, of the function .zip file you uploaded.

      • 'Description' <~String> - user-provided description.

      • 'FunctionArn' <~String> - Amazon Resource Name (ARN) assigned to the function.

      • 'FunctionName' <~String> - name of the function.

      • 'Handler' <~String> - function Lambda calls to begin executing your function.

      • 'LastModified' <~Time> - timestamp of the last time you updated the function.

      • 'Memorysize' <~String> - memory size, in MB, you configured for the function.

      • 'Role' <~String> - ARN of the IAM role that Lambda assumes when it executes your function to access any other AWS resources.

      • 'Runtime' <~String> - runtime environment for the Lambda function.

      • 'Timeout' <~Integer> - function execution time at which Lambda should terminate the function.

# File lib/fog/aws/requests/lambda/update_function_code.rb, line 28
def update_function_code(params={})
  function_name = params.delete('FunctionName')

  s3_bucket     = params.delete('S3Bucket')
  s3_key        = params.delete('S3Key')
  s3_object_ver = params.delete('S3ObjectVersion')
  zip_file      = params.delete('ZipFile')

  update = {}
  update.merge!('S3Bucket'        => s3_bucket)     if s3_bucket
  update.merge!('S3Key'           => s3_key)        if s3_key
  update.merge!('S3ObjectVersion' => s3_object_ver) if s3_object_ver
  update.merge!('ZipFile'         => zip_file)      if zip_file

  request({
    :method  => 'PUT',
    :path    => "/functions/#{function_name}/versions/HEAD/code",
    :body    => Fog::JSON.encode(update),
    :parser  => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end
update_function_configuration(params={}) click to toggle source

Updates the configuration parameters for the specified Lambda function. docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionConfiguration.html

Parameters

  • FunctionName <~String> - name of the Lambda function.

  • Description <~String> - short user-defined function description.

  • Handler <~String> - function that Lambda calls to begin executing your function.

  • MemorySize <~Integer> - amount of memory, in MB, your Lambda function is given.

  • Role <~String> - ARN of the IAM role that Lambda will assume when it executes your function.

  • Timeout <~Integer> - function execution time at which AWS Lambda should terminate the function.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • 'CodeSize' <~Integer> - size, in bytes, of the function .zip file you uploaded.

      • 'Description' <~String> - user-provided description.

      • 'FunctionArn' <~String> - Amazon Resource Name (ARN) assigned to the function.

      • 'FunctionName' <~String> - name of the function.

      • 'Handler' <~String> - function Lambda calls to begin executing your function.

      • 'LastModified' <~Time> - timestamp of the last time you updated the function.

      • 'Memorysize' <~String> - memory size, in MB, you configured for the function.

      • 'Role' <~String> - ARN of the IAM role that Lambda assumes when it executes your function to access any other AWS resources.

      • 'Runtime' <~String> - runtime environment for the Lambda function.

      • 'Timeout' <~Integer> - function execution time at which Lambda should terminate the function.

# File lib/fog/aws/requests/lambda/update_function_configuration.rb, line 29
def update_function_configuration(params={})
  function_name = params.delete('FunctionName')

  description = params.delete('Description')
  handler     = params.delete('Handler')
  memory_size = params.delete('MemorySize')
  role        = params.delete('Role')
  timeout     = params.delete('Timeout')

  update = {}
  update.merge!('Description' => description) if description
  update.merge!('Handler'     => handler)     if handler
  update.merge!('MemorySize'  => memory_size) if memory_size
  update.merge!('Role'        => role)        if role
  update.merge!('Timeout'     => timeout)     if timeout

  request({
    :method  => 'PUT',
    :path    => "/functions/#{function_name}/versions/HEAD/configuration",
    :body    => Fog::JSON.encode(update),
    :parser  => Fog::AWS::Parsers::Lambda::Base.new
  }.merge(params))
end

Private Instance Methods

_request(method, path, query, body, headers, expects, idempotent, parser=nil) click to toggle source
# File lib/fog/aws/lambda.rb, line 165
def _request(method, path, query, body, headers, expects, idempotent, parser=nil)
  response = process_response(@connection.request({
    :path       => path,
    :query      => query,
    :body       => body,
    :expects    => expects,
    :idempotent => idempotent,
    :headers    => headers,
    :method     => method
  }), parser)
rescue Excon::Errors::HTTPStatusError => error
  match = Fog::AWS::Errors.match_error(error)
  raise if match.empty?
  raise Fog::AWS::Lambda::Error.slurp(error,
    "#{match[:code]} => #{match[:message]}")
end
process_response(response, parser) click to toggle source
# File lib/fog/aws/lambda.rb, line 182
def process_response(response, parser)
  if response &&
     response.body &&
     response.body.is_a?(String) &&
     !response.body.strip.empty? &&
     Fog::AWS.json_response?(response)
    begin
      response.body = Fog::JSON.decode(response.body)
      response.body = parser.process(response.body) if parser
    rescue Fog::JSON::DecodeError => e
      Fog::Logger.warning("Error parsing response json - #{e}")
      response.body = {}
    end
  end
  response
end
request(params) click to toggle source
# File lib/fog/aws/lambda.rb, line 120
def request(params)
  refresh_credentials_if_expired

  idempotent   = params.delete(:idempotent)
  parser       = params.delete(:parser)
  path         = params.delete(:path)
  request_path = "/#{@version}#{path}"
  query        = params.delete(:query)   || {}
  method       = params.delete(:method)  || 'POST'
  expects      = params.delete(:expects) || 200
  headers      = { 'Content-Type' => 'application/json' }

  headers.merge!(params[:headers] || {})

  request_path_to_sign = case path
  when %r{^/functions/([0-9a-zA-Z\:\-\_]+)(/.+)?$}
    "/#{@version}/functions/#{Fog::AWS.escape($~[1])}#{$~[2]}"
  else
    request_path
  end

  body, headers = AWS.signed_params_v4(
    params,
    headers,
    {
      :method            => method,
      :aws_session_token => @aws_session_token,
      :signer            => @signer,
      :host              => @host,
      :path              => request_path_to_sign,
      :port              => @port,
      :query             => query,
      :body              => params[:body]
    }
  )

  if @instrumentor
    @instrumentor.instrument("#{@instrumentor_name}.request", params) do
      _request(method, request_path, query, body, headers, expects, idempotent, parser)
    end
  else
    _request(method, request_path, query, body, headers, expects, idempotent, parser)
  end
end
setup_credentials(options) click to toggle source
# File lib/fog/aws/lambda.rb, line 111
def setup_credentials(options)
  @aws_access_key_id         = options[:aws_access_key_id]
  @aws_secret_access_key     = options[:aws_secret_access_key]
  @aws_session_token         = options[:aws_session_token]
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]

  @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region, 'lambda')
end