-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial work to do reliable backup of SSM parameters #1
base: reviewed
Are you sure you want to change the base?
Changes from 10 commits
4580b51
e63677e
e58ccef
ace38e4
fa01ae0
987a120
bd470d6
bba1b78
d9d8609
e85d952
377e36c
e4f85c0
d76b3d6
cd45e42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
*.retry | ||
*~ | ||
*venv | ||
aws_credentials* | ||
*password* | ||
\#* | ||
*environment | ||
*postfix | ||
.#* | ||
*.dat | ||
*.pub | ||
gpgtemp | ||
keys/ | ||
build | ||
*.log | ||
dump.sql* | ||
*.pri | ||
mockstmp | ||
.anslk_* | ||
.prepare* | ||
test-config* | ||
__pycache__ | ||
.mypy_cache | ||
*.gpg | ||
bin/backup_encrypt | ||
*.pyc | ||
dist | ||
MANIFEST | ||
deploy_key | ||
deploy_key.bck | ||
encrypted_build_files | ||
encrypted_build_files.tjz | ||
*.egg-info | ||
*.makestamp | ||
.hypothesis |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
exclude: '^$' | ||
fail_fast: false | ||
repos: | ||
- repo: https://github.com/ambv/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
language_version: python3.7 | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v1.2.3 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-json | ||
- id: detect-private-key | ||
- id: end-of-file-fixer | ||
- id: flake8 | ||
exclude: '^features/.*_steps/*' | ||
args: | ||
- --ignore=W503,E402,E501 | ||
- --max-line-length=131 | ||
- id: forbid-new-submodules | ||
- id: check-yaml | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: 'master' # Use the sha / tag you want to point at | ||
hooks: | ||
- id: mypy | ||
# - repo: https://github.com/Lucas-C/pre-commit-hooks-go | ||
# sha: v1.0.0 | ||
# hooks: | ||
# - id: checkmake |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
AWS_ACCOUNT_NAME ?= michael | ||
AWS_DEFAULT_REGION ?= eu-west-1 | ||
PYTHON ?= python3 | ||
BEHAVE ?= behave | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem to be used anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above - will commit to clear this up soon |
||
|
||
LIBFILES := $(shell find backup_cloud_ssm -name '*.py') | ||
|
||
all: lint test | ||
|
||
# pytest-mocked is much faster than non-mocked which is slower even than | ||
# the functional tests so run it first, then behave then finally the | ||
# full pytest tests so that failures are detected early where possible. | ||
test: develop pytest-mocked behave pytest | ||
|
||
behave: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the comments for the each command (ideally on the same line as the command name) - see the comment about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michael-paddle could you please add this? It is not super clear what each command does |
||
behave --tags ~@future | ||
|
||
pytest-mocked: | ||
MOCK_AWS=true pytest | ||
|
||
pytest: | ||
pytest | ||
|
||
wip: develop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. work in progress - standard behave / BDD development acronym There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what Johan means is it is not clear what this command does. |
||
$(BEHAVE) --wip | ||
|
||
lint: | ||
pre-commit install --install-hooks | ||
pre-commit run -a | ||
|
||
|
||
# develop is needed to install scripts that are called during testing | ||
develop: .develop.makestamp | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If needed, can we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it's useful; setup alone doesn't get you to a state where the test cases can pass. I'd rather not get that as something people expect to run until the time that we have it as a useful thing to do. |
||
.develop.makestamp: setup.py backup_cloud_ssm/aws_ssm_cli.py $(LIBFILES) | ||
$(PYTHON) setup.py install --force | ||
$(PYTHON) setup.py develop | ||
touch $@ | ||
|
||
.PHONY: all test behave pytest-mocked pytest wip lint develop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to add the
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Backup SSM parameter store to a file. Optional (but default) | ||
encryption to be added. | ||
|
||
## Using CLI tools | ||
|
||
The CLI tool provides a simple interface to dump or restore the full | ||
set of SSM parameters. | ||
|
||
1) set up the appropriate environment including AWS variables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we be more specific ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||
|
||
export AWS_REGION=us-west-2 | ||
export AWS_ACCESS_KEY_ID=AKIABCDEFGHIJKLMNOPQ | ||
export AWS_SECRET_ACCESS_KEY=1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZABCD | ||
|
||
2) to backup run | ||
|
||
aws-ssm-backup > `<filename>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose it requires to have the previous setup step run before ? |
||
|
||
3) to restore run | ||
|
||
aws-ssm-backup --restore > `<filename>` | ||
|
||
Special notes: | ||
|
||
1) the tool does not overwrite - if you want to replace an existing | ||
parameter, simply manually delete it and run again. | ||
|
||
2) ssm seems to be eventually consistent - you will not want to update | ||
SSM shortly before doing a backup. You may want to wait a second or | ||
so after restoring. | ||
|
||
## Using python interface | ||
|
||
The backup and restore functions are provided as a libray. For backup | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
import backup_aws_ssm | ||
backup_aws_ssm.backup_to_file("myfile") | ||
|
||
for restore: | ||
|
||
import backup_aws_ssm | ||
backup_aws_ssm.restore_from_file("myfile") | ||
|
||
set the appropriate AWS variables to configure the aws region where | ||
this will work. | ||
|
||
## Using python ssm library | ||
|
||
Included in the package is a library which provides a dict object | ||
which accesses SSM parameter store. This will likely, later, be split out into a separate packge. In the meantime it can be used in Alpha testing mode. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
from backup_cloud_ssm.aws_ssm_dict import aws_ssm_dict | ||
ssm_dict = aws_ssm_dict() | ||
ssm_dict["parameter"] = "value" | ||
print(ssm_dict["parameter"]) | ||
|
||
SSM parameter store treats storing no description and storing the | ||
empty description ("") as the same thing and will not return any | ||
description. For simplicity we have now chosen to represent this as | ||
the empty string. This decision may change in future and feedback is | ||
appreciated. | ||
|
||
When parameters are deleted the parameter description sometimes seems | ||
to persist for some time, possibly only when it was '0'. Do not rely | ||
on the description to be empty or see testing/test_parameter_storage | ||
for how to handle this. | ||
|
||
|
||
## Development | ||
|
||
We aim to use Behavior Driven Development to encourage reasonable feature descriptions and a level of tests appropriate for the business functionality included here. Test Driven Development and to some extent Test Driven Design are encouraged in order to improve testability and eas of modification of the code. | ||
|
||
Some of the tests are designed to run against either the Moto library or a real AWS instance. By defining the shell variable MOCK_AWS as "true" all of the tests which can be run in mocked form will be. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is part of README, can we have a link to the |
||
|
||
export MOCK_AWS=true | ||
|
||
This considerably speeds up testing but slightly increases risk since Moto's model of SSM is missing a number of features. | ||
|
||
## Defined functionality | ||
|
||
See the features directory for the supported features of the software. This is considered part of the documentation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from backup_cloud_ssm.backup_aws_ssm import ( # noqa: F401 | ||
backup_to_file, | ||
restore_from_file, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import argparse | ||
import sys | ||
import backup_cloud_ssm | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Backup AWS SSM Parameter Store") | ||
parser.add_argument("--restore", help="restore from stdin", action="store_true") | ||
args = parser.parse_args() | ||
if args.restore: | ||
backup_cloud_ssm.restore_from_file(sys.stdin) | ||
else: | ||
backup_cloud_ssm.backup_to_file(sys.stdout) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove all
AWS
defaults ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's there as a reminder to set up credentials which make it difficult to accidentally do things on production. Will become clear when I add CI.