Skip to content

Instantly share code, notes, and snippets.

@tomfun
Created July 25, 2022 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfun/52e96f48130258eb5480080f9f36ea28 to your computer and use it in GitHub Desktop.
Save tomfun/52e96f48130258eb5480080f9f36ea28 to your computer and use it in GitHub Desktop.
Пример работы с пайтон проектом
  1. pyenv curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash follow instructions and add PYENV_ROOT
edit  ~/.bashrc

Add this to end

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

For stability it requires libs

sudo apt-get install curl ca-certificates build-essential zlib1g-dev libbz2-dev libssl-dev libreadline-dev libncurses5-dev libsqlite3-dev libgdbm-dev libdb-dev libexpat-dev libpcap-dev liblzma-dev libpcre3-dev libffi-dev
apt install python3-pip python3-openssl python3.8-venv
  1. python 3.7 (aws version for the moment)
pyenv install 3.7.10
python -V #   3.7.10
pyenv virtualenv 3.7.10
pyenv virtualenv 3.7.10 py37_10
# OR
# python -m venv .venv
pyenv activate py37_10
pip install -r requirements.txt
  1. run
python s.py eu-central-1 secret/name
# or
# AWS_PROFILE=cp python s.py eu-central-1 secret/name
#!/bin/env python3
import boto3
import base64
import sys
from botocore.exceptions import ClientError
def get_secret(region_name, secret_name):
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
# Depending on whether the secret is a string or binary, one of these fields will be populated.
if 'SecretString' in get_secret_value_response:
return get_secret_value_response['SecretString']
else:
return base64.b64decode(get_secret_value_response['SecretBinary'])
if __name__ == "__main__":
args = sys.argv[1:]
print(get_secret(
args[0],
args[1]
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment