Identity and access management (IAM) is the portcullis of a layered security system: it checks who is making a request and whether they are allowed to make it. These checks apply to users and internal services, not just traffic at the network boundary. section 11.2.2
A server that needs a database password should not carry a permanent, hardcoded credential. Instead, it can use a short-lived IAM role to request that secret at runtime. Grant only the permission it needs—such as reading one specific secret—and let the cloud provider rotate the temporary role credentials. section 11.5.1
This approach avoids several avoidable headaches:
- Credentials do not end up in source-control history. section 11.5.1
- A breached service has less authority than an all-powerful database account. section 11.5.1
- Changing a secret does not require rebuilding and redeploying the application. section 11.5.1
Listing 11.2 Secure Runtime Retrieval Refactor
import boto3
import json
from botocore.exceptions import ClientError
def get_database_credentials():
secret_name = "prod/BillingDatabase/Credentials"
region_name = "us-east-1"
# 1. Connect to the highly secure Secrets Manager
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
try:
# 2. Request the credentials at runtime
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
raise e #A
# 3. Parse the secure response
secret_string = get_secret_value_response['SecretString']
secret_dict = json.loads(secret_string)
# 4. Return the credentials to be used by the ORM/Database connection
return secret_dict['username'], secret_dict['password']
db_user, db_pass = get_database_credentials() #B
connect_to_database(db_user, db_pass)
The Python example requests a named secret from AWS Secrets Manager at runtime rather than embedding its value in the application. section 11.5.1





