Event-driven SSM Param backups and point-in-time restore.
Project description
The AWS SSM Parameter Store is simple and great for AWS config bits, but SSM only preserves 100 versions and maintains no record of deletion.
To enable point-in-time restore, including deleted versions and entire recursive trees, we use an s3 bucket with versioning enabled as a backend.
This project includes all the pieces to both backup and restore SSM Params to a point in time. Bonus: generic s3bak preview/restore/download.
- Backup: Eventbridge -> SQS -> Lambda -> S3
- launch cloudformation stack from
template
with
ssmbak-stack <name> create.
- launch cloudformation stack from
template
with
- Restore with either:
ssmbak restorecli, which uses- the well-tested library
from ssmbak.restore.actions import ParamPath
ParamPath.restore()
Quickstart
You'll need credentials that can create IAM resources with Cloudformation (to assign minimal permissions to the lambda role).
pip install ssmbak
ssmbak-stack <SSMBAK_STACKNAME> create
That's it. All new params will automatically be backed-up and
available for ssmbak point-in-time restore via CLI or lib, like:
ssmbak preview /my/ssm/path/ 2024-06-15T17:56:58
ssmbak preview /my/ssm/path/ 2024-06-15T17:56:58 -R
ssmbak restore /my/ssm/path/ 2024-06-15T17:56:58
The same point-in-time machinery is exposed as s3bak, a standalone CLI (and S3Path lib class) for any versioned S3 bucket — not just ssmbak's. Subcommands: preview, body (download a past version to a file), restore. Bucket is explicit since it isn't tied to a stack:
SSMBAK_BUCKET=`ssmbak-stack <SSMBAK_STACKNAME> bucketname`
s3bak preview my/object/key 2024-06-15T17:56:58 -b $SSMBAK_BUCKET
s3bak restore my/object/key 2024-06-15T17:56:58 -b $SSMBAK_BUCKET
s3bak body my/object/key 2024-06-15T17:56:58 -b $SSMBAK_BUCKET -o ./key
You need a bunch of shady permissions to create the stack. Look for such errors if it fails.
CLI and Lib Tutorials available, CLI codified in experimental script tests/verify_cli_tutorial.sh that does the steps.
Backup Guarantees
Event Time Preservation
-
Regular backups (Create/Update): Event time is preserved via S3 object tags (
ssmbakTime), ensuring accurate point-in-time restore even during Lambda processing delays or outages. -
Delete markers: Event time cannot be preserved because S3 delete markers don't support tags. Delete markers use S3's
LastModifiedtimestamp (when the Lambda processed the delete) instead of the original event time.
Implications During Outages
If SQS messages queue up during an outage and delete events are processed late:
-
Worst case: A parameter that was deleted may appear with its last value instead of showing as deleted when querying for a time between the actual deletion and when the Lambda processed it.
-
Safe failure mode: You might restore previously deleted data (resurrection), but you will never lose data that actually existed at the query time.
Example:
- T1: Parameter has value "important"
- T2: Parameter deleted
- T3-T10: Lambda outage (delete event queued)
- T11: Lambda processes delete, creates delete marker with LastModified=T11
- Query at T5: Returns "important" (last backup before T5) instead of showing deleted
This is an inherent limitation of S3 delete markers not supporting tags.
Scripts
-
ssmbak-allwill back up all SSM params to the bucket. You can also give it a path. -
ssmbak-stackcan create, update and give you info about the stack, including all its resources. -
-hfor more info.
Seed backups for all previously set SSM Params with ssmbak-all. It
will just show you what would be backed-up. --do-it to actually
perform the backups.
If you download a new version, best to get that same version running in the Lambda with:
ssmbak-stack <SSMBAK_STACKNAME> update
The lambda is configured to write logs to cloudwatch.
SSMBAK_LAMBDANAME=`ssmbak-stack $SSMBAK_STACKNAME lambdaname`
aws logs tail --format short /aws/lambda/$SSMBAK_LAMBDANAME
2024-06-13T20:11:07 INIT_START Runtime Version: python:3.13.v36 Runtime Version ARN: arn:aws:lambda:us-west-2::runtime:bbd47e5ef4020932b9374e2ab9f9ed3bac502f27e17a031c35d9fb8935cf1f8c
2024-06-13T20:11:07 START RequestId: d404f4c7-1c53-5e41-a7db-aa2248dee8cd Version: $LATEST
2024-06-13T20:11:10 [INFO] 2024-06-13T20:11:10.776Z d404f4c7-1c53-5e41-a7db-aa2248dee8cd put_object {'Bucket': 'ssmbak-bucket-vhvs73zpfvy5', 'Key': '/testyssmbak/3', 'Tagging': 'ssmbakTime=1718309456&ssmbakType=String', 'Body': 'initial'}
2024-06-13T20:11:10 [INFO] 2024-06-13T20:11:10.964Z d404f4c7-1c53-5e41-a7db-aa2248dee8cd result: 200
2024-06-13T20:11:11 END RequestId: d404f4c7-1c53-5e41-a7db-aa2248dee8cd
2024-06-13T20:11:11 REPORT RequestId: d404f4c7-1c53-5e41-a7db-aa2248dee8cd Duration: 3430.49 ms Billed Duration: 3431 ms Memory Size: 128 MB Max Memory Used: 84 MB Init Duration: 282.28 ms
...
Development
This is a poetry project, so it should be butter once you get that sorted. Install pre-commit for ruff check/format on commit, mypy on push.
Testing
Testing uses localstack, as you can see in the Github
actions. docker compose up ssmbak --detach, then poetry run pytest.
-
Recent docker versions allow for
docker-compose up --watch, allowing for hot-reloading of the lambda. -
Lambda tests use both the lambda's backup function and hitting the local container running it.
Testing Gotchas
- Tests are pinned to localstack via
tests/safety.py— boto3 client creation raisesRuntimeErrorfor any non-localstack endpoint. Don't disable this; tests will set versioning on the bucket and manipulate/destroypytest.test_path.
Addenda
ssmbak-stackcreates two alarms for the process queue, in case you'd like to configure some actions.- Use a custom kms key for added security, which will require you to set up the infra.
- Support for advanced ssm params has not been tested at all.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ssmbak-0.5.2.tar.gz.
File metadata
- Download URL: ssmbak-0.5.2.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d3a0b0b6ea2360df6ea0a4e703e8c97240473de4d28e6d6d5294d9906e4bbda
|
|
| MD5 |
50726de034f159114d5a731e5fd144a6
|
|
| BLAKE2b-256 |
03bba393ee9234de451ad7ab4bae151bafe0ad503e6827057e3e6d6589099c12
|
Provenance
The following attestation bundles were made for ssmbak-0.5.2.tar.gz:
Publisher:
publish.yml on newvoll/ssmbak
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssmbak-0.5.2.tar.gz -
Subject digest:
0d3a0b0b6ea2360df6ea0a4e703e8c97240473de4d28e6d6d5294d9906e4bbda - Sigstore transparency entry: 1724774854
- Sigstore integration time:
-
Permalink:
newvoll/ssmbak@cc6e8e9c6720def6851d235e6ba7b47047d8c279 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/newvoll
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cc6e8e9c6720def6851d235e6ba7b47047d8c279 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ssmbak-0.5.2-py3-none-any.whl.
File metadata
- Download URL: ssmbak-0.5.2-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
495b451cc1487ec36cbc8a9d82669bf46b85f8e2736023e8be1ad1a310bc1515
|
|
| MD5 |
e847ba8ca8f67046593aa180cfd967a4
|
|
| BLAKE2b-256 |
fe329ef5689a23a6a18772d668207d0abcb533e1ebb57966e46324e979f82f40
|
Provenance
The following attestation bundles were made for ssmbak-0.5.2-py3-none-any.whl:
Publisher:
publish.yml on newvoll/ssmbak
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ssmbak-0.5.2-py3-none-any.whl -
Subject digest:
495b451cc1487ec36cbc8a9d82669bf46b85f8e2736023e8be1ad1a310bc1515 - Sigstore transparency entry: 1724774930
- Sigstore integration time:
-
Permalink:
newvoll/ssmbak@cc6e8e9c6720def6851d235e6ba7b47047d8c279 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/newvoll
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cc6e8e9c6720def6851d235e6ba7b47047d8c279 -
Trigger Event:
push
-
Statement type: