Storing database credentials in Amazon Secrets Manager
When you call the Data API, you can pass credentials for the cluster or serverless workgroup by using a secret in Amazon Secrets Manager. To pass credentials in this way, you specify the name of the secret or the Amazon Resource Name (ARN) of the secret.
To store credentials with Secrets Manager, you need SecretManagerReadWrite
managed policy permission. For more information about the minimum permissions, see
Creating and Managing Secrets
with Amazon Secrets Manager in the Amazon Secrets Manager User Guide.
To store your credentials in a secret for an Amazon Redshift cluster
-
Use the Amazon Secrets Manager console to create a secret that contains credentials for your cluster:
-
When you choose Store a new secret, choose Credentials for Redshift cluster.
-
Store your values for User name (database user), Password, and DB cluster (cluster identifier) in your secret.
-
Tag the secret with the key
RedshiftDataFullAccess
. The Amazon managed policyAmazonRedshiftDataFullAccess
only allows the actionsecretsmanager:GetSecretValue
for secrets tagged with the keyRedshiftDataFullAccess
.
For instructions, see Creating a Basic Secret in the Amazon Secrets Manager User Guide.
-
-
Use the Amazon Secrets Manager console to view the details for the secret you created, or run the
aws secretsmanager describe-secret
Amazon CLI command.Note the name and ARN of the secret. You can use these in calls to the Data API.
To store your credentials in a secret for a serverless workgroup
-
Use Amazon Secrets Manager Amazon CLI commands to store a secret that contains credentials for your serverless workgroup:
-
Create your secret in a file, for example a JSON file named
mycreds.json
. Provide the values for User name (database user) and Password in the file.{ "username": "myusername", "password": "mypassword" }
-
Store your values in your secret and tag the secret with the key
RedshiftDataFullAccess
.aws secretsmanager create-secret --name MyRedshiftSecret --tags Key="RedshiftDataFullAccess",Value="serverless" --secret-string file://mycreds.json
The following shows the output.
{ "ARN": "arn:aws:secretsmanager:
region
:accountId
:secret:MyRedshiftSecret-mvLHxf
", "Name": "MyRedshiftSecret", "VersionId": "a1603925-e8ea-4739-9ae9-e509eEXAMPLE" }
For more information, see Creating a Basic Secret with Amazon CLI in the Amazon Secrets Manager User Guide.
-
-
Use the Amazon Secrets Manager console to view the details for the secret you created, or run the
aws secretsmanager describe-secret
Amazon CLI command.Note the name and ARN of the secret. You can use these in calls to the Data API.