Skip to content

Basic Exe Install Interface #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
## [1.1.0] - 2023-04-16

### Added

- New `lambda_punch` install interface.

## [1.0.3] - 2021-10-27

### Added

-
- Any Timeout Gem. Tempfile Location Interface

### Changed

Expand Down
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,36 @@ The LambdaPunch extension process is very small and lean. It only requires a few

## 🎁 Installation

Add this line to your project's `Gemfile` and then make sure to `bundle install` afterward.
Add this line to your project's `Gemfile` and then make sure to `bundle install` afterward. It is only needed in the `production` group.

```ruby
gem 'lambda_punch'
```

Now, within your application's handler file, make sure to start the LambdaPunch DRb server outside of your handler method. Within the handler method, add an `ensure` section that lets the extension process know the request is done.
Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, add the following. Make sure you do this before you `COPY` your code. The idea is to implicitly use the default `USER root` since it needs permissions to create an `/opt/extensions` directory.

```ruby
LambdaPunch.start_server!

def handler(event:, context:)
# ...
ensure
LambdaPunch.handled!(context)
end
```dockerfile
RUN gem install lambda_punch && lambda_punch install
```

Within your project or [Rails application's](https://lamby.custominktech.com/docs/anatomy) `Dockerfile`, after you copy your code, add this `RUN` command to install the extension within your container's `/opt/extensions` directory.
Installation with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem can be done using Lamby's `handled_proc` config. For example, appends these to your `config/environments/production.rb` file. Here we are ensuring that the LambdaPunch DRb server is running and that after each Lamby request we notify LambdaPunch.

```dockerfile
RUN bundle exec rake lambda_punch:install
```ruby
config.to_prepare { LambdaPunch.start_server! }
config.lamby.handled_proc = Proc.new do |_event, context|
LambdaPunch.handled!(context)
end
```

If you are using `LambdaPunch` with a non-Rails project, add this to your Rake file
If you are using an older version of Lamby or a simple Ruby project with your own handler method, the installation would look something like this:

```ruby
spec = Gem::Specification.find_by_name 'lambda_punch'
load "#{spec.gem_dir}/lib/lambda_punch/tasks/install.rake"
LambdaPunch.start_server!
def handler(event:, context:)
# ...
ensure
LambdaPunch.handled!(context)
end
```

## 🧰 Usage
Expand All @@ -59,11 +60,11 @@ LambdaPunch.push do
end
```

For example, if you are using Rails with AWS Lambda via the [Lamby](https://lamby.custominktech.com/) v4 (or higher) gem along with [New Relic APM](https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) here is how you configure the handled proc called after `Lamby.cmd` in an `ensure` block. This will force metrics to be flushed after each request.
A common use case would be to ensure the [New Relic APM](https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) flushes its data after each request. Using Lamby in your `config/environments/production.rb` file would look like this:

```ruby
# config/environments/production.rb
config.lambda.handled_proc = Proc.new do |_event, context|
config.to_prepare { LambdaPunch.start_server! }
config.lamby.handled_proc = Proc.new do |_event, context|
LambdaPunch.push { NewRelic::Agent.agent.flush_pipe_data }
LambdaPunch.handled!(context)
end
Expand Down
10 changes: 10 additions & 0 deletions exe/lambda_punch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'rake'

load "#{spec.gem_dir}/lib/lambda_punch/tasks/install.rake"

command = ARGV[0] || 'install'

Rake::Task["lambda_punch:#{command}"].invoke
2 changes: 1 addition & 1 deletion lib/lambda_punch/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module LambdaPunch
VERSION = "1.0.3"
VERSION = "1.1.0"
end