Create an AWS Secrets Manager secret
A secret can be a password, a set of credentials such as a user name and password, an OAuth token, or other secret information that you store in an encrypted form in Secrets Manager.
Tip
For Amazon RDS and Amazon Redshift admin user credentials, we recommend you use managed secrets. You create the managed secret through the managing servce, and then you can use managed rotation.
When you use the console to store database credentials for a source database that is replicated to other Regions, the secret contains connection information for the source database. If you then replicate the secret, the replicas are copies of the source secret and contain the same connection information. You can add additional key/value pairs to the secret for regional connection information.
To create a secret, you need the permissions granted by the SecretsManagerReadWrite managed policy.
Secrets Manager generates a CloudTrail log entry when you create a secret. For more information, see Log AWS Secrets Manager events with AWS CloudTrail.
To create a secret (console)
Open the Secrets Manager console at https://console.aws.amazon.com/secretsmanager/
. -
Choose Store a new secret.
-
On the Choose secret type page, do the following:
-
For Secret type, do one of the following:
-
To store database credentials, choose the type of database credentials to store. Then choose the Database and then enter the Credentials.
-
To store API keys, access tokens, credentials that aren't for databases, choose Other type of secret.
In Key/value pairs, either enter your secret in JSON Key/value pairs, or choose the Plaintext tab and enter the secret in any format. You can store up to 65536 bytes in the secret. Some examples:
-
-
For Encryption key, choose the AWS KMS key that Secrets Manager uses to encrypt the secret value. For more information, see Secret encryption and decryption.
-
For most cases, choose aws/secretsmanager to use the AWS managed key for Secrets Manager. There is no cost for using this key.
-
If you need to access the secret from another AWS account, or if you want to use your own KMS key so that you can rotate it or apply a key policy to it, choose a customer managed key from the list or choose Add new key to create one. For information about the costs of using a customer managed key, see Pricing.
You must have Permissions for the KMS key. For information about cross-account access, see Access AWS Secrets Manager secrets from a different account.
-
-
Choose Next.
-
-
On the Configure secret page, do the following:
-
Enter a descriptive Secret name and Description. Secret names can contain 1-512 alphanumeric and /_+=.@- characters.
-
(Optional) In the Tags section, add tags to your secret. For tagging strategies, see Tag AWS Secrets Manager secrets. Don't store sensitive information in tags because they aren't encrypted.
-
(Optional) In Resource permissions, to add a resource policy to your secret, choose Edit permissions. For more information, see Resource-based policies.
-
(Optional) In Replicate secret, to replicate your secret to another AWS Region, choose Replicate secret. You can replicate your secret now or come back and replicate it later. For more information, see Replicate secrets across Regions.
-
Choose Next.
-
-
(Optional) On the Configure rotation page, you can turn on automatic rotation. You can also keep rotation off for now and then turn it on later. For more information, see Rotate secrets. Choose Next.
-
On the Review page, review your secret details, and then choose Store.
Secrets Manager returns to the list of secrets. If your new secret doesn't appear, choose the refresh button.
AWS CLI
When you enter commands in a command shell, there is a risk of the command history being accessed or utilities having access to your command parameters. See Mitigate the risks of using the AWS CLI to store your AWS Secrets Manager secrets.
Example Create a secret from database credentials in a JSON file
The following create-secret
example creates a secret from credentials in a file. For more information, see Loading AWS CLI parameters from a file in the AWS CLI User Guide.
For Secrets Manager to be able to rotate the secret, you must make sure the JSON matches the JSON structure of a secret.
aws secretsmanager create-secret \ --name MyTestSecret \ --secret-string file://mycreds.json
Contents of mycreds.json:
{ "engine": "mysql", "username": "saanvis", "password": "EXAMPLE-PASSWORD", "host": "my-database-endpoint.us-west-2.rds.amazonaws.com", "dbname": "myDatabase", "port": "3306" }
Example Create a secret
The following create-secret
example creates a secret with two key-value pairs.
aws secretsmanager create-secret \ --name MyTestSecret \ --description "My test secret created with the CLI." \ --secret-string "{\"user\":\"diegor\",\"password\":\"EXAMPLE-PASSWORD\"}"
AWS SDK
To create a secret by using one of the AWS SDKs, use the CreateSecret
action. For more
information, see AWS SDKs.