Skip to content

Commit fca96ff

Browse files
committed
Now uses stage in default&custom SSM key prefixes
Also uses a more appropriate lifecycle hook for updating SSM
1 parent 25500f9 commit fca96ff

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ A simple plugin that, when deploying your API, updates SSM Parameter Store with
44

55
## Configuration
66

7-
The API git versions are updated into SSM using a specific key prefix, which by default is '/api-gateway/versions/'. If you want to supply a custom prefix, you can do so by putting the following configuration in your serverless config file:
7+
The API git versions are updated into SSM using a specific key prefix, which by default is '/api-gateway/<stage>/versions/'. If you want to supply a custom prefix, you can do so by putting the following configuration in your serverless config file:
88

99
```yaml
1010
custom:
1111
ssmApiGitVersion:
1212
ssmPrefix: '/my-custom/prefix/'
1313
```
1414
15-
Note that the plugin currently always uses the region supplied in the `provider` section of serverless configuration, regardless of the command line region parameter.
15+
The `<stage>` placeholder gets replaced with the stack stage.
1616

1717
## Usage
1818

index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ class ServerlessPlugin {
1919
this.commands = {};
2020

2121
this.hooks = {
22-
'deploy:finalize': this.updateGitDescriptionToSsm.bind(this)
22+
'after:aws:deploy:deploy:updateStack': this.updateGitDescriptionToSsm.bind(this)
2323
};
2424
}
2525

2626
updateGitDescriptionToSsm() {
2727
this.serverless.cli.log('SSM API git version: Acquiring git description...');
2828

29-
const region = this.serverless.service.provider.region;
29+
const stage = this.options.stage;
30+
const region = this.options.region;
3031

3132
const SSM = new AWS.SSM({ region });
3233

@@ -46,7 +47,11 @@ class ServerlessPlugin {
4647

4748
return promisexec('git describe --tags')
4849
.then(value => {
49-
const ssmPrefix = this.serverless.service.custom.ssmApiGitVersion.ssmPrefix || '/api-gateway/versions/';
50+
const ssmPrefix = (this.serverless.service.custom
51+
&& this.serverless.service.custom.ssmApiGitVersion
52+
&& this.serverless.service.custom.ssmApiGitVersion.ssmPrefix)
53+
? this.serverless.service.custom.ssmApiGitVersion.ssmPrefix.replace(/<stage>/g, stage)
54+
: `/api-gateway/${stage}/versions/`;
5055
const name = ssmPrefix + this.serverless.service.service;
5156

5257
this.serverless.cli.log(`SSM API git version: Updating git description '${value}' to SSM with key '${name}' at region ${region}`);

0 commit comments

Comments
 (0)