aws_ec2_environment 0.1.0 → 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 +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +22 -15
- data/README.md +38 -0
- data/aws_ec2_environment.gemspec +37 -0
- data/lib/aws_ec2_environment/ssm_port_forwarding_session.rb +6 -6
- data/lib/aws_ec2_environment/version.rb +1 -1
- data/sig/aws_ec2_environment/ssm_port_forwarding_session.rbs +9 -2
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b294268a688df38dfde011db33d1cf3e69f6d5562424b93a487224e180f5268d
|
|
4
|
+
data.tar.gz: 6aff34b804255143bf4095d1346d13fc4635e6549d767b22b512d37129f8b6e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5219053812134a5b2143d22be1c882f73cba47bbb06f41fbd560cdfbbac43e93d987169bd10fa62bd8b57126ded34bfcfd894303edeb4eaf81431a5ebd1239b7
|
|
7
|
+
data.tar.gz: e18d61043d7a0acc999b98e11cec1fb733e1c48e52bd41762233c67f7a2cd669b190663c442a411f383fd158ca395478697c13b27e3389fce61ba957fd844f04
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
11
|
+
## [0.1.1] - 2025-12-15
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Make sure string used for capturing cmd output is unfrozen
|
|
16
|
+
([#25](https://github.com/ackama/aws_ec2_environment/pull/25))
|
|
17
|
+
|
|
3
18
|
## [0.1.0] - 2022-08-17
|
|
4
19
|
|
|
5
20
|
- Initial release
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
aws_ec2_environment (0.
|
|
4
|
+
aws_ec2_environment (0.2.0)
|
|
5
5
|
aws-sdk-ec2 (~> 1.0)
|
|
6
6
|
aws-sdk-ssm (~> 1.0)
|
|
7
7
|
|
|
@@ -9,27 +9,32 @@ GEM
|
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
11
|
ast (2.4.2)
|
|
12
|
-
aws-eventstream (1.
|
|
13
|
-
aws-partitions (1.
|
|
14
|
-
aws-sdk-core (3.
|
|
15
|
-
aws-eventstream (~> 1, >= 1.0
|
|
16
|
-
aws-partitions (~> 1, >= 1.
|
|
17
|
-
aws-sigv4 (~> 1.
|
|
12
|
+
aws-eventstream (1.4.0)
|
|
13
|
+
aws-partitions (1.1172.0)
|
|
14
|
+
aws-sdk-core (3.233.0)
|
|
15
|
+
aws-eventstream (~> 1, >= 1.3.0)
|
|
16
|
+
aws-partitions (~> 1, >= 1.992.0)
|
|
17
|
+
aws-sigv4 (~> 1.9)
|
|
18
|
+
base64
|
|
19
|
+
bigdecimal
|
|
18
20
|
jmespath (~> 1, >= 1.6.1)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
aws-
|
|
21
|
+
logger
|
|
22
|
+
aws-sdk-ec2 (1.562.0)
|
|
23
|
+
aws-sdk-core (~> 3, >= 3.231.0)
|
|
24
|
+
aws-sigv4 (~> 1.5)
|
|
22
25
|
aws-sdk-ssm (1.138.0)
|
|
23
26
|
aws-sdk-core (~> 3, >= 3.127.0)
|
|
24
27
|
aws-sigv4 (~> 1.1)
|
|
25
|
-
aws-sigv4 (1.
|
|
28
|
+
aws-sigv4 (1.12.1)
|
|
26
29
|
aws-eventstream (~> 1, >= 1.0.2)
|
|
27
30
|
base64 (0.1.1)
|
|
31
|
+
bigdecimal (3.3.1)
|
|
28
32
|
diff-lcs (1.5.0)
|
|
29
33
|
docile (1.4.0)
|
|
30
|
-
jmespath (1.6.
|
|
31
|
-
json (2.
|
|
34
|
+
jmespath (1.6.2)
|
|
35
|
+
json (2.15.1)
|
|
32
36
|
language_server-protocol (3.17.0.3)
|
|
37
|
+
logger (1.7.0)
|
|
33
38
|
parallel (1.23.0)
|
|
34
39
|
parser (3.2.2.3)
|
|
35
40
|
ast (~> 2.4.1)
|
|
@@ -38,7 +43,7 @@ GEM
|
|
|
38
43
|
rainbow (3.1.1)
|
|
39
44
|
rake (13.0.6)
|
|
40
45
|
regexp_parser (2.8.1)
|
|
41
|
-
rexml (3.2
|
|
46
|
+
rexml (3.4.2)
|
|
42
47
|
rspec (3.11.0)
|
|
43
48
|
rspec-core (~> 3.11.0)
|
|
44
49
|
rspec-expectations (~> 3.11.0)
|
|
@@ -88,6 +93,8 @@ GEM
|
|
|
88
93
|
|
|
89
94
|
PLATFORMS
|
|
90
95
|
arm64-darwin-21
|
|
96
|
+
arm64-darwin-22
|
|
97
|
+
arm64-darwin-23
|
|
91
98
|
x86_64-darwin-19
|
|
92
99
|
x86_64-darwin-20
|
|
93
100
|
x86_64-linux
|
|
@@ -102,4 +109,4 @@ DEPENDENCIES
|
|
|
102
109
|
simplecov
|
|
103
110
|
|
|
104
111
|
BUNDLED WITH
|
|
105
|
-
2.
|
|
112
|
+
2.5.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
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/aws_ec2_environment/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "aws_ec2_environment"
|
|
7
|
+
spec.version = AwsEc2Environment::VERSION
|
|
8
|
+
spec.authors = ["Gareth Jones"]
|
|
9
|
+
spec.email = %w[open-source@ackama.com]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Interact with AWS EC2-based Ruby apps easily"
|
|
12
|
+
spec.homepage = "https://github.com/ackama/aws_ec2_environment"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
15
|
+
|
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
|
19
|
+
|
|
20
|
+
# TODO: we expect to have to disable this if we switch to automatic releases
|
|
21
|
+
# but until then we've got it enabled to make Rubocop happy
|
|
22
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
23
|
+
|
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
26
|
+
spec.files = Dir.chdir(__dir__) do
|
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
28
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = "exe"
|
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
spec.add_dependency "aws-sdk-ec2", "~> 1.0"
|
|
36
|
+
spec.add_dependency "aws-sdk-ssm", "~> 1.0"
|
|
37
|
+
end
|
|
@@ -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,9 +33,9 @@ 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
|
-
@cmd_output = ""
|
|
38
|
+
@cmd_output = +""
|
|
38
39
|
@session_id = wait_for_session_id
|
|
39
40
|
|
|
40
41
|
@logger.info("SSM session #{@session_id} opening, forwarding port #{remote_port} on #{instance_id}")
|
|
@@ -64,9 +65,8 @@ class AwsEc2Environment
|
|
|
64
65
|
|
|
65
66
|
private
|
|
66
67
|
|
|
67
|
-
def ssm_port_forward_cmd(local_port, reason)
|
|
68
|
-
|
|
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],
|
|
@@ -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: (
|
|
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,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aws_ec2_environment
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gareth Jones
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: aws-sdk-ec2
|
|
@@ -38,7 +37,6 @@ dependencies:
|
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '1.0'
|
|
41
|
-
description:
|
|
42
40
|
email:
|
|
43
41
|
- open-source@ackama.com
|
|
44
42
|
executables: []
|
|
@@ -58,6 +56,7 @@ files:
|
|
|
58
56
|
- LICENSE.txt
|
|
59
57
|
- README.md
|
|
60
58
|
- Rakefile
|
|
59
|
+
- aws_ec2_environment.gemspec
|
|
61
60
|
- lib/aws_ec2_environment.rb
|
|
62
61
|
- lib/aws_ec2_environment/ci_service.rb
|
|
63
62
|
- lib/aws_ec2_environment/config.rb
|
|
@@ -75,7 +74,6 @@ metadata:
|
|
|
75
74
|
source_code_uri: https://github.com/ackama/aws_ec2_environment
|
|
76
75
|
changelog_uri: https://github.com/ackama/aws_ec2_environment
|
|
77
76
|
rubygems_mfa_required: 'true'
|
|
78
|
-
post_install_message:
|
|
79
77
|
rdoc_options: []
|
|
80
78
|
require_paths:
|
|
81
79
|
- lib
|
|
@@ -90,8 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
88
|
- !ruby/object:Gem::Version
|
|
91
89
|
version: '0'
|
|
92
90
|
requirements: []
|
|
93
|
-
rubygems_version: 3.
|
|
94
|
-
signing_key:
|
|
91
|
+
rubygems_version: 3.6.9
|
|
95
92
|
specification_version: 4
|
|
96
93
|
summary: Interact with AWS EC2-based Ruby apps easily
|
|
97
94
|
test_files: []
|