We have seen how to take the parameter store backup in the previous blog(URL: https://medium.com/supportsages/automating-ssm-parameter-store-backup-using-python-2acfc1cd6482). Now we are going to have a look into how we can restore these backups to the parameter store.
Requirements
- Python3 should be installed on your machine.
- Boto3 should be installed.
- AWS CLI profile configured with necessary access to S3 and SSM parameter store.
You can use the script given below to restore these backups to the parameter store.
import boto3
session = boto3.Session(region_name="<Region>" , profile_name="<Profile_name")
client = boto3.client('ssm')
s3 = boto3.client('s3')
def paramrestore():
with open(file_name , "r") as file:
for line in file:
parts = line.split('=',1)
if len(parts) == 2:
left_side = parts[0].strip()
right_side = parts[1].strip()
print(f"Updating parameter with name {left_side}")
client.put_parameter(
Name = left_side,
Value = right_side,
Type = 'String',
Overwrite=True
)
consent = input("Is the backup file in s3? (yes/no)").strip().lower()
if consent == "yes":
bucket_name = input("Please enter the name of the bucket where the backup file resides : ")
file_name = input("Enter the name of the backup file : ")
s3.download_file(bucket_name, file_name, file_name)
paramrestore()
elif consent == "no":
file_name = input("Please enter the path to the parameter backup file : ")
paramrestore()
else:
print("please enter a valid input (yes/no)")Here the script will ask the user if the backup is in s3 or not. If the backup is in S3 the script will download the file from S3 to our local machine. Then it will be restored to the parameter store.
If the backups are not in S3 the script will ask for the location of the file in the local machine. Then it will be restored to the parameter store.

The above picture depicts the execution of the Python script file, if the backup file is in S3 the script will ask the user for the s3 bucket name and also the name of the file. Then the script will download the file to the local system and restore it to the parameter store. If the backup file is not in S3 bucket the script will ask for the full path of the backup file and restore it accordingly.

That’s it thank you have a nice day.
Enhance your AWS environment effortlessly! Explore SupportSages’ complete guide for streamlined AWS Parameter Store backup restoration. Access expert insights, step-by-step instructions, and a purpose-built Python script. Fortify your system’s resilience and secure critical data integrity with ease. Discover more at SupportSages







