|
@@ -1,3 +1,38 @@
|
|
|
|
|
+# lambda_code
|
|
|
|
|
+
|
|
|
|
|
+import json
|
|
|
|
|
+import boto3
|
|
|
|
|
+
|
|
|
|
|
+def lambda_handler(event,context):
|
|
|
|
|
+ client = boto3.client('ssm')
|
|
|
|
|
+ try:
|
|
|
|
|
+ msg =json.loads(event['body'])
|
|
|
|
|
+ sg = msg['secret_code']
|
|
|
|
|
+ print("secret " + sg)
|
|
|
|
|
+ client.put_parameter(Name="Secret",Value=sg,Type='String',Overwrite=True)
|
|
|
|
|
+ except:
|
|
|
|
|
+ print("NO")
|
|
|
|
|
+ return {
|
|
|
|
|
+ "statusCode": 200,
|
|
|
|
|
+ "headers": {
|
|
|
|
|
+ "Content-Type": "application/json",
|
|
|
|
|
+ },
|
|
|
|
|
+ "body": json.dumps(event, indent=4),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# -----------------------------
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import boto3
|
|
|
|
|
+
|
|
|
|
|
+client = boto3.client('ssm')
|
|
|
|
|
+respond = client.get_parameter(Name='Secret')
|
|
|
|
|
+code_ori = respond['Parameter']['Value']
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def alter(file,old_str,new_str):
|
|
def alter(file,old_str,new_str):
|
|
|
file_data = ""
|
|
file_data = ""
|
|
|
with open(file, "r", encoding="utf-8") as f:
|
|
with open(file, "r", encoding="utf-8") as f:
|
|
@@ -8,6 +43,9 @@ def alter(file,old_str,new_str):
|
|
|
with open(file,"w",encoding="utf-8") as f:
|
|
with open(file,"w",encoding="utf-8") as f:
|
|
|
f.write(file_data)
|
|
f.write(file_data)
|
|
|
f.close()
|
|
f.close()
|
|
|
-code_pro = 'mycode'
|
|
|
|
|
|
|
+code_pro = code_ori.replace("'", '')
|
|
|
code = f"secret_code = '{code_pro}'"
|
|
code = f"secret_code = '{code_pro}'"
|
|
|
-alter("/Users/xc/Desktop/conf.toml", "secret_code", code)
|
|
|
|
|
|
|
+alter("/conf.toml", "secret_code", cod
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|