Sha256: e2bc685da2492f72581f36f29636f0ea6ac8e5012bef3ba8ea3717fca5ebf38d
Contents?: true
Size: 624 Bytes
Versions: 7
Compression:
Stored size: 624 Bytes
Contents
require 'aws-sdk-ec2' require 'json' def lambda_handler(event:, context:) ec2 = Aws::EC2::Client.new instance_id = event['instance_id'] action = event['action'] begin case action when 'start' ec2.start_instances(instance_ids: [instance_id]) puts "Started EC2 instance: #{instance_id}" when 'stop' ec2.stop_instances(instance_ids: [instance_id]) puts "Stopped EC2 instance: #{instance_id}" else raise "Invalid action: #{action}. Must be 'start' or 'stop'." end rescue Aws::EC2::Errors::ServiceError => e puts "Error during EC2 action: #{e.message}" end end
Version data entries
7 entries across 7 versions & 1 rubygems