Skip to content

Instantly share code, notes, and snippets.

@vishnuhd
Created April 18, 2020 10:10
Show Gist options
  • Select an option

  • Save vishnuhd/670aabdcb60a8c22044241161d3f971f to your computer and use it in GitHub Desktop.

Select an option

Save vishnuhd/670aabdcb60a8c22044241161d3f971f to your computer and use it in GitHub Desktop.

Revisions

  1. vishnuhd created this gist Apr 18, 2020.
    22 changes: 22 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import boto3
    import os
    import json
    filename = 'data.json'
    kms_id = ''
    secretdata= {"username":"chris","password":"BnQw!XDWgaEeT9XGTT29"}
    secret_data={}
    for k,v in secretdata.items():
    encrypt_string = os.popen(("aws kms encrypt --key-id %s --plaintext '%s' --query CiphertextBlob --output text" % (kms_id, v))).read()
    secret_data[k] = encrypt_string
    json_data = json.dumps(secret_data)
    with open(filename,'w') as f:
    f.write(json_data)
    with open('data.json', 'r') as content_file:
    secret_content = content_file.read()
    print(secret_content)
    client = boto3.client('secretsmanager')
    response = client.create_secret(
    Description='My test secret',
    Name='MyTestt',
    SecretString=secret_content,
    )