Module: Lambda::MicroVMs::Session
- Defined in:
- lib/lambda/microvms/session.rb
Overview
Convenience API for run/use/cleanup MicroVM sessions.
Class Method Summary collapse
-
.cleanup(vm, after) ⇒ Object?
Apply a session cleanup policy to a MicroVM.
-
.session(image_arn:, role_arn:, after: :suspend, client: Client.new, **run_options) {|vm| ... } ⇒ Object
Run a MicroVM, wait for it, yield it, and then clean it up.
Class Method Details
.cleanup(vm, after) ⇒ Object?
Apply a session cleanup policy to a MicroVM.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lambda/microvms/session.rb', line 32 def cleanup(vm, after) # rubocop:disable Naming/MethodParameterName case after when :keep, nil nil when :suspend vm.suspend when :terminate vm.terminate else raise ArgumentError, "unknown cleanup policy: #{after.inspect}" end end |
.session(image_arn:, role_arn:, after: :suspend, client: Client.new, **run_options) {|vm| ... } ⇒ Object
Run a MicroVM, wait for it, yield it, and then clean it up.
18 19 20 21 22 23 24 |
# File 'lib/lambda/microvms/session.rb', line 18 def session(image_arn:, role_arn:, after: :suspend, client: Client.new, **) vm = client.image(image_arn).run(role_arn: role_arn, **) vm.wait_until_running yield vm ensure cleanup(vm, after) if vm end |