aws_ec2_environment 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 737e9d6f8e8b401117093eafc846a8522f1904afda0f44a98de3568e3ced961d
4
- data.tar.gz: 702df72ea4cdac5293012c0eb4a73dc5bfdda61a5d6b98d61e6e69bbe9961945
3
+ metadata.gz: b294268a688df38dfde011db33d1cf3e69f6d5562424b93a487224e180f5268d
4
+ data.tar.gz: 6aff34b804255143bf4095d1346d13fc4635e6549d767b22b512d37129f8b6e8
5
5
  SHA512:
6
- metadata.gz: 9bde699e347ad8add1e517e8fa52a6703ea155d76def3ed488097a4037068235b7fb715b655e14c5d6929a8ae99406551f912dfb017a73728c31a4844a04d244
7
- data.tar.gz: d4078cf90c5a8395e29818e8d07c4de064e78ca9ccdb66e8facd96c25031adf9b734553914870221bb42ad094afab5940d4fb236083db6fae604816ff03d8613
6
+ metadata.gz: 5219053812134a5b2143d22be1c882f73cba47bbb06f41fbd560cdfbbac43e93d987169bd10fa62bd8b57126ded34bfcfd894303edeb4eaf81431a5ebd1239b7
7
+ data.tar.gz: e18d61043d7a0acc999b98e11cec1fb733e1c48e52bd41762233c67f7a2cd669b190663c442a411f383fd158ca395478697c13b27e3389fce61ba957fd844f04
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2026-01-09
4
+
5
+ ### Added
6
+
7
+ - Support using alternative documents and parameters with
8
+ `SsmPortForwardingSession`
9
+ ([#22](https://github.com/ackama/aws_ec2_environment/pull/22))
10
+
3
11
  ## [0.1.1] - 2025-12-15
4
12
 
5
13
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aws_ec2_environment (0.1.1)
4
+ aws_ec2_environment (0.2.0)
5
5
  aws-sdk-ec2 (~> 1.0)
6
6
  aws-sdk-ssm (~> 1.0)
7
7
 
data/README.md CHANGED
@@ -199,6 +199,44 @@ task :forward_port, %i[instance_id remote_port local_port] => :environment do |_
199
199
  end
200
200
  ```
201
201
 
202
+ You can also use specific documents, and pass in extra parameters, which can be
203
+ useful for using tunnels to access other private resources like database
204
+ instances:
205
+
206
+ ```ruby
207
+ require "aws_ec2_environment"
208
+
209
+ desc "Dumps a copy of the postgres database using AWS and PG environment variables"
210
+ task :dump_pg_database, %i[instance_id dump_file] => :environment do |_, args|
211
+ instance_id = args.fetch(:instance_id)
212
+ dump_file = args.fetch(:dump_file)
213
+
214
+ remote_host = ENV.fetch("PGHOST")
215
+ remote_port = ENV.fetch("PGPORT", 5432).to_i
216
+
217
+ session = AwsEc2Environment::SsmPortForwardingSession.new(
218
+ instance_id,
219
+ remote_port,
220
+ document: "AWS-StartPortForwardingSessionToRemoteHost",
221
+ extra_params: { "host" => [remote_host] }
222
+ )
223
+
224
+ at_exit { session.close }
225
+
226
+ local_port = session.wait_for_local_port
227
+
228
+ system(
229
+ "pg_dump",
230
+ "--format=c",
231
+ "--no-owner",
232
+ "--no-privileges",
233
+ "--host=localhost",
234
+ "--port=#{local_port}",
235
+ "--file=#{dump_file}",
236
+ )
237
+ end
238
+ ```
239
+
202
240
  ### AWS Authentication and Permissions
203
241
 
204
242
  Since this gem interacts with AWS, it must be configured with credentials - see
@@ -22,8 +22,9 @@ class AwsEc2Environment
22
22
  # rubocop:disable Metrics/ParameterLists
23
23
  def initialize(
24
24
  instance_id, remote_port,
25
+ document: "AWS-StartPortForwardingSession",
25
26
  local_port: nil, logger: Logger.new($stdout),
26
- timeout: 15, reason: nil
27
+ timeout: 15, reason: nil, extra_params: {}
27
28
  )
28
29
  # rubocop:enable Metrics/ParameterLists
29
30
  @logger = logger
@@ -32,7 +33,7 @@ class AwsEc2Environment
32
33
  @local_port = nil
33
34
  @timeout = timeout
34
35
 
35
- @reader, @writer, @pid = PTY.spawn(ssm_port_forward_cmd(local_port, reason))
36
+ @reader, @writer, @pid = PTY.spawn(ssm_port_forward_cmd(local_port, reason, document, extra_params))
36
37
 
37
38
  @cmd_output = +""
38
39
  @session_id = wait_for_session_id
@@ -64,9 +65,8 @@ class AwsEc2Environment
64
65
 
65
66
  private
66
67
 
67
- def ssm_port_forward_cmd(local_port, reason)
68
- document_name = "AWS-StartPortForwardingSession"
69
- parameters = { "portNumber" => [remote_port.to_s] }
68
+ def ssm_port_forward_cmd(local_port, reason, document_name, extra_params)
69
+ parameters = extra_params.merge({ "portNumber" => [remote_port.to_s] })
70
70
  parameters["localPortNumber"] = [local_port.to_s] unless local_port.nil?
71
71
  flags = [
72
72
  ["--target", instance_id],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AwsEc2Environment
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -16,10 +16,12 @@ class AwsEc2Environment
16
16
  def initialize: (
17
17
  String instance_id,
18
18
  Integer remote_port,
19
+ ?document: String,
19
20
  ?local_port: Integer | nil,
20
21
  ?logger: Logger,
21
22
  ?timeout: Numeric,
22
- ?reason: String | nil
23
+ ?reason: String | nil,
24
+ ?extra_params: Hash[String, untyped]
23
25
  ) -> void
24
26
 
25
27
  def close: () -> void
@@ -38,7 +40,12 @@ class AwsEc2Environment
38
40
  @writer: IO
39
41
  @cmd_output: String
40
42
 
41
- def ssm_port_forward_cmd: (Integer | nil local_port, String | nil reason) -> String
43
+ def ssm_port_forward_cmd: (
44
+ Integer | nil local_port,
45
+ String | nil reason,
46
+ String document_name,
47
+ Hash[String, untyped] extra_params
48
+ ) -> String
42
49
 
43
50
  # Checks the cmd process output until either the given +pattern+ matches or the +timeout+ is over.
44
51
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_ec2_environment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gareth Jones