
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Middleware (Ruby) to automatically log API calls from AWS Lambda functions and sends and sends to Moesif for API analytics.
This middleware expects the Lambda proxy integration type. If you're using AWS Lambda with API Gateway, you are most likely using the proxy integration type.
bundle install moesif_aws_lambda
def your_original_handler(event:, context:)
# your code
end
moesif_options = {
# application_id is required
"application_id" => 'Your Moesif Application Id',
"debug" => true,
# see list of other options below.
}
# create moesif_middleware object.
$moesif_middleware = Moesif::MoesifAwsMiddleware.new(method(:your_original_handler), moesif_options)
def wrapped_handler(event:, context:)
$moesif_middleware.handle(event: event, context: context);
end
configure AWS Lambda handler to wrapped_handler
instead.
application_id
Required. String. This is the Moesif application_id under settings from your Moesif account.
api_version
Optional. String. Tag requests with the version of your API.
identify_user
Optional. identify_user is a Proc that takes event, context, and lambda result as arguments and returns a user_id string. This helps us attribute requests to unique users. Even though Moesif can automatically retrieve the user_id without this, this is highly recommended to ensure accurate attribution.
event
and context
are original lambda input params, and result
is the return result from your own original lambda handler.
moesif_options['identify_user'] = Proc.new { |event, context, result|
# Add your custom code that returns a string for user id
'12345'
}
identify_company
Optional. identify_company returns a company_id string. This helps us attribute requests to unique company.
moesif_options['identify_company'] = Proc.new { |event, context, result|
# Add your custom code that returns a string for company id
'67890'
}
identify_session
Optional. A Proc that takes env, headers, body and returns a string.
moesif_options['identify_session'] = Proc.new { |event, context, result|
# Add your custom code that returns a string for session/API token
'XXXXXXXXX'
}
get_metadata
Optional. get_metadata is a Proc that takes env, headers, and body as arguments and returns a Hash that is representation of a JSON object. This allows you to attach any metadata to this event.
moesif_options['get_metadata'] = Proc.new { |event, context, result|
# Add your custom code that returns a dictionary
value = {
'datacenter' => 'westus',
'deployment_version' => 'v1.2.3'
}
value
}
mask_data
Optional. A Proc that takes event_model as an argument and returns event_model.
With mask_data, you can make modifications to headers or body of the event before it is sent to Moesif.
moesif_options['mask_data'] = Proc.new { |event_model|
# Add your custom code that returns a event_model after modifying any fields
event_model.response.body.password = nil
event_model
}
For details for the spec of moesif event model, please see the moesifapi-ruby or Moesif Ruby API Documentation
skip
Optional. A Proc that takes env, headers, body and returns a boolean.
moesif_options['skip'] = Proc.new { |event, context, result|
# Add your custom code that returns true to skip logging the API call
if event.key?("rawPath")
# Skip probes to health page
event["rawPath"].include? "/health"
else
false
end
}
debug
Optional. Boolean. Default false. If true, it will print out debug messages. In debug mode, the processing is not done in backend thread.
log_body
Optional. Boolean. Default true. If false, will not log request and response body to Moesif.
If you wish to update User or Company profile when needed using this SDK, you can also use below methods:
$moesif_middleware.update_user(user_profile)
$moesif_middleware.update_user_batch(user_profiles)
$moesif_middleware.update_company(company_profile)
$moesif_middleware.update_company_batch(company_profiles)
For details regarding shape of the profiles, please see the Moesif Ruby API Documentation
For AWS lambda with ruby, you have to bundle the gem dependencies into the zip file. https://docs.aws.amazon.com/lambda/latest/dg/ruby-package.html
In your ruby main file, you may have to specify where the dependencies are installed:
load_paths = Dir[
"./vendor/bundle/ruby/2.7.0/gems/**/lib"
]
$LOAD_PATH.unshift(*load_paths)
example_handler.rb
is an example file that implement this.
FAQs
Unknown package
We found that moesif_aws_lambda demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.