|
| 1 | +## About this project |
| 2 | + |
| 3 | +Right now the only methods available to deploy AWS SSM Documents are: |
| 4 | +- Using CloudFormation template that can deploy SSM document but cannot set a fixed name otherwise the deploy will fail. |
| 5 | +- Using the web console (until the page is reloaded) but a little bit uncomfortable |
| 6 | + |
| 7 | +This is a third method that allows you to version the code, deploy and manage documents. |
| 8 | + |
| 9 | +PS: Also tried [Serverless Components](https://github.com/daaru00/serverless-plugin-ssm-document) but starts having issue with deployments. |
| 10 | + |
| 11 | +## Install CLI |
| 12 | + |
| 13 | +Download last archive package version from [releases page](https://github.com/daaru00/aws-ssm-document-cli/releases): |
| 14 | + |
| 15 | +* Windows: aws-ssm-document_VERSION_Windows_x86_64.zip |
| 16 | +* Mac: aws-ssm-document_VERSION_Darwin_x86_64.tar.gz |
| 17 | +* Linux: aws-ssm-document_VERSION_Linux_x86_64.tar.gz |
| 18 | + |
| 19 | +Unpack it and copy `aws-ssm-document` into one of your executable paths, for example, for Mac and Linux users: |
| 20 | +```bash |
| 21 | +tar -czvf aws-ssm-document_*.tar.gz |
| 22 | +sudo mv aws-ssm-document /usr/local/bin/aws-ssm-document |
| 23 | +rm aws-ssm-document_*.tar.gz |
| 24 | +``` |
| 25 | + |
| 26 | +### For Linux Users |
| 27 | + |
| 28 | +You can also install CLI from deb or rpm package downloading from releases page: |
| 29 | + |
| 30 | +* aws-ssm-document_1.0.0_linux_amd64.deb |
| 31 | +* aws-ssm-document_1.0.0_linux_amd64.rpm |
| 32 | + |
| 33 | +### For Mac Users |
| 34 | + |
| 35 | +Unlock CLI executable file going to "System Preference > Security and Privacy > General" and click on button "open anyway". |
| 36 | + |
| 37 | +## Commands |
| 38 | + |
| 39 | +Usage: |
| 40 | +```bash |
| 41 | +./aws-ssm-document [global options] command [command options] [path...] |
| 42 | +``` |
| 43 | + |
| 44 | +- **deploy**: Deploy SSM Documents |
| 45 | +- **remove**: Remove SSM Documents |
| 46 | + |
| 47 | +## Environment configuration file |
| 48 | + |
| 49 | +This CLI also load environment variable from `.env` file in current working directory: |
| 50 | +``` |
| 51 | +AWS_PROFILE=my-profile |
| 52 | +AWS_REGION=us-east-1 |
| 53 | +``` |
| 54 | + |
| 55 | +Setting `SSM_DOCUMENT_ENV` environment variable is it possible to load different env file: |
| 56 | +```bash |
| 57 | +export SSM_DOCUMENT_ENV="" |
| 58 | +aws-ssm-document deploy # will load .env file |
| 59 | +``` |
| 60 | +```bash |
| 61 | +export SSM_DOCUMENT_ENV="prod" |
| 62 | +aws-ssm-document deploy # will load .env.prod file |
| 63 | +``` |
| 64 | +```bash |
| 65 | +export SSM_DOCUMENT_ENV="STAGE" |
| 66 | +aws-ssm-document deploy # will load .env.STAGE file |
| 67 | +``` |
| 68 | + |
| 69 | +## Document configuration file |
| 70 | + |
| 71 | +This CLI will search for `document.yml` configurations files, recursively, in search path (provided via first argument of any commands) for configurations file and deploy/remove documents in parallels. The document configuration file looks like this: |
| 72 | +```yaml |
| 73 | +name: MyDocument |
| 74 | +description: My document description |
| 75 | +accountIds: |
| 76 | + - 123456789 |
| 77 | +file: ./script.sh |
| 78 | +parameters: |
| 79 | + ParameterName: |
| 80 | + type: String |
| 81 | + description: "Parameter description" |
| 82 | + Command: |
| 83 | + type: String |
| 84 | + description: "Command to execute" |
| 85 | + default: "default-value" |
| 86 | +tags: |
| 87 | + Project: my-project |
| 88 | + Environment: my-env |
| 89 | + Type: command |
| 90 | +``` |
| 91 | +
|
| 92 | +### Interpolation |
| 93 | +
|
| 94 | +In configuration file it is possible to interpolate environment variables using `${var}` or `$var` syntax: |
| 95 | +```yaml |
| 96 | +name: MyDocument |
| 97 | +file: ./script.sh |
| 98 | +tags: |
| 99 | + Project: "${APP_NAME}" |
| 100 | + Environment: "${ENV}" |
| 101 | +``` |
| 102 | + |
| 103 | +### Search path |
| 104 | + |
| 105 | +Any command accept file or directory paths as arguments, any document configuration file that match will be loaded an added to list. |
| 106 | + |
| 107 | +If a directory is provided the CLI will search recursively for files `document.yml` (configurable via `--config-config-file`) |
| 108 | +and try to parse them using YAML parser (configurable via `--config-config-parser`), for example: |
| 109 | +```bash |
| 110 | +aws-ssm-document deploy ./documents |
| 111 | +``` |
| 112 | + |
| 113 | +Search path and config file name can be set via environment variable (or `.env` file): |
| 114 | +``` |
| 115 | +SSM_DOCUMENT_PATH=./documents/ |
| 116 | +SSM_DOCUMENT_CONFIG_FILE=*.yml |
| 117 | +``` |
| 118 | + |
| 119 | +If a file is provided the CLI will be try to parse using YAML parser (configurable via `--config-config-parser`), for example: |
| 120 | +```bash |
| 121 | +aws-ssm-document deploy examples/simple/document.yml |
| 122 | +``` |
| 123 | + |
| 124 | +Search path can be multiple, every argument respect the rules mentioned above: |
| 125 | +```bash |
| 126 | +aws-ssm-document deploy examples/simple/document.yml examples/parameters/document.yml examples/script/document.yml |
| 127 | +# load 3 documents from provided files |
| 128 | +
|
| 129 | +aws-ssm-document deploy examples/ other-examples/script/document.yml |
| 130 | +# load all documents in examples directory and a single one from other-examples |
| 131 | +
|
| 132 | +aws-ssm-document deploy examples/ other-examples/ |
| 133 | +# load all documents from examples and other-examples directories (all) |
| 134 | +``` |
| 135 | + |
| 136 | +Also a file glob pattern can be used as search paths: |
| 137 | +```bash |
| 138 | +aws-ssm-document deploy examples/**/document.yml |
| 139 | +# load 2 documents, one in nodejs directory and the other in the python one |
| 140 | +``` |
| 141 | + |
| 142 | +Here an example of project configuration with single document: |
| 143 | +```bash |
| 144 | +. |
| 145 | +└── my-command |
| 146 | + ├── document.yml |
| 147 | + └── script.sh |
| 148 | +``` |
| 149 | + |
| 150 | +Here an example of project configuration with multiple documents: |
| 151 | +```bash |
| 152 | +. |
| 153 | +└── documents |
| 154 | + ├── command1 |
| 155 | + │ ├── document.yml |
| 156 | + │ └── script.sh |
| 157 | + ├── command2 |
| 158 | + │ ├── document.yml |
| 159 | + │ └── script.sh |
| 160 | + └── command3 |
| 161 | + ├── document.yml |
| 162 | + └── script.sh |
| 163 | +``` |
| 164 | + |
| 165 | +Configuration file name can be changed via `--config-file` parameter: |
| 166 | +```bash |
| 167 | +aws-ssm-document deploy --config-file="ssm.yml" /commands/ |
| 168 | +. |
| 169 | +└── commands |
| 170 | + ├── command1 |
| 171 | + │ ├── ssm.yml |
| 172 | + │ └── script.sh |
| 173 | + ├── command2 |
| 174 | + │ ├── ssm.yml |
| 175 | + │ └── script.sh |
| 176 | + └── command3 |
| 177 | + ├── ssm.yml |
| 178 | + └── script.sh |
| 179 | +``` |
| 180 | +both exact match and wildcard pattern can be used: |
| 181 | +```bash |
| 182 | +aws-ssm-document deploy --config-file="*.yml" /commands/ |
| 183 | +. |
| 184 | +└── commands |
| 185 | + ├── command1.yml |
| 186 | + ├── command2.yml |
| 187 | + ├── command3.yml |
| 188 | + └── script.sh # export single script |
| 189 | +``` |
| 190 | + |
| 191 | +## Deploy documents |
| 192 | + |
| 193 | +To deploy documents run the `deploy` command: |
| 194 | +```bash |
| 195 | +aws-ssm-document deploy |
| 196 | +``` |
| 197 | + |
| 198 | +## Remove documents |
| 199 | + |
| 200 | +To remove (only) documents run the `remove` command: |
| 201 | +```bash |
| 202 | +aws-ssm-document remove |
| 203 | +``` |
0 commit comments