aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.03k stars 568 forks source link

Better examples #6297

Closed tsrdatatech closed 4 weeks ago

tsrdatatech commented 1 month ago

Describe the issue

The example here is very basic and simple, when someone tries to do something more like updating an actual value then their whole secret is wiped out if they do not know what they are doing. You should add some real world examples like updating an actual value rather than just the description or something. And outline the steps it takes to do that. For example:

async function updateToken(token) {
  // Retrieve the current secret value
  const currentSecretValue = await getSecret(YOUR_SECRET_NAME);
  const secretObject = JSON.parse(currentSecretValue);

  // Update the desired key-value pair
  secretObject.some_value = some_new_value;

  // Update the secret with the modified value
  const command = new UpdateSecretCommand({
    SecretId: YOUR_SECRET_NAME,
    SecretString: JSON.stringify(secretObject),
  });
  const response = await client.send(command);
  return response;
}

Links

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/secrets-manager/command/UpdateSecretCommand/

aBurmeseDev commented 1 month ago

Hi @tsrdatatech - thanks for reaching out and sharing feedback on our docs.

Regarding the code example you provided. It appears that you're invoking the UpdateSecret API within the updateToken function. However, it's important to note that retrieving the current secret value is unnecessary when updating it. Instead, you can simplify your code by following this example:

import {
  SecretsManagerClient,
  UpdateSecretCommand,
} from "@aws-sdk/client-secrets-manager";
const client = new SecretsManagerClient();
const input = {
  // UpdateSecretRequest
  SecretId: "secretID", // required
  SecretString: ""fasdfaseasef"",
};
const command = new UpdateSecretCommand(input);
const response = await client.send(command);

SecretString would take in string and is recommended to be in JSON structure "{ \"a\": \"b\" }"

Reference from service API docs:

The text data to encrypt and store in the new version of the secret. We recommend you use a JSON structure of key/value pairs for your secret value.

when someone tries to do something more like updating an actual value then their whole secret is wiped out

Moving on to your comment, I'd appreciate if you could provide more context or clarification. Can you please elaborate further on the specific aspect you need additional information about? This will help me understand your query better and provide a more accurate response.

Best, John

github-actions[bot] commented 1 month ago

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] commented 2 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.