Skip to content

Commit 414fcac

Browse files
meghasomaraddermeghasv09
andauthored
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 <meghasomaradder2@gmail.com>
1 parent 3748cac commit 414fcac

File tree

1 file changed

+33
-0
lines changed
  • src/pages/gen1/[platform]/build-a-backend/functions/secrets

1 file changed

+33
-0
lines changed

src/pages/gen1/[platform]/build-a-backend/functions/secrets/index.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ To access the secret values in your Lambda function, use the [AWS SSM GetParamet
7777

7878
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.
7979

80+
<BlockSwitcher>
81+
82+
<Block name='AWS SDK V2'>
83+
8084
```js
8185
const aws = require('aws-sdk');
8286

@@ -89,6 +93,35 @@ const { Parameters } = await (new aws.SSM())
8993

9094
// Parameters will be of the form { Name: 'secretName', Value: 'secretValue', ... }[]
9195
```
96+
</Block>
97+
98+
<Block name='AWS SDK V3'>
99+
100+
```js
101+
const { SSMClient, GetParametersCommand } = require("@aws-sdk/client-ssm");
102+
103+
const client = new SSMClient();
104+
105+
const command = new GetParametersCommand({
106+
Names: ["EXAMPLE_SECRET_1", "EXAMPLE_SECRET_2"].map(
107+
(secretName) => process.env[secretName]
108+
),
109+
WithDecryption: true,
110+
});
111+
112+
client
113+
.send(command)
114+
.then((response) => {
115+
const { Parameters } = response;
116+
console.log(Parameters);
117+
})
118+
.catch((error) => {
119+
console.error(error);
120+
});
121+
```
122+
</Block>
123+
124+
</BlockSwitcher>
92125

93126
## Multi-environment flows
94127
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`.

0 commit comments

Comments
 (0)