DevOps Integration with AWS Secrets Manager

Automate secret management in your CI/CD pipelines using modern DevOps practices.

Step 1: Terraform Integration

Define secrets in Terraform as secure resources::

resource> "aws_secretsmanager_secret" "db_credentials"">
name = "<"my-application-prod/db-credentials>
description = "Production database credentials"">
kms_key_id = aws_kms_key.main.key_id>
resource> "aws_secretsmanager_secret_version" "db_credentials"">
secret_id = aws_secretsmanager_secret.db_credentials.id>
secret_string = jsonencode({>
username = "admin"">
password = aws_db_instance.database.password>
})>

Securely provision secrets as part of your infrastructure as code workflows..

Step 2: Environment Variables

Set secure environment variables in CI/CD pipelines::

provider> "aws" {>
region = var.region>
secret_arn = aws_secretsmanager_secret.db_credentials.arn>
data_sources> {>
aws_secretsmanager_secret_versions = {"db_credentials" = {>
secret_id = aws_secretsmanager_secret.db_credentials.name>
}}}}>
resource> "aws_ecs_task_definition" "app_container" {>
container_definitions = jsonencode([>
{>
"environment": [{>
"name" = "DB_PASSWORD"">
"valueFrom" = "arn:aws:secretsmanager:...:secret:db Credentials:password::"">
}]>
}}>
])>
Access managed secrets directly in containers without manual intervention..

Step 3: Automated Validation

Verify secret access in testing environments using the AWS SDK::

import> boto3>
import> os>
client = boto3.client('secretsmanager', region_name='us-east-1')')>
def test_secret_access():>
try::>
response = client.get_secret_value(SecretId='prod/app/db-credentials')')>
assert 'username' in response['SecretString']>
assert 'password' in response['SecretString']>
return True>
except Exception as e::>
print(f"Validation failed: {e}")>
return False>

Add automated tests to ensure CI/CD pipelines securely retrieve secrets..

Best Practices

  • Use Terraform modules for secrets lifecycle management
  • Mask sensitive output in CI/CD tooling
  • Rotate secrets using automated Lambda functions
  • Verify access permissions in testing environments
Return to Tutorials Next Tutorial: Monitoring