forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_system_parameters.py
34 lines (28 loc) · 1.57 KB
/
store_system_parameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import boto3
# This file writes key-value mappings to AWS Parameter Store.
def generate_parameter_store_values(account_id_mappings):
# Create an SSM client using boto3 library
ssm = boto3.client('ssm')
# Iterate through each key-value pair in the account_id_mappings list
for key, value in account_id_mappings:
try:
# Check if the parameter with the specified name (key) already exists in Parameter Store
ssm.get_parameter(Name=key, WithDecryption=True)
# If the parameter already exists, update its value with the new value
print(f"Parameter '{key}' already exists. Updating the value...")
ssm.put_parameter(Name=key, Value=value, Type='SecureString', Overwrite=True)
except ssm.exceptions.ParameterNotFound:
# If the parameter does not exist, create a new parameter with the given key-value pair
print(f"Parameter '{key}' does not exist. Creating a new parameter...")
ssm.put_parameter(Name=key, Value=value, Type='SecureString')
if __name__ == "__main__":
# List of key-value pairs representing parameter names and their corresponding values
mappings = [
('/account-mappings/ruby', '260778392212'),
('/account-mappings/dotnetv3', '565846806325'),
('/account-mappings/javav2', '814548047983'),
('/account-mappings/python', '489398071715'),
('/account-mappings/gov2', '489398071715')
]
# Call the function to generate or update the parameter values in Parameter Store
generate_parameter_store_values(mappings)