This lab provides a step-by-step introduction to using a Secrets Manager to securely store, retrieve, and utilize sensitive information, such as passwords or API keys. The instructions are designed for beginners and include visual aids to ensure clarity.
Step 1: Configure the Secrets Manager
-
Log in to the AWS Management Console (or your chosen cloud provider’s equivalent).
-
In the search bar, type “Secrets Manager” and select the service from the results.
- On the Secrets Manager dashboard, locate and click the Create secret button (labeled as “Store a new secret” or similar).
-
Select the secret type:
- Choose “Other type of secret” for a custom key-value pair.
-
Enter the secret details:
- Key:
my_password - Value:
SuperSecret123!
-
Assign a name to the secret, such as my-first-secret.
-
Proceed by clicking Next, then Store, leaving optional settings at their defaults.
Step 2: Retrieve the Secret
-
Return to the Secrets Manager dashboard.
-
Locate
my-first-secretin the list of secrets and click its name to view details.
- Select the option to Retrieve secret value (or a similar command) to display the secret.
- Note the secret value (
SuperSecret123!) or copy the secret’s ARN (Amazon Resource Name) for later use.
Step 3: Access the Secret Programmatically
-
Open a text editor and create a new file named
get_secret.py. -
Insert the following Python code to retrieve the secret from AWS Secrets Manager:
import boto3
# Initialize a Secrets Manager client
client = boto3.client(
'secretsmanager',
region_name='us-east-1',
aws_access_key_id='AK..', # Replace with your Access Key ID
aws_secret_access_key='Q4R..' # Replace with your Secret Access Key
)
# Specify the secret name and retrieve its value
secret_name = "my-first-secret" #Replace with your Secret ARN
response = client.get_secret_value(SecretId=secret_name)
secret = response['SecretString']
# Display the secret
print("Retrieved secret:", secret)
- Save the file.
- Install the required Python library:
- Open a terminal and execute:
pip install boto3.
- Configure your AWS credentials:
- Run
aws configurein the terminal and provide your AWS Access Key, Secret Key, and region.
- Execute the script by running:
python get_secret.py.
Upon successful execution, the terminal will display:
Step 4: Cleanup
-
Navigate back to the Secrets Manager dashboard.
-
Select
my-first-secretand choose the option to delete it. -
Confirm the deletion to maintain a tidy environment.
This lab demonstrates the fundamental operations of a Secrets Manager in a straightforward manner. For further assistance or advanced configurations, feel free to reach out.







