File size: 723 Bytes
0101ee2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# parameter_utils.py
import os

import boto3

ssm = boto3.client('ssm', region_name='ap-southeast-3')

def init_secret(path):
    next_token = None
    while True:
        response = ssm.get_parameters_by_path(
            Path=path,
            Recursive=True,
            WithDecryption=True,
            NextToken=next_token if next_token else "",
        )
        parameters = response.get("Parameters", [])
        for parameter in parameters:
            key = parameter.get("Name").split("/")[-1]
            value = parameter.get("Value")
            os.environ[key] = value
            print(f"Set env variable {key}")

        next_token = response.get("NextToken")
        if not next_token:
            break