Getting Started
After you installed this package, the next step is to import the package into your code and start using the functions.
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
As a demonstration of the library, let's build a simple example together that will do something cool .
Setting up connection
Note
There are two different ways to authenticate.
1. Creating the .aws
folder in the home directory, you need to create two files.
# ~/.aws/config
[default]
region=<region_code>
# ~/.aws/credentials
[default]
aws_access_key_id=<your_aws_access_key_id>
aws_secret_access_key=<your_aws_secret_access_key>
secrets = BotSecretsManagerPlugin()
2. Passing credentials in the class constructor.
secrets = BotSecretsManagerPlugin(
use_credentials_file=False,
access_key_id='<your_aws_access_key_id>',
secret_access_key='<your_aws_secret_access_key>',
region_name='<region_code>'
)
Info: If not found secret
Some methods return None
if they don't find the secret, if you want to receive the error and handle it use RAISE_IF_NOT_FOUND=True
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
secret.RAISE_IF_NOT_FOUND=True # default is False
Create new secret
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
response = secret.create_secret(
secret_name='test',
secret_value={'key': 'name'}, # dict or str
description='Test description.')
print(response)
# Or
secret["test"] = {'key': 'name'} # description=''
List secrets
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
print(secret.list_secrets())
Retrieves secret info
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
print(secret.describe_secret(secret_name='test'))
Retrieve secret value
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
print(secret.get_secret_value(secret_name='test'))
# Or
print(secret["test"])
Update secret value
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
print(secret.update_secret(secret_name='test', secret_value={'key2': 'value2'}, description='New value'))
Delete secret
Warning
If you delete a secret with the without_recovery=True
parameter, then you have no opportunity to recover the secret. You lose the secret permanently.
from botcity.plugins.aws.secretsmanager import BotSecretsManagerPlugin
secret = BotSecretsManagerPlugin()
print(secret.delete_secret(secret_name='test', without_recovery=True))
# Or
del secret["test"] # without_recovery=False
Next Steps
Check our examples and experiment with the API. Let us know where it can be improved.
Have fun automating!