is2-aws-ssm-env 0.1.1
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 +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE +201 -0
- data/README.md +355 -0
- data/README_ja.md +322 -0
- data/lib/aws-ssm-env.rb +160 -0
- data/lib/aws-ssm-env/fetcher.rb +120 -0
- data/lib/aws-ssm-env/fetchers/begins_with.rb +84 -0
- data/lib/aws-ssm-env/fetchers/factory.rb +67 -0
- data/lib/aws-ssm-env/fetchers/path.rb +75 -0
- data/lib/aws-ssm-env/loader.rb +67 -0
- data/lib/aws-ssm-env/naming_strategies/basename.rb +19 -0
- data/lib/aws-ssm-env/naming_strategies/factory.rb +68 -0
- data/lib/aws-ssm-env/naming_strategies/snakecase.rb +58 -0
- data/lib/aws-ssm-env/naming_strategy.rb +23 -0
- data/lib/aws-ssm-env/version.rb +3 -0
- data/spec/aws-ssm-env/fetcher_spec.rb +158 -0
- data/spec/aws-ssm-env/fetchers/begins_with_spec.rb +106 -0
- data/spec/aws-ssm-env/fetchers/factory_spec.rb +65 -0
- data/spec/aws-ssm-env/fetchers/path_spec.rb +100 -0
- data/spec/aws-ssm-env/loader_spec.rb +84 -0
- data/spec/aws-ssm-env/naming_strategies/basename_spec.rb +14 -0
- data/spec/aws-ssm-env/naming_strategies/factory_spec.rb +57 -0
- data/spec/aws-ssm-env/naming_strategies/snakecase_spec.rb +78 -0
- data/spec/aws-ssm-env/naming_strategy_spec.rb +11 -0
- data/spec/aws-ssm-env/parameter.rb +7 -0
- data/spec/aws-ssm-env_spec.rb +128 -0
- data/spec/spec_helper.rb +22 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2596df3b035e162294fa921eef5782e718d963231d5bb4ca252d5e0aec5d81e9
|
4
|
+
data.tar.gz: d9b45671edb74f506c90bb8d53271ca29387d17b622340ec83ad55543bd7988c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34b6a1360750e596072027da2e5d0a7dfa6c86fe3e3e44fa61fcbd506190eec0b75396952e565d70c95f53d714f5ab63eaa0edae221f71b22ee696466912924e
|
7
|
+
data.tar.gz: 5feca5652db1f2d50070783243f34984b8a63c9938069c2cfee8283fbd1bc3a66ec8a3f67b0f95ee362c3d8beb603abe8a6ede1ef778c83ead6019c677030863
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,355 @@
|
|
1
|
+
[](https://travis-ci.org/sonodar/aws-ssm-env-ruby)
|
2
|
+
[](https://coveralls.io/github/sonodar/aws-ssm-env-ruby?branch=master)
|
3
|
+
[](https://badge.fury.io/rb/aws-ssm-env)
|
4
|
+
|
5
|
+
# aws-ssm-env
|
6
|
+
|
7
|
+
This tool sets parameters acquired from `AWS EC2 Parameter Store` as environment variables.
|
8
|
+
|
9
|
+
By default, the last hierarchy of the parameter name is
|
10
|
+
set as the environment variable name.
|
11
|
+
|
12
|
+
For example, if the parameter name is `/staging/secure/DB_PASSWORD`,
|
13
|
+
the parameter value is set to `ENV['DB_PASSWORD']`.
|
14
|
+
The naming of environment variables is optional and can be customized.
|
15
|
+
(described later)
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
This gem has been tested with ruby version 2.2 to 2.5.
|
20
|
+
|
21
|
+
```
|
22
|
+
gem install aws-ssm-env
|
23
|
+
```
|
24
|
+
|
25
|
+
### Rails
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Gemfile
|
29
|
+
gem 'aws-ssm-env', group: :aws
|
30
|
+
```
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# config/application.rb
|
34
|
+
if defined?(AwsSsmEnv)
|
35
|
+
AwsSsmEnv.load(path: "/myapp/#{ENV['RAILS_ENV']}", recursive: true)
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### Other ruby program
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'aws-ssm-env'
|
43
|
+
AwsSsmEnv.load!(begins_with: "myapp.#{ENV['RACK_ENV']}.")
|
44
|
+
```
|
45
|
+
|
46
|
+
## Quick Start
|
47
|
+
|
48
|
+
First of all, register the parameters in `AWS EC2 Parameter Store`.
|
49
|
+
|
50
|
+
```shell
|
51
|
+
# ex) register /myservice/staging/RDS_PASSWORD with SecureString
|
52
|
+
aws ssm --region ap-northeast-1 put-parameter \
|
53
|
+
--name /myservice/staging/RDS_PASSWORD \
|
54
|
+
--type SecureString --value <secret value>
|
55
|
+
```
|
56
|
+
|
57
|
+
Then, set authentication information of AWS.
|
58
|
+
For example, you can use environment variables as follows,
|
59
|
+
|
60
|
+
```shell
|
61
|
+
export AWS_ACCESS_KEY_ID=YOURACCESSKEYID
|
62
|
+
export AWS_SECRET_ACCESS_KEY=YOURSECRETKEY
|
63
|
+
bundle exec rails start
|
64
|
+
```
|
65
|
+
|
66
|
+
Or, you can pass `ssm_client_args` as the argument for `AwsSsmEnv#load`:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
AwsSsmEnv.load(
|
70
|
+
fetch: "/myservice/#{ENV['RAILS_ENV']}",
|
71
|
+
ssm_client_args: {
|
72
|
+
access_key_id: 'ACCESS_KEY_ID',
|
73
|
+
secret_access_key: 'SECRET_ACCESS_KEY',
|
74
|
+
region: 'ap-northeast-1',
|
75
|
+
}
|
76
|
+
)
|
77
|
+
```
|
78
|
+
|
79
|
+
You can also use `Aws.config`.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
|
83
|
+
if defined?(AwsSsmEnv)
|
84
|
+
AWS.config({
|
85
|
+
access_key_id: 'ACCESS_KEY_ID',
|
86
|
+
secret_access_key: 'SECRET_ACCESS_KEY',
|
87
|
+
region: 'ap-northeast-1',
|
88
|
+
})
|
89
|
+
AwsSsmEnv.load(path: "/myservice/#{ENV['RAILS_ENV']}")
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
For details, refer to the document of aws-sdk.
|
94
|
+
|
95
|
+
## Develop
|
96
|
+
|
97
|
+
### Unit test
|
98
|
+
|
99
|
+
```shell
|
100
|
+
bundle exec rspec
|
101
|
+
bundle exec rubocop
|
102
|
+
```
|
103
|
+
|
104
|
+
### Integration test
|
105
|
+
|
106
|
+
```shell
|
107
|
+
export AWS_ACCESS_KEY_ID=xxxx
|
108
|
+
export AWS_SECRET_ACCESS_KEY=xxxx
|
109
|
+
export AWS_REGION=xxxx
|
110
|
+
bundle exec rspec --tag integration
|
111
|
+
```
|
112
|
+
|
113
|
+
IAM users who run tests need the following authorization policy:
|
114
|
+
|
115
|
+
```json
|
116
|
+
{
|
117
|
+
"Version": "2012-10-17",
|
118
|
+
"Statement": [
|
119
|
+
{
|
120
|
+
"Sid": "",
|
121
|
+
"Effect": "Allow",
|
122
|
+
"Action": [
|
123
|
+
"ssm:PutParameter",
|
124
|
+
"ssm:DeleteParameters",
|
125
|
+
"ssm:DescribeParameters",
|
126
|
+
"ssm:GetParameters*"
|
127
|
+
],
|
128
|
+
"Resource": "*"
|
129
|
+
}
|
130
|
+
]
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
|
135
|
+
## Usage
|
136
|
+
|
137
|
+
Here are descriptions of the options passed to `AwsSsmEnv#load`.
|
138
|
+
|
139
|
+
### decryption: [Boolean]
|
140
|
+
|
141
|
+
Flag indicating whether to decrypt SecureString parameters.
|
142
|
+
If `true` is specified, the value of the acquired SecureString parameter is decrypted.
|
143
|
+
In case of `false` it is set as encrypted and environment variable value.
|
144
|
+
Since it is a gem for this, the default is `true` (decrypt).
|
145
|
+
|
146
|
+
### overwrite: [Boolean]
|
147
|
+
|
148
|
+
Specify whether to overwrite an already set environment variable.
|
149
|
+
If `true` is specified, even if the environment variable is set,
|
150
|
+
it overwrites it with the acquired parameter value.
|
151
|
+
If `false` is specified, do not overwrite already set environment variables.
|
152
|
+
The default is `false` (do not overwrite).
|
153
|
+
If you invoke `AwsSsmEnv#load!`, This flag will automatically be set to `true`.
|
154
|
+
|
155
|
+
### client: [Aws::SSM::Client]
|
156
|
+
|
157
|
+
Specify an instance of `Aws::SSM::Client`.
|
158
|
+
An option to set it if there are already created instances.
|
159
|
+
If there are no instances created, use `ssm_client_args` instead.
|
160
|
+
|
161
|
+
### ssm_client_args: [Hash]
|
162
|
+
|
163
|
+
Specify a hash to pass to the constructor of `Aws::SSM::Client`.
|
164
|
+
If not specified, `Aws::SSM::Client#new` is called with an empty argument.
|
165
|
+
It is unnecessary when using environment variable
|
166
|
+
or authentication information by `EC2 InstanceProfile`.
|
167
|
+
|
168
|
+
### fetch: [Symbol, AwsSsmEnv::Fetcher, Object]
|
169
|
+
|
170
|
+
Specify parameter fetch strategy.
|
171
|
+
Possible values are `:path`,`:begins_with`
|
172
|
+
or an instance of a class that implements `AwsSsmEnv::Fetcher`,
|
173
|
+
or an instance of a class with a `each` method.
|
174
|
+
If nothing is specified, it is treated as `:path`.
|
175
|
+
But when `begins_with` (which is described later) is specified,
|
176
|
+
it will automatically be `:begins_with`.
|
177
|
+
|
178
|
+
#### `:fetch => :path` or default
|
179
|
+
|
180
|
+
When `:path` is specified, `AwsSsmEnv::PathFetcher` which fetches
|
181
|
+
parameter hierarchy by path specification is used.
|
182
|
+
In this case, the `path` argument described below is required.
|
183
|
+
Also, the `recursive` argument (described later) is used.
|
184
|
+
When acquiring parameters in this way, you need `ssm:GetParametersByPath` authority
|
185
|
+
for the specified path.
|
186
|
+
An example of the IAM policy is shown below.
|
187
|
+
|
188
|
+
```json
|
189
|
+
{
|
190
|
+
"Version": "2012-10-17",
|
191
|
+
"Statement": [
|
192
|
+
{
|
193
|
+
"Sid": "",
|
194
|
+
"Effect": "Allow",
|
195
|
+
"Action": "ssm:GetParametersByPath",
|
196
|
+
"Resource": "arn:aws:ssm:YOUR_REGION:YOUR_ACCOUNT_ID:parameter/YOUR_PATH"
|
197
|
+
}
|
198
|
+
]
|
199
|
+
}
|
200
|
+
```
|
201
|
+
|
202
|
+
#### `:fetch => :begins_with`
|
203
|
+
|
204
|
+
If `:begins_with` is specified, `AwsSsmEnv::BeginsWithFetcher` is used to fetch
|
205
|
+
parameters starting from the character string specified by the parameter name.
|
206
|
+
In this case, the `begins_with` argument described below is required.
|
207
|
+
When acquiring parameters in this way,
|
208
|
+
you need the authority of `ssm:DescribeParameters` and `ssm:GetParameters`
|
209
|
+
for the specified path.
|
210
|
+
An example of the IAM policy is shown below.
|
211
|
+
|
212
|
+
```json
|
213
|
+
{
|
214
|
+
"Version": "2012-10-17",
|
215
|
+
"Statement": [
|
216
|
+
{
|
217
|
+
"Sid": "",
|
218
|
+
"Effect": "Allow",
|
219
|
+
"Action": "ssm:DescribeParameters",
|
220
|
+
"Resource": "arn:aws:ssm:YOUR_REGION:YOUR_ACCOUNT_ID:parameter"
|
221
|
+
},
|
222
|
+
{
|
223
|
+
"Sid": "",
|
224
|
+
"Effect": "Allow",
|
225
|
+
"Action": "ssm:GetParameters",
|
226
|
+
"Resource": "arn:aws:ssm:YOUR_REGION:YOUR_ACCOUNT_ID:parameter/YOUR_PREFIX*"
|
227
|
+
}
|
228
|
+
]
|
229
|
+
}
|
230
|
+
```
|
231
|
+
|
232
|
+
#### other
|
233
|
+
|
234
|
+
If you specify an instance of a class that implements `AwsSsmEnv::Fetcher` in` fetch`,
|
235
|
+
or an instance with a `each` method, that instance will be used as is.
|
236
|
+
|
237
|
+
### naming: [Symbol, AwsSsmEnv::NamingStrategy, Object]
|
238
|
+
|
239
|
+
Specify the naming strategy for the environment variable name.
|
240
|
+
Possible values are `:basename`,`:snakecase`
|
241
|
+
or an instance of a class that implements `AwsSsmEnv::NamingStrategy`,
|
242
|
+
or an instance of a class with a `parse_name` method.
|
243
|
+
If nothing is specified, it is treated as `:basename`.
|
244
|
+
|
245
|
+
#### `:naming => :basename` or default
|
246
|
+
|
247
|
+
If `naming` is not specified or `:basename` is specified,
|
248
|
+
`AwsSsmEnv::BasenameNamingStrategy` whose variable name is
|
249
|
+
the last hierarchy of the parameter hierarchy is used.
|
250
|
+
In this case, for example, if the parameter name is `/myapp/production/DB_PASSWORD`,
|
251
|
+
the parameter value is set to `ENV['DB_PASSWORD']`.
|
252
|
+
|
253
|
+
#### `:naming => :snakecase`
|
254
|
+
|
255
|
+
When `:snakecase` is specified, `AwsSsmEnv::SnakeCaseNamingStrategy` which uses
|
256
|
+
the underscore delimiter of the parameter name's slash delimiter and converts
|
257
|
+
it to uppercase letters as the environment variable name is used.
|
258
|
+
In this case, for example, if the parameter name is `/myapp/production/DB_PASSWORD`,
|
259
|
+
the parameter value is set to `ENV['MYAPP_PRODUCTION_DB_PASSWORD']`.
|
260
|
+
You can specify first part of string to exclude with
|
261
|
+
the `removed_prefix` argument described below.
|
262
|
+
In addition, you can specify characters to be converted to
|
263
|
+
underscores with the `delimiter` option described below.
|
264
|
+
In the following example, the parameter `/myapp/production/db.password` is
|
265
|
+
set to `ENV['DB_PASSWORD']`.
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
AwsSsmEnv.load!(
|
269
|
+
naming: :snakecase,
|
270
|
+
removed_prefix: '/myapp/production',
|
271
|
+
delimiter: /[\/.]/
|
272
|
+
)
|
273
|
+
```
|
274
|
+
|
275
|
+
#### other
|
276
|
+
|
277
|
+
If you specify an instance of a class that implements `AwsSsmEnv::NamingStrategy` in` fetch`,
|
278
|
+
or an instance with a `parse_name` method, that instance is used as is.
|
279
|
+
|
280
|
+
|
281
|
+
### path: [String]
|
282
|
+
|
283
|
+
Required if nothing is specified for `fetch` or if `:path` is specified.
|
284
|
+
This option specifies the path hierarchy for acquiring parameters from `Parameter Store`.
|
285
|
+
In the example below, the parameter immediately under `/myapp/web/production` is acquired.
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
AwsSsmEnv.load(path: '/myapp/web/production')
|
289
|
+
```
|
290
|
+
|
291
|
+
#### recursive: [Boolean]
|
292
|
+
|
293
|
+
Used when no parameter is specified for `fetch` option or when `:path` is specified.
|
294
|
+
If true is specified, acquires all parameters below the specified path hierarchy.
|
295
|
+
If nothing is specified this parameter, it is treated as `false`(one level).
|
296
|
+
In the following example, all parameters below `/myapp/web/production` are acquired.
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
AwsSsmEnv.load(path: '/myapp/web/production', recursive: true)
|
300
|
+
```
|
301
|
+
|
302
|
+
### begins_with: [String, Array<String>]
|
303
|
+
|
304
|
+
Required if `:begins_with` is specified in `fetch`.
|
305
|
+
You can specify the prefix of the parameter name to be acquired by this option.
|
306
|
+
It is also possible to specify more than one in an array (OR condition).
|
307
|
+
In the example below, parameters with names starting with `myapp.web.production` are acquired.
|
308
|
+
|
309
|
+
```ruby
|
310
|
+
AwsSsmEnv.load(path: 'myapp.web.production')
|
311
|
+
```
|
312
|
+
|
313
|
+
### removed_prefix: [String]
|
314
|
+
|
315
|
+
Used when `:snakecase` is specified in `naming`.
|
316
|
+
By this option, you can specify the prefix of the parameter name to exclude
|
317
|
+
from the environment variable name.
|
318
|
+
If `:removed_ prefix` is not specified, and `:begins_with` or `:path` is specified, that will be used.
|
319
|
+
|
320
|
+
### delimiter: [String, Regexp]
|
321
|
+
|
322
|
+
Used when `:snakecase` is specified in `naming`.
|
323
|
+
By this option, you can specify a string or a regular expression to be converted to an underscore.
|
324
|
+
The default is a slash (`/`).
|
325
|
+
|
326
|
+
### fetch_size: [Integer]
|
327
|
+
|
328
|
+
Specify the number of parameters to be acquired with one execution of AWS API.
|
329
|
+
If `:path` is specified, the maximum value is `10` and the default is `10`.
|
330
|
+
If `:begins_with` is specified, the maximum value is `50` and the default is `50`.
|
331
|
+
Usually this parameter is never specified.
|
332
|
+
|
333
|
+
## Security
|
334
|
+
|
335
|
+
Because you must grant authority to acquire secret information,
|
336
|
+
careful attention is required for security operation.
|
337
|
+
|
338
|
+
|
339
|
+
When the `EC2 InstanceProfile` is set, the parameters can be seen by any account on EC2,
|
340
|
+
It is necessary to improve the security level by preparing an IAM User separately
|
341
|
+
from the `EC2 InstanceProfile`.
|
342
|
+
|
343
|
+
If it is only the administrator that you can log in to EC2,
|
344
|
+
it is not much different from having it in a file.
|
345
|
+
|
346
|
+
Since `AWS Fargate` makes it difficult to execute commands on containers,
|
347
|
+
this risk is mitigated.
|
348
|
+
|
349
|
+
## License
|
350
|
+
|
351
|
+
Apache License 2.0
|
352
|
+
|
353
|
+
## Contributors
|
354
|
+
|
355
|
+
- Ryohei Sonoda <[sonodar](https://github.com/sonodar)>
|