Skip to content

Commit 51f52e8

Browse files
authored
Scoped environment variables pattern (#39)
1 parent 844c092 commit 51f52e8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,29 @@ Shown below is a simple Node.js 16 function which has the appropriate [IAM Permi
201201

202202
![Screenshot of Code source in the AWS Lambda Console showing the `body` results of `1A2B3C4D5E6F` which is resolved from SSM Parameter Store.](/images/readme-code-results.png)
203203

204+
#### Scope variables to a specific environment
205+
Your `template.yaml` file can contain a variable that indicates the environment of the app. You can use this variable to fetch the correct env variable in SSM depending on the environment you are deploying your app to.
206+
For exemple, a [Lamby app](https://lamby.cloud/docs/quick-start) has a `RailsEnv` variable in the `template.yaml` file that indicates the environment you are deploying the app:
207+
```yaml
208+
Parameters:
209+
210+
RailsEnv:
211+
Type: String
212+
Default: staging
213+
AllowedValues:
214+
- staging
215+
- production
216+
```
217+
This variable can be used to get SSM variables that follow this path: `/myapp/${RailsEnv}/MY_VARIABLE`. The `template.yaml` file will then look like this:
218+
```yaml
219+
Environment:
220+
Variables:
221+
SECRET: x-crypteia-ssm:/myapp/${RailsEnv}/SECRET
222+
ACCESS_KEY: x-crypteia-ssm:/myapp/${RailsEnv}/access-key
223+
X_CRYPTEIA_SSM: x-crypteia-ssm-path:/myapp/${RailsEnv}/envs
224+
```
225+
This way you can have one different SSM variable for each one of your environments.
226+
204227
#### IAM Permissions
205228

206229
Please refer to the AWS guide on [Restricting access to Systems Manager parameters using IAM policies](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-access.html) for details on which policies your function's IAM Role will need. These examples assume the `/myapp` prefix and should work for direct secrets in that path or further nesting in a path prefix as described in the [usage section](#usage).

0 commit comments

Comments
 (0)