From 414fcacf70695615297ca1b8bd646e6c7dac1b5a Mon Sep 17 00:00:00 2001 From: Megha S Date: Tue, 11 Jun 2024 00:12:32 +0530 Subject: [PATCH] Updated Amplify doc to add sdk v3 code (#7674) * added sdk v3 code * updated the sdk v3 code as per the suggestions --------- Co-authored-by: meghasv09 --- .../functions/secrets/index.mdx | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/pages/gen1/[platform]/build-a-backend/functions/secrets/index.mdx b/src/pages/gen1/[platform]/build-a-backend/functions/secrets/index.mdx index 0091316927d..0e9be9015bd 100644 --- a/src/pages/gen1/[platform]/build-a-backend/functions/secrets/index.mdx +++ b/src/pages/gen1/[platform]/build-a-backend/functions/secrets/index.mdx @@ -77,6 +77,10 @@ To access the secret values in your Lambda function, use the [AWS SSM GetParamet If your Lambda function is using the Node.js runtime, a comment block will be placed at the top of your `index.js` file with example code to retrieve the secret values. + + + + ```js const aws = require('aws-sdk'); @@ -89,6 +93,35 @@ const { Parameters } = await (new aws.SSM()) // Parameters will be of the form { Name: 'secretName', Value: 'secretValue', ... }[] ``` + + + + +```js +const { SSMClient, GetParametersCommand } = require("@aws-sdk/client-ssm"); + +const client = new SSMClient(); + +const command = new GetParametersCommand({ + Names: ["EXAMPLE_SECRET_1", "EXAMPLE_SECRET_2"].map( + (secretName) => process.env[secretName] + ), + WithDecryption: true, +}); + +client + .send(command) + .then((response) => { + const { Parameters } = response; + console.log(Parameters); + }) + .catch((error) => { + console.error(error); + }); +``` + + + ## Multi-environment flows When creating a new Amplify environment using `amplify env add`, Amplify CLI asks if you want to apply all secret values to the new environment or modify them. If you choose to apply the existing values, you can still make edits anytime using `amplify update function`.