Uploading AWS Secret Values using updateSecret.sh Script

Uploading AWS Secret Values using updateSecret.sh Script

Introduction:-

In this tutorial, we will explore how to securely store secret values using #AWS Secrets Manager and the AWS Command Line Interface (CLI). We will walk through an example where we store secret credentials for a MySQL database in #AWS Secrets Manager using a JSON file. This method allows for easy management and retrieval of sensitive information, enhancing the security and flexibility of your application. Let’s get started!

Prerequisites:

  • AWS account credentials with appropriate permissions to use #AWS Secrets Manager and the AWS CLI.

  • AWS CLI installed and configured on your local machine. Refer to the AWS CLI documentation for installation instructions.

  1. .create a secrets.json folder in the system directory. Prepare the credentials JSON file Create a file named core_db.json in the secrets.json folder and populate it with the necessary credentials. For this example, let's assume we have the following credentials.As shown in below example or picture.
{
    "master_password":"jbjvhgvj",
    "master_username":"postgres",
    "read_only_password":"jbjjbjbh",
    "read_only_username":"read_only"
}

3. create a updatesecret.sh file in the same secrets.json directory to execute the command and upload the secret values to aws secret.

4. Store your secret values in the .json file and pass the secret id and secret value(string) file path in the updatesecret.sh file. Refer below example for more understanding.

 aws secretsmanager put-secret-value \
     --secret-id  <your-secret-id> \
     --secret-string file://core_db.json

5.open a terminal window in your local machine and navigate to the secrets.json directory and configure or export your aws credentials. Next Run the below command to update the secret value in aws secret.

sh updatesecret.sh

6. Verify the updated secret To verify the successful update, you can use the below AWS CLI command to retrieve the secret value or u can login to the aws console’s secret manager service and retrieve the secret value.

aws secretsmanager get-secret-value --secret-id <your-secret-id>

Replace <your-secret-id> with the ARN or name of your secret. The command will return the updated secret value if the update was successful.

Conclusion:

In this tutorial, we learned how to securely upload AWS secret values using the updateSecret.sh command script. #AWS Secrets Manager provides a convenient way to manage and update sensitive information, while the updateSecret.sh script simplifies the process of programmatically updating secrets. By following these steps, you can effectively manage your secrets in #AWS Secrets Manager and ensure the security of your sensitive data.