AWS Systems Manager Parameter Store cross-region replicator
This Lambda function is designed to replicate parameters stored in the AWS Systems Manager Parameter Store across different regions within the same AWS account. It listens for CloudWatch events and replicates any updated parameters to a specified target region immediately.
Ensure that you have the Serverless Framework installed:
npm install -g serverless
Deploy the Lambda function to your main region, setting the target as your replication region. For example, to replicate from us-east-1
to us-west-2
:
sls deploy --source_region us-east-1 --target_region us-west-2
Establish two-way replication by deploying a counterpart Lambda in the target region:
sls deploy --source_region us-west-2 --target_region us-east-1
Note: To prevent infinite loops in two-way replication setups (the "ping pong" effect), logic is implemented to check if the parameter's value and type match in the target region. If they do, the replication is skipped.
Deploy your function with the updated settings, then update a parameter in your main region:
aws ssm put-parameter --name "/example/parameter" --value "newValue" --type "String" --overwrite --region us-east-1
After a short wait, you should see the parameter replicated in the target region. Verify by retrieving the parameter in both regions:
aws ssm get-parameter --name "/example/parameter" --region us-east-1
Expected output from us-east-1
:
{
"Parameter": {
"Version": [Latest_Version_Number],
"Type": "String",
"Name": "/example/parameter",
"Value": "newValue"
}
}
aws ssm get-parameter --name "/example/parameter" --region us-west-2
Expected output from us-west-2
:
{
"Parameter": {
"Version": [Latest_Version_Number],
"Type": "String",
"Name": "/example/parameter",
"Value": "newValue"
}
}
In instances where the parameter-store-replicator
Lambda has been non-operational, we provide a Python script for manual, retroactive replication of parameters not copied during the downtime.
- Purpose: Facilitates the retroactive replication of parameters missed during Lambda downtime.
- Features:
- Dry-run mode to assess potential changes.
- Skips and logs parameters that exceed size limits.
- Usage:
- Dry-Run Execution: Preview which parameters will be replicated without making changes.
python replicate_parameters.py --source-region us-east-1 --target-region us-west-2 --dry-run
- Actual Replication: Perform the replication of parameters.
python replicate_parameters.py --source-region us-east-1 --target-region us-west-2
- Dry-Run Execution: Preview which parameters will be replicated without making changes.
Please note that this script is intended as a stopgap measure and does not replace the real-time replication capabilities of the parameter-store-replicator
Lambda function.