2021/03/03 - AWS Secrets Manager - 3 new3 updated api methods
Changes Update secretsmanager client to latest version
Removes the secret from replication and promotes the secret to a regional secret in the replica Region.
See also: AWS API Documentation
Request Syntax
client.stop_replication_to_replica( SecretId='string' )
string
[REQUIRED]
Response to StopReplicationToReplica of a secret, based on the SecretId.
dict
Response Syntax
{ 'ARN': 'string' }
Response Structure
(dict) --
ARN (string) --
Response StopReplicationToReplica of a secret, based on the ARN,.
Converts an existing secret to a multi-Region secret and begins replication the secret to a list of new regions.
See also: AWS API Documentation
Request Syntax
client.replicate_secret_to_regions( SecretId='string', AddReplicaRegions=[ { 'Region': 'string', 'KmsKeyId': 'string' }, ], ForceOverwriteReplicaSecret=True|False )
string
[REQUIRED]
Use the Secret Id to replicate a secret to regions.
list
[REQUIRED]
Add Regions to replicate the secret.
(dict) --
(Optional) Custom type consisting of a Region (required) and the KmsKeyId which can be an ARN, Key ID, or Alias.
Region (string) --
Describes a single instance of Region objects.
KmsKeyId (string) --
Can be an ARN, Key ID, or Alias.
boolean
(Optional) If set, Secrets Manager replication overwrites a secret with the same name in the destination region.
dict
Response Syntax
{ 'ARN': 'string', 'ReplicationStatus': [ { 'Region': 'string', 'KmsKeyId': 'string', 'Status': 'InSync'|'Failed'|'InProgress', 'StatusMessage': 'string', 'LastAccessedDate': datetime(2015, 1, 1) }, ] }
Response Structure
(dict) --
ARN (string) --
Replicate a secret based on the ReplicaRegionType> consisting of a Region(required) and a KMSKeyId (optional) which can be the ARN, KeyID, or Alias.
ReplicationStatus (list) --
Describes the secret replication status as PENDING, SUCCESS or FAIL.
(dict) --
A replication object consisting of a RegionReplicationStatus object and includes a Region, KMSKeyId, status, and status message.
Region (string) --
The Region where replication occurs.
KmsKeyId (string) --
Can be an ARN, Key ID, or Alias.
Status (string) --
The status can be InProgress, Failed, or InSync.
StatusMessage (string) --
Status message such as "Secret with this name already exists in this region".
LastAccessedDate (datetime) --
The date that you last accessed the secret in the Region.
Remove regions from replication.
See also: AWS API Documentation
Request Syntax
client.remove_regions_from_replication( SecretId='string', RemoveReplicaRegions=[ 'string', ] )
string
[REQUIRED]
Remove a secret by SecretId from replica Regions.
list
[REQUIRED]
Remove replication from specific Regions.
(string) --
dict
Response Syntax
{ 'ARN': 'string', 'ReplicationStatus': [ { 'Region': 'string', 'KmsKeyId': 'string', 'Status': 'InSync'|'Failed'|'InProgress', 'StatusMessage': 'string', 'LastAccessedDate': datetime(2015, 1, 1) }, ] }
Response Structure
(dict) --
ARN (string) --
The secret ARN removed from replication regions.
ReplicationStatus (list) --
Describes the remaining replication status after you remove regions from the replication list.
(dict) --
A replication object consisting of a RegionReplicationStatus object and includes a Region, KMSKeyId, status, and status message.
Region (string) --
The Region where replication occurs.
KmsKeyId (string) --
Can be an ARN, Key ID, or Alias.
Status (string) --
The status can be InProgress, Failed, or InSync.
StatusMessage (string) --
Status message such as "Secret with this name already exists in this region".
LastAccessedDate (datetime) --
The date that you last accessed the secret in the Region.
{'AddReplicaRegions': [{'KmsKeyId': 'string', 'Region': 'string'}], 'ForceOverwriteReplicaSecret': 'boolean'}Response
{'ReplicationStatus': [{'KmsKeyId': 'string', 'LastAccessedDate': 'timestamp', 'Region': 'string', 'Status': 'InSync | Failed | InProgress', 'StatusMessage': 'string'}]}
Creates a new secret. A secret in Secrets Manager consists of both the protected secret data and the important information needed to manage the secret.
Secrets Manager stores the encrypted secret data in one of a collection of "versions" associated with the secret. Each version contains a copy of the encrypted secret data. Each version is associated with one or more "staging labels" that identify where the version is in the rotation cycle. The SecretVersionsToStages field of the secret contains the mapping of staging labels to the active versions of the secret. Versions without a staging label are considered deprecated and not included in the list.
You provide the secret data to be encrypted by putting text in either the SecretString parameter or binary data in the SecretBinary parameter, but not both. If you include SecretString or SecretBinary then Secrets Manager also creates an initial secret version and automatically attaches the staging label AWSCURRENT to the new version.
Minimum permissions
To run this command, you must have the following permissions:
secretsmanager:CreateSecret
kms:GenerateDataKey - needed only if you use a customer-managed AWS KMS key to encrypt the secret. You do not need this permission to use the account default AWS managed CMK for Secrets Manager.
kms:Decrypt - needed only if you use a customer-managed AWS KMS key to encrypt the secret. You do not need this permission to use the account default AWS managed CMK for Secrets Manager.
secretsmanager:TagResource - needed only if you include the Tags parameter.
Related operations
To delete a secret, use DeleteSecret.
To modify an existing secret, use UpdateSecret.
To create a new version of a secret, use PutSecretValue.
To retrieve the encrypted secure string and secure binary values, use GetSecretValue.
To retrieve all other details for a secret, use DescribeSecret. This does not include the encrypted secure string and secure binary values.
To retrieve the list of secret versions associated with the current secret, use DescribeSecret and examine the SecretVersionsToStages response value.
See also: AWS API Documentation
Request Syntax
client.create_secret( Name='string', ClientRequestToken='string', Description='string', KmsKeyId='string', SecretBinary=b'bytes', SecretString='string', Tags=[ { 'Key': 'string', 'Value': 'string' }, ], AddReplicaRegions=[ { 'Region': 'string', 'KmsKeyId': 'string' }, ], ForceOverwriteReplicaSecret=True|False )
string
[REQUIRED]
Specifies the friendly name of the new secret.
The secret name must be ASCII letters, digits, or the following characters : /_+=.@-
string
(Optional) If you include SecretString or SecretBinary, then an initial version is created as part of the secret, and this parameter specifies a unique identifier for the new version.
This value helps ensure idempotency. Secrets Manager uses this value to prevent the accidental creation of duplicate versions if there are failures and retries during a rotation. We recommend that you generate a UUID-type value to ensure uniqueness of your versions within the specified secret.
If the ClientRequestToken value isn't already associated with a version of the secret then a new version of the secret is created.
If a version with this value already exists and the version SecretString and SecretBinary values are the same as those in the request, then the request is ignored.
If a version with this value already exists and that version's SecretString and SecretBinary values are different from those in the request, then the request fails because you cannot modify an existing version. Instead, use PutSecretValue to create a new version.
This value becomes the VersionId of the new version.
This field is autopopulated if not provided.
string
(Optional) Specifies a user-provided description of the secret.
string
(Optional) Specifies the ARN, Key ID, or alias of the AWS KMS customer master key (CMK) to be used to encrypt the SecretString or SecretBinary values in the versions stored in this secret.
You can specify any of the supported ways to identify a AWS KMS key ID. If you need to reference a CMK in a different account, you can use only the key ARN or the alias ARN.
If you don't specify this value, then Secrets Manager defaults to using the AWS account's default CMK (the one named aws/secretsmanager). If a AWS KMS CMK with that name doesn't yet exist, then Secrets Manager creates it for you automatically the first time it needs to encrypt a version's SecretString or SecretBinary fields.
bytes
(Optional) Specifies binary data that you want to encrypt and store in the new version of the secret. To use this parameter in the command-line tools, we recommend that you store your binary data in a file and then use the appropriate technique for your tool to pass the contents of the file as a parameter.
Either SecretString or SecretBinary must have a value, but not both. They cannot both be empty.
This parameter is not available using the Secrets Manager console. It can be accessed only by using the AWS CLI or one of the AWS SDKs.
string
(Optional) Specifies text data that you want to encrypt and store in this new version of the secret.
Either SecretString or SecretBinary must have a value, but not both. They cannot both be empty.
If you create a secret by using the Secrets Manager console then Secrets Manager puts the protected secret text in only the SecretString parameter. The Secrets Manager console stores the information as a JSON structure of key/value pairs that the Lambda rotation function knows how to parse.
For storing multiple values, we recommend that you use a JSON text string argument and specify key/value pairs. For information on how to format a JSON parameter for the various command line tool environments, see Using JSON for Parameters in the AWS CLI User Guide. For example:
{"username":"bob","password":"abc123xyz456"}
If your command-line tool or SDK requires quotation marks around the parameter, you should use single quotes to avoid confusion with the double quotes required in the JSON text.
list
(Optional) Specifies a list of user-defined tags that are attached to the secret. Each tag is a "Key" and "Value" pair of strings. This operation only appends tags to the existing list of tags. To remove tags, you must use UntagResource.
This parameter requires a JSON text string argument. For information on how to format a JSON parameter for the various command line tool environments, see Using JSON for Parameters in the AWS CLI User Guide. For example:
[{"Key":"CostCenter","Value":"12345"},{"Key":"environment","Value":"production"}]
If your command-line tool or SDK requires quotation marks around the parameter, you should use single quotes to avoid confusion with the double quotes required in the JSON text.
The following basic restrictions apply to tags:
Maximum number of tags per secret—50
Maximum key length—127 Unicode characters in UTF-8
Maximum value length—255 Unicode characters in UTF-8
Tag keys and values are case sensitive.
Do not use the aws: prefix in your tag names or values because AWS reserves it for AWS use. You can't edit or delete tag names or values with this prefix. Tags with this prefix do not count against your tags per secret limit.
If you use your tagging schema across multiple services and resources, remember other services might have restrictions on allowed characters. Generally allowed characters: letters, spaces, and numbers representable in UTF-8, plus the following special characters: + - = . _ : / @.
(dict) --
A structure that contains information about a tag.
Key (string) --
The key identifier, or name, of the tag.
Value (string) --
The string value associated with the key of the tag.
list
(Optional) Add a list of regions to replicate secrets. Secrets Manager replicates the KMSKeyID objects to the list of regions specified in the parameter.
(dict) --
(Optional) Custom type consisting of a Region (required) and the KmsKeyId which can be an ARN, Key ID, or Alias.
Region (string) --
Describes a single instance of Region objects.
KmsKeyId (string) --
Can be an ARN, Key ID, or Alias.
boolean
(Optional) If set, the replication overwrites a secret with the same name in the destination region.
dict
Response Syntax
{ 'ARN': 'string', 'Name': 'string', 'VersionId': 'string', 'ReplicationStatus': [ { 'Region': 'string', 'KmsKeyId': 'string', 'Status': 'InSync'|'Failed'|'InProgress', 'StatusMessage': 'string', 'LastAccessedDate': datetime(2015, 1, 1) }, ] }
Response Structure
(dict) --
ARN (string) --
The Amazon Resource Name (ARN) of the secret that you just created.
Name (string) --
The friendly name of the secret that you just created.
VersionId (string) --
The unique identifier associated with the version of the secret you just created.
ReplicationStatus (list) --
Describes a list of replication status objects as InProgress, Failed or InSync.
(dict) --
A replication object consisting of a RegionReplicationStatus object and includes a Region, KMSKeyId, status, and status message.
Region (string) --
The Region where replication occurs.
KmsKeyId (string) --
Can be an ARN, Key ID, or Alias.
Status (string) --
The status can be InProgress, Failed, or InSync.
StatusMessage (string) --
Status message such as "Secret with this name already exists in this region".
LastAccessedDate (datetime) --
The date that you last accessed the secret in the Region.
{'PrimaryRegion': 'string', 'ReplicationStatus': [{'KmsKeyId': 'string', 'LastAccessedDate': 'timestamp', 'Region': 'string', 'Status': 'InSync | Failed | InProgress', 'StatusMessage': 'string'}]}
Retrieves the details of a secret. It does not include the encrypted fields. Secrets Manager only returns fields populated with a value in the response.
Minimum permissions
To run this command, you must have the following permissions:
secretsmanager:DescribeSecret
Related operations
To create a secret, use CreateSecret.
To modify a secret, use UpdateSecret.
To retrieve the encrypted secret information in a version of the secret, use GetSecretValue.
To list all of the secrets in the AWS account, use ListSecrets.
See also: AWS API Documentation
Request Syntax
client.describe_secret( SecretId='string' )
string
[REQUIRED]
The identifier of the secret whose details you want to retrieve. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.
dict
Response Syntax
{ 'ARN': 'string', 'Name': 'string', 'Description': 'string', 'KmsKeyId': 'string', 'RotationEnabled': True|False, 'RotationLambdaARN': 'string', 'RotationRules': { 'AutomaticallyAfterDays': 123 }, 'LastRotatedDate': datetime(2015, 1, 1), 'LastChangedDate': datetime(2015, 1, 1), 'LastAccessedDate': datetime(2015, 1, 1), 'DeletedDate': datetime(2015, 1, 1), 'Tags': [ { 'Key': 'string', 'Value': 'string' }, ], 'VersionIdsToStages': { 'string': [ 'string', ] }, 'OwningService': 'string', 'CreatedDate': datetime(2015, 1, 1), 'PrimaryRegion': 'string', 'ReplicationStatus': [ { 'Region': 'string', 'KmsKeyId': 'string', 'Status': 'InSync'|'Failed'|'InProgress', 'StatusMessage': 'string', 'LastAccessedDate': datetime(2015, 1, 1) }, ] }
Response Structure
(dict) --
ARN (string) --
The ARN of the secret.
Name (string) --
The user-provided friendly name of the secret.
Description (string) --
The user-provided description of the secret.
KmsKeyId (string) --
The ARN or alias of the AWS KMS customer master key (CMK) that's used to encrypt the SecretString or SecretBinary fields in each version of the secret. If you don't provide a key, then Secrets Manager defaults to encrypting the secret fields with the default AWS KMS CMK (the one named awssecretsmanager) for this account.
RotationEnabled (boolean) --
Specifies whether automatic rotation is enabled for this secret.
To enable rotation, use RotateSecret with AutomaticallyRotateAfterDays set to a value greater than 0. To disable rotation, use CancelRotateSecret.
RotationLambdaARN (string) --
The ARN of a Lambda function that's invoked by Secrets Manager to rotate the secret either automatically per the schedule or manually by a call to RotateSecret.
RotationRules (dict) --
A structure with the rotation configuration for this secret.
AutomaticallyAfterDays (integer) --
Specifies the number of days between automatic scheduled rotations of the secret.
Secrets Manager schedules the next rotation when the previous one is complete. Secrets Manager schedules the date by adding the rotation interval (number of days) to the actual date of the last rotation. The service chooses the hour within that 24-hour date window randomly. The minute is also chosen somewhat randomly, but weighted towards the top of the hour and influenced by a variety of factors that help distribute load.
LastRotatedDate (datetime) --
The last date and time that the rotation process for this secret was invoked.
The most recent date and time that the Secrets Manager rotation process successfully completed. If the secret doesn't rotate, Secrets Manager returns a null value.
LastChangedDate (datetime) --
The last date and time that this secret was modified in any way.
LastAccessedDate (datetime) --
The last date that this secret was accessed. This value is truncated to midnight of the date and therefore shows only the date, not the time.
DeletedDate (datetime) --
This value exists if the secret is scheduled for deletion. Some time after the specified date and time, Secrets Manager deletes the secret and all of its versions.
If a secret is scheduled for deletion, then its details, including the encrypted secret information, is not accessible. To cancel a scheduled deletion and restore access, use RestoreSecret.
Tags (list) --
The list of user-defined tags that are associated with the secret. To add tags to a secret, use TagResource. To remove tags, use UntagResource.
(dict) --
A structure that contains information about a tag.
Key (string) --
The key identifier, or name, of the tag.
Value (string) --
The string value associated with the key of the tag.
VersionIdsToStages (dict) --
A list of all of the currently assigned VersionStage staging labels and the VersionId that each is attached to. Staging labels are used to keep track of the different versions during the rotation process.
(string) --
(list) --
(string) --
OwningService (string) --
Returns the name of the service that created this secret.
CreatedDate (datetime) --
The date you created the secret.
PrimaryRegion (string) --
Specifies the primary region for secret replication.
ReplicationStatus (list) --
Describes a list of replication status objects as InProgress, Failed or InSync. P
(dict) --
A replication object consisting of a RegionReplicationStatus object and includes a Region, KMSKeyId, status, and status message.
Region (string) --
The Region where replication occurs.
KmsKeyId (string) --
Can be an ARN, Key ID, or Alias.
Status (string) --
The status can be InProgress, Failed, or InSync.
StatusMessage (string) --
Status message such as "Secret with this name already exists in this region".
LastAccessedDate (datetime) --
The date that you last accessed the secret in the Region.
{'Filters': {'Key': {'primary-region'}}}Response
{'SecretList': {'PrimaryRegion': 'string'}}
Lists all of the secrets that are stored by Secrets Manager in the AWS account. To list the versions currently stored for a specific secret, use ListSecretVersionIds. The encrypted fields SecretString and SecretBinary are not included in the output. To get that information, call the GetSecretValue operation.
Minimum permissions
To run this command, you must have the following permissions:
secretsmanager:ListSecrets
Related operations
To list the versions attached to a secret, use ListSecretVersionIds.
See also: AWS API Documentation
Request Syntax
client.list_secrets( MaxResults=123, NextToken='string', Filters=[ { 'Key': 'description'|'name'|'tag-key'|'tag-value'|'primary-region'|'all', 'Values': [ 'string', ] }, ], SortOrder='asc'|'desc' )
integer
(Optional) Limits the number of results you want to include in the response. If you don't include this parameter, it defaults to a value that's specific to the operation. If additional items exist beyond the maximum you specify, the NextToken response element is present and has a value (isn't null). Include that value as the NextToken request parameter in the next call to the operation to get the next part of the results. Note that Secrets Manager might return fewer results than the maximum even when there are more results available. You should check NextToken after every operation to ensure that you receive all of the results.
string
(Optional) Use this parameter in a request if you receive a NextToken response in a previous request indicating there's more output available. In a subsequent call, set it to the value of the previous call NextToken response to indicate where the output should continue from.
list
Lists the secret request filters.
(dict) --
Allows you to add filters when you use the search function in Secrets Manager.
Key (string) --
Filters your list of secrets by a specific key.
Values (list) --
Filters your list of secrets by a specific value.
You can prefix your search value with an exclamation mark ( !) in order to perform negation filters.
(string) --
string
Lists secrets in the requested order.
dict
Response Syntax
{ 'SecretList': [ { 'ARN': 'string', 'Name': 'string', 'Description': 'string', 'KmsKeyId': 'string', 'RotationEnabled': True|False, 'RotationLambdaARN': 'string', 'RotationRules': { 'AutomaticallyAfterDays': 123 }, 'LastRotatedDate': datetime(2015, 1, 1), 'LastChangedDate': datetime(2015, 1, 1), 'LastAccessedDate': datetime(2015, 1, 1), 'DeletedDate': datetime(2015, 1, 1), 'Tags': [ { 'Key': 'string', 'Value': 'string' }, ], 'SecretVersionsToStages': { 'string': [ 'string', ] }, 'OwningService': 'string', 'CreatedDate': datetime(2015, 1, 1), 'PrimaryRegion': 'string' }, ], 'NextToken': 'string' }
Response Structure
(dict) --
SecretList (list) --
A list of the secrets in the account.
(dict) --
A structure that contains the details about a secret. It does not include the encrypted SecretString and SecretBinary values. To get those values, use the GetSecretValue operation.
ARN (string) --
The Amazon Resource Name (ARN) of the secret.
For more information about ARNs in Secrets Manager, see Policy Resources in the AWS Secrets Manager User Guide.
Name (string) --
The friendly name of the secret. You can use forward slashes in the name to represent a path hierarchy. For example, /prod/databases/dbserver1 could represent the secret for a server named dbserver1 in the folder databases in the folder prod.
Description (string) --
The user-provided description of the secret.
KmsKeyId (string) --
The ARN or alias of the AWS KMS customer master key (CMK) used to encrypt the SecretString and SecretBinary fields in each version of the secret. If you don't provide a key, then Secrets Manager defaults to encrypting the secret fields with the default KMS CMK, the key named awssecretsmanager, for this account.
RotationEnabled (boolean) --
Indicates whether automatic, scheduled rotation is enabled for this secret.
RotationLambdaARN (string) --
The ARN of an AWS Lambda function invoked by Secrets Manager to rotate and expire the secret either automatically per the schedule or manually by a call to RotateSecret.
RotationRules (dict) --
A structure that defines the rotation configuration for the secret.
AutomaticallyAfterDays (integer) --
Specifies the number of days between automatic scheduled rotations of the secret.
Secrets Manager schedules the next rotation when the previous one is complete. Secrets Manager schedules the date by adding the rotation interval (number of days) to the actual date of the last rotation. The service chooses the hour within that 24-hour date window randomly. The minute is also chosen somewhat randomly, but weighted towards the top of the hour and influenced by a variety of factors that help distribute load.
LastRotatedDate (datetime) --
The most recent date and time that the Secrets Manager rotation process was successfully completed. This value is null if the secret hasn't ever rotated.
LastChangedDate (datetime) --
The last date and time that this secret was modified in any way.
LastAccessedDate (datetime) --
The last date that this secret was accessed. This value is truncated to midnight of the date and therefore shows only the date, not the time.
DeletedDate (datetime) --
The date and time the deletion of the secret occurred. Not present on active secrets. The secret can be recovered until the number of days in the recovery window has passed, as specified in the RecoveryWindowInDays parameter of the DeleteSecret operation.
Tags (list) --
The list of user-defined tags associated with the secret. To add tags to a secret, use TagResource. To remove tags, use UntagResource.
(dict) --
A structure that contains information about a tag.
Key (string) --
The key identifier, or name, of the tag.
Value (string) --
The string value associated with the key of the tag.
SecretVersionsToStages (dict) --
A list of all of the currently assigned SecretVersionStage staging labels and the SecretVersionId attached to each one. Staging labels are used to keep track of the different versions during the rotation process.
(string) --
(list) --
(string) --
OwningService (string) --
Returns the name of the service that created the secret.
CreatedDate (datetime) --
The date and time when a secret was created.
PrimaryRegion (string) --
The Region where Secrets Manager originated the secret.
NextToken (string) --
If present in the response, this value indicates that there's more output available than included in the current response. This can occur even when the response includes no values at all, such as when you ask for a filtered view of a very long list. Use this value in the NextToken request parameter in a subsequent call to the operation to continue processing and get the next part of the output. You should repeat this until the NextToken response element comes back empty (as null).