From 63bcf51eed1ed02f73fe0f9625df7e6b58d3950b Mon Sep 17 00:00:00 2001 From: meghasv09 Date: Wed, 29 May 2024 20:45:46 +0530 Subject: [PATCH 1/2] added sdk v3 code --- .../functions/secrets/index.mdx | 23 +++++++++++++++++++ 1 file changed, 23 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..4ae9fd70750 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,25 @@ const { Parameters } = await (new aws.SSM()) // Parameters will be of the form { Name: 'secretName', Value: 'secretValue', ... }[] ``` + + + + +```js +const {ssm} = require("@aws-sdk/client-ssm"); + +const { Parameters } = await (new ssm()) + .getParameters({ + Names: ["EXAMPLE_SECRET_1", "EXAMPLE_SECRET_2"].map(secretName => process.env[secretName]), + WithDecryption: true, + }) + .promise(); + +// Parameters will be of the form { Name: 'secretName', Value: 'secretValue', ... }[] +``` + + + ## 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`. From 7dba8a5bffd1db11ce26c2aeadebb842f244e679 Mon Sep 17 00:00:00 2001 From: meghasv09 Date: Mon, 10 Jun 2024 15:58:04 +0530 Subject: [PATCH 2/2] updated the sdk v3 code as per the suggestions --- .../functions/secrets/index.mdx | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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 4ae9fd70750..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 @@ -98,16 +98,26 @@ const { Parameters } = await (new aws.SSM()) ```js -const {ssm} = require("@aws-sdk/client-ssm"); - -const { Parameters } = await (new ssm()) - .getParameters({ - Names: ["EXAMPLE_SECRET_1", "EXAMPLE_SECRET_2"].map(secretName => process.env[secretName]), - WithDecryption: true, +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); }) - .promise(); - -// Parameters will be of the form { Name: 'secretName', Value: 'secretValue', ... }[] + .catch((error) => { + console.error(error); + }); ```