Last active
May 5, 2022 04:48
-
-
Save readybuilderone/12a79ac1460a88cad9476f31cca71b7a to your computer and use it in GitHub Desktop.
Boto3 Scripts to Clone Elasticache Parameter Group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from curses import has_key | |
from urllib import response | |
import boto3 | |
SourceParameterGroupName = 'sample-source-pg' | |
TargetParameterGroupName = 'sample-target-pg' | |
def createParameterGroup(client, pgName, pgFamily, pgDescription=''): | |
response = client.create_cache_parameter_group( | |
CacheParameterGroupName=pgName, | |
CacheParameterGroupFamily=pgFamily, | |
Description=pgDescription | |
) | |
print(pgName, 'created successfully.') | |
def cloneParameterGroup(client, sourcePGName, targetPGName): | |
initMarker = 'abc' | |
maxRecords = 100 | |
response = client.describe_cache_parameters( | |
CacheParameterGroupName=sourcePGName, | |
Source='system', | |
MaxRecords=maxRecords | |
) | |
for parameter in response['Parameters']: | |
if('ParameterValue' in parameter): | |
try: | |
client.modify_cache_parameter_group( | |
CacheParameterGroupName = targetPGName, | |
ParameterNameValues=[ | |
{ | |
'ParameterName': parameter['ParameterName'], | |
'ParameterValue': parameter['ParameterValue'] | |
} | |
] | |
) | |
print(parameter['ParameterName'], ' cloned.') | |
except Exception as err: | |
print('err', err) | |
def main(): | |
elasticacheClient=boto3.client('elasticache') | |
# createParameterGroup(elasticacheClient, TargetParameterGroupName, 'redis4.0') | |
cloneParameterGroup(elasticacheClient,SourceParameterGroupName, TargetParameterGroupName) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment