AWS Secrets Manager: Tutorial & best practices
AWS Secrets Manager vs KMS: Differences & synergies
AWS Secrets Manager vs. Parameter Store: Features, cost & more
AWS CLI Secrets Manager: In-depth tutorial with examples
AWS Secrets Manager with Terraform: Tutorial & examples
AWS KMS key rotation: Tutorial & best practices
AWS Secrets Manager for Kubernetes: Tutorial & best practices
AWS Secrets Manager alternatives: A comprehensive analysis
AWS Lambda Secrets Manager best practices
AWS Vault: Tutorial, best practices & limitations
AWS CDK Secrets Manager tutorial & best practices
SSM Parameter Store: Tutorial & best practices
The AWS Secrets Manager helps users manage and protect their sensitive information in the AWS cloud. It automates the process of securing, rotating, and retrieving secrets like database credentials or API keys so organizations reduce the risk of unauthorized access and maintain compliance with industry standards.
Users can interact with the service using the AWS Command Line Interface (CLI). It provides a simple and efficient way to manage secrets, create and update secret values, and configure rotation policies. With AWS CLI, Secrets Manager can be integrated into existing workflows to automate the management of secrets.
This article explores the top six commands for Secrets Manager in CLI. We also share additional tips on optimizing usage for enhanced protection and efficiency.
The rest of the article discusses the most commonly used AWS CLI secrets manager commands in detail.
We will install and configure the AWS CLI before running the commands.
After creating an IAM user configure the CLI by running aws configure command as follows.
The command examples in this article use JSON for their output format. After completing these steps, your AWS CLI should be installed and configured, ready to manage your AWS services.
You can use the create-secret command to store sensitive information, such as database credentials, API keys, or other secrets that your applications and services need to access. Here are some useful `create-secret` command options:
For example, let's say you want to store the credentials for a database named mydb with a username dbuser and a password dbpassword. The following command creates a new secret named mydb-credentials with the given username and password.
The get-secret-value command is used to retrieve the value of a secret stored in AWS Secrets Manager. This command is particularly helpful when you need to access the secret value for your application or service. These are the important options for this command.
For example, let's say you want to retrieve the credentials for the mydb database stored previously in AWS Secrets Manager. The following command retrieves the secret value and information.
The update-secret command modifies an existing secret stored in AWS Secrets Manager. This command is particularly helpful when you need to update the value of a secret, such as changing a password or API key.
Here's a detailed explanation of the various options for the update-secret command and how to use them:
For example, let's say you need to update the password for the mydb database. The AWS CLI Secret Manager script for updates is as below.
The rotate-secret command rotates a secret stored in AWS Secrets Manager. It can create rotation schedules and integrate with other AWS services like Aurora and RDS. It uses Lambda functions to automatically update the integrated applications and databases with the new secret value.
Here's a detailed explanation of the various options for the rotate-secret command and how to use them:
For example, let's say you want to rotate the credentials for the mydb database every 30 days. You can rotate the secret with the following command:
You can use the put-resource-policy to put a resource policy on a secret stored in the AWS Secrets Manager. The resource policy is an additional layer of access control. A policy can give or deny other IAM roles and users permission to manage the secret. Note that attaching a policy to a secret is optional.
Here's a detailed explanation of the various options for the rotate-secret command and how to use them:
For example, if you want to allow your DB admin to access the database credentials secret, you can apply the policy using the following command.
The policy file declares a policy to allow DB admin roles to have access to the secret.
You can use the list-secret-version-ids command to list all version IDs for a secret stored in AWS Secrets Manager. It is useful when you want to see the history of changes made to a secret over time or when you need to retrieve an older version of a secret.
Here's a detailed explanation of the various options for the list-secret-version-ids command and how to use them:
For example, let's say you want to view the different versions of the mydb-credentials secret stored in AWS Secrets Manager. You can list the version IDs with the following command:
When you execute this command, you will receive a response that includes the version IDs, their metadata, and a NextToken value if there are more results to retrieve. You can use the NextToken value to retrieve the next page of results.
We share some additional tips below on how to best use the AWS CLI for Secrets Manager.
The `rotate-secret` command should be preferred over the `update-secret` command for most production use cases. It automatically rotates the secrets while ensuring proper versioning is maintained. Moreover, it has in-built integration with AWS services like RDS and Aurora and also supports custom integrations via Lambda functions. The integrations allow updating consuming applications or databases with the new secret. This is the preferred method for maintaining secure access to resources.
AWS Secrets Manager is designed to ensure the security and availability of your sensitive information. When you update, rotate, or even delete a secret, it is not permanently removed from the system; instead, it undergoes a "soft delete" process. The secret is marked as deleted but remains recoverable for a certain configurable period between 7 and 30 days, allowing you to restore it using the `restore-secret` command. This feature protects against accidental deletion or modification of your secrets, ensuring that your critical data remains accessible for a few days, even if an unintended change occurs.
The AWS CLI only supports commands for AWS services. Moreover, the AWS Secrets Manager service has native integrations only for other AWS services. Users need to implement Lambda functions to integrate with other applications and services, making secret management a challenging task, particularly when dealing with applications and services running in non-AWS environments.
Doppler addresses the challenge of organizing secrets by providing a centralized, secure, and user-friendly platform for managing sensitive information across various environments and applications. It offers a unified dashboard that enables developers to access and manage secrets for different platforms and languages easily.
Doppler's environment-based approach allows developers to segregate secrets according to their respective environments, such as local development, staging, and production. It simplifies secret organization and ensures that the right secrets are used in the right context.
The AWS Secrets Manager is a powerful service that allows you to securely store and manage secrets such as database credentials, API keys, and other sensitive information. It provides an easy-to-use interface for managing secrets and integrates with other AWS services. The AWS CLI for Secrets Manager makes it possible to create, retrieve, update, rotate, and manage the different versions of your secrets right from the terminal. However, the CLI has limitations and is restricted to the AWS environment. You can use Doppler to manage secrets across multiple environments, including AWS cloud.
Trusted by the world’s best DevOps and security teams. Doppler is the secrets manager developers love.