Skip to content

Commit 6e1dccb

Browse files
edwardfoylejosefaidt
authored andcommitted
update sandbox secret management (#7108)
* update sandbox secret management * Update src/pages/gen2/deploy-and-host/sandbox-environments/features/index.mdx * Update src/pages/gen2/deploy-and-host/sandbox-environments/features/index.mdx * Update src/pages/gen2/deploy-and-host/sandbox-environments/features/index.mdx * Update src/pages/gen2/deploy-and-host/sandbox-environments/features/index.mdx * Update src/pages/gen2/deploy-and-host/sandbox-environments/features/index.mdx --------- Co-authored-by: josef <josef.aidt@gmail.com>
1 parent 139eca8 commit 6e1dccb

File tree

2 files changed

+84
-137
lines changed

2 files changed

+84
-137
lines changed

src/pages/[platform]/deploy-and-host/sandbox-environments/features/index.mdx

Lines changed: 83 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,68 @@ Sandbox environments include additional features for managing secrets, deploying
3535
## Secure secrets in your sandbox
3636

3737
<Callout info>
38+
3839
Secrets set in a sandbox do not show up in the Amplify Console. You can view them in the AWS Systems Manager (SSM) Parameter Store console.
40+
3941
</Callout>
4042

41-
Amplify Gen 2 offers secure secret storage to manage sensitive data like API keys and database credentials. Secrets are similar to environment variables, but they are encrypted AWS Systems Manager Parameter Store key value pairs. Secrets are stored in AWS Parameter Store with the following naming convention: `/amplify/<package.json#name>/<sandbox-name>/<key-name>`.
43+
Amplify Gen 2 offers secure secret storage to manage sensitive data like API keys and database credentials. Secrets are similar to environment variables, but they are encrypted AWS Systems Manager Parameter Store key value pairs. Secrets are stored in AWS Parameter Store under the `/amplify` prefix.
4244

4345
### Set secrets
4446

45-
You can add secrets while running your cloud sandbox with the following command:
47+
You can add secrets to your sandbox environment using the following command:
4648

47-
```bash title="Terminal" showLineNumbers={false}
49+
```bash
4850
npx amplify sandbox secret set foo
4951
? Enter secret value: ###
5052
Done!
5153

52-
> npx amplify sandbox secret set bar
54+
npx amplify sandbox secret set bar
5355
? Enter secret value: ###
5456
Done!
5557
```
5658

57-
### Access secrets
59+
After these commands, your sandbox will have two secrets named `foo` and `bar`.
60+
61+
### List secrets
62+
63+
You can list all of the secret names available in your sandbox environment with the following command:
64+
65+
```bash
66+
npx amplify sandbox secret list
67+
- foo
68+
- bar
69+
```
70+
71+
### Retrieve a secret
72+
73+
<Callout warning>
74+
75+
**Note:** This will print a secret value in plain text to the terminal. Do not use this command anywhere that terminal logs may be stored (such as CI/CD jobs).
76+
77+
</Callout>
78+
79+
To show the value of a secret, run the following command.
80+
81+
```bash
82+
npx amplify sandbox secret get foo
83+
name: foo
84+
version: 1
85+
value: abc123
86+
lastUpdated: Mon Nov 13 2023 22:19:12 GMT-0800 (Pacific Standard Time)
87+
```
88+
89+
### Remove secrets
90+
91+
To remove a secret from from the sandbox, run the following command in your terminal:
92+
93+
```bash
94+
npx amplify sandbox secret remove foo
95+
```
96+
97+
### Reference secrets
5898

59-
Once you have set a secret, you can access the values in code by calling the `secret()` function. The following example shows how to set up social sign-in with authentication in your app. Depending on your environment, Amplify will automatically load the correct secret value with no extra configuration.
99+
Once you have set a secret, you can reference the secret in your backend definition using the `secret()` function. The following example shows how to set up social sign-in with authentication in your app. Depending on your environment, Amplify will automatically load the correct secret value.
60100

61101
```ts
62102
import { defineAuth, secret } from '@aws-amplify/backend';
@@ -76,184 +116,91 @@ export const auth = defineAuth({
76116
});
77117
```
78118

79-
### Retrieve secrets
119+
The `secret()` function does NOT retrieve the value of the secret. It places a reference to the secret value in the backend definition. The secret value is only resolved during deployment of your backend.
80120

81-
To get the value of a secret from the cloud, run the following command in your terminal:
82-
83-
```bash title="Terminal" showLineNumbers={false}
84-
npx amplify sandbox secret get foo
85-
name: foo
86-
version: 1
87-
value: 123
88-
lastUpdated: Mon Nov 13 2023 22:19:12 GMT-0800 (Pacific Standard Time)
89-
```
121+
The `secret()` function can only be used in specific places in your backend definition such as [configuring auth providers](/gen2/build-a-backend/auth/add-social-provider/#configure-social-sign-in-backend) and [granting function secret access](/gen2/build-a-backend/functions/#secret-access).
90122

91-
### Remove secrets
123+
<Callout info>
92124

93-
To remove a secret from the cloud, run the following command in your terminal:
125+
To deploy a backend that uses `secret()` references via Amplify hosting, the secret values must be [configured for the Amplify app or branch](/gen2/deploy-and-host/fullstack-branching/secrets-and-vars)
94126

95-
```bash title="Terminal" showLineNumbers={false}
96-
npx amplify sandbox secret remove foo
97-
```
127+
</Callout>
98128

99-
### Work with multiple AWS profiles
129+
## Work with multiple AWS profiles
100130

101-
Sometimes you might have multiple AWS profiles set up locally. To run `amplify sandbox secret` commands, use the `--profile` flag to deploy to a specific profile. For example, let's say you have two AWS profiles set up locally—`default` and `work`. To add secrets to the `work` profile, run the following command in your terminal:
131+
Sometimes you might have multiple AWS profiles set up locally. To run `amplify sandbox secret` commands, use the `--profile` flag to deploy to a specific profile. For example, let's say you have two AWS profiles set up locally—`default` and `work`. To add secrets to the sandbox in the `work` profile, run the following command in your terminal:
102132

103-
```bash title="Terminal" showLineNumbers={false}
133+
```bash
104134
npx amplify sandbox secret set foo --profile work
105135
```
106136

107-
## Multiple sandboxes per app
137+
## Work with multiple named sandboxes
108138

109139
<Callout info>
110-
Provisioning multiple sandboxes per app is possible but not recommended because managing multiple ephemeral environments for a single app introduces complexity. With multiple sandboxes, it can be difficult to keep track of what code version or configuration is deployed where. Sticking to a single ephemeral sandbox per app keeps your workflows simple and straightforward.
111-
</Callout>
112140

113-
You can create multiple cloud sandbox environments for each app if you want to keep persistent sandbox environments up and running to test against. First, run the following command in the terminal:
141+
Provisioning multiple sandboxes per app is possible but not recommended because managing multiple ephemeral environments for a single developer introduces complexity. With multiple sandboxes, it can be difficult to keep track of what code version or configuration is deployed where. Sticking to a single sandbox per developer keeps your workflows simpler.
114142

115-
```bash title="Terminal" showLineNumbers={false}
116-
npx amplify sandbox --name s1
117-
```
143+
</Callout>
118144

119-
Once the deployment completes, exit sandbox `s1` and run the following command in the terminal:
145+
You can create multiple sandboxes if you want to have different features or test environments available in different sandboxes. By default, your sandbox is named based on the local machine username. To override this name, use the `--identifier` option:
120146

121-
```bash title="Terminal" showLineNumbers={false}
122-
npx amplify sandbox --name s2
147+
```bash
148+
npx amplify sandbox --identifier feature1sandbox
123149
```
124150

125-
After successful deployment, sandboxes `s1` and `s2` will be ready. Pick sandbox `s1` or `s2` to activate. You can switch between them but only one can be running at a time.
126-
127-
## Generate client config
151+
This will start a sandbox named `feature1sandbox`.
128152

129-
The client config (e.g. `amplifyconfiguration.json` file for Web) contains the configuration strings for interacting with AWS resources specific to an environment. The Amplify client libraries need the client config file in order to use the library APIs to connect to backend resources. By default, the cloud sandbox generates the client configuration file at the root of the project (such as `@/amplifyconfiguration.json`). If you want to place the file at a different path you can use the following command template:
153+
Once the deployment completes, exit sandbox and run the following command in the terminal:
130154

131-
```bash title="Terminal" showLineNumbers={false}
132-
npx amplify sandbox --config-out-dir path/to/config --config-format ["mjs", "json", "json-mobile", "ts", "dart"]
155+
```bash
156+
npx amplify sandbox --identifier feature2sandbox
133157
```
134158

135-
### Sandbox Environment
159+
After successful deployment, you will have two sandboxes `feature1sandbox` and `feature2sandbox`. You can switch between them but only one can be running at a time.
136160

137-
For Web and React Native, generating the client in the root of the project would work, but all the other platforms have specific directories to target.
161+
### Secret management with named sandboxes
138162

139-
<InlineFilter filters={['angular','javascript','nextjs','react','react-native','swift','vue']}>
140-
```bash title="Terminal" showLineNumbers={false}
141-
npx amplify sandbox
142-
```
143-
</InlineFilter>
163+
When working with multiple sandboxes, secrets must be configured for each one. All of the `sandbox secret` commands accept the `--identifier` argument to manage secrets for named sandboxes. For example, to add a secret to `feature1sandbox`, use:
144164

145-
<InlineFilter filters={['flutter']}>
146-
```bash title="Terminal" showLineNumbers={false}
147-
npx amplify sandbox --config-format dart --config-out-dir lib
165+
```bash
166+
npx amplify sandbox --identifier feature1sandbox secret set baz
148167
```
149-
</InlineFilter>
150-
<InlineFilter filters={['android']}>
151-
<Callout warning>
152-
Be sure to add a "raw" folder under app/src/main/res directory if it doesn't
153-
exist.
154-
</Callout>
155168

156-
```bash title="Terminal" showLineNumbers={false}
157-
npx amplify sandbox --config-format json-mobile --config-out-dir app/src/main/res/raw
158-
```
159-
</InlineFilter>
169+
## Generate client config
160170

161-
<InlineFilter filters={['swift']}>
171+
The client config, or `amplifyconfiguration.json` file, contains the configuration strings for interacting with AWS resources specific to an environment. The Amplify client libraries need the client config in order to use the library APIs to connect to backend resources. By default, the cloud sandbox generates the client configuration file at the root of the project (such as `@/amplifyconfiguration.json`). If you want to place the file at a different path (such as for a monorepo or Android app), run the following command in the terminal:
162172

163-
```bash title="Terminal" showLineNumbers={false}
164-
npx amplify sandbox --config-format json-mobile
173+
```bash
174+
npx amplify sandbox --config-out-dir ./path/to/config --format ["mjs", "json", "json-mobile", "ts", "dart"]
165175
```
166176

167-
Once the sandbox environment is running, you would also generate the configuration files for your application. However, Xcode won't be able to recognize them. For recognizing the files, you need to drag and drop the generated files to your project.
177+
Alternatively, if you want to generate the config for a branch environment to test against, run the following command in the terminal.
168178

169-
<video autoPlay={true} muted={true} loop={true} width="100%" playsInline={true}>
170-
<source src="/images/gen2/getting-started/ios/ios-getting-started-2.mp4" />
171-
</video>
172-
</InlineFilter>
173-
174-
### Deployment Environment
175-
176-
Alternatively, if you want to generate the config for a branch environment to test against, you can run the following command below in the terminal:
177-
178-
<InlineFilter filters={['android','angular','flutter','javascript','nextjs','react','react-native','swift','vue']}>
179-
For Web and React Native, generating the config with the default format and output directory.
180-
181-
```bash title="Terminal" showLineNumbers={false}
182-
npx amplify generate config --app-id <app-id> --branch main
179+
```bash
180+
npx amplify generate config --app-id <AMPLIFY_APP_ID> --branch main --format ["mjs", "json", "json-mobile", "ts", "dart"] out-dir ./path/to/config
183181
```
184-
</InlineFilter>
185-
<InlineFilter filters={['flutter']}>
186-
```bash title="Terminal" showLineNumbers={false}
187-
npx amplify generate config --app-id <app-id> --branch main --format dart --out-dir lib
188-
```
189-
</InlineFilter>
190-
<InlineFilter filters={['android']}>
191-
<Callout warning>
192-
Be sure to add a "raw" folder under app/src/main/res directory if it doesn't
193-
exist.
194-
</Callout>
195-
196-
```bash title="Terminal" showLineNumbers={false}
197-
npx amplify generate config --app-id <app-id> --branch main --format json-mobile --out-dir app/src/main/res/raw
198-
```
199-
</InlineFilter>
200-
<InlineFilter filters={['swift']}>
201-
202-
```bash title="Terminal" showLineNumbers={false}
203-
npx amplify generate config --app-id <app-id> --format json-mobile
204-
```
205-
206-
Once the sandbox environment is running, you would also generate the configuration files for your application. However, Xcode won't be able to recognize them. For recognizing the files, you need to drag and drop the generated files to your project.
207-
208-
<video autoPlay={true} muted={true} loop={true} width="100%" playsInline={true}>
209-
<source src="/images/gen2/getting-started/ios/ios-getting-started-2.mp4" />
210-
</video>
211-
212-
</InlineFilter>
213182

214183
## Generate client codegen
215184

216185
<Callout info>
217-
Amplify Gen 2 introduces a fully typed experience for data that no longer requires an explicit codegen step, unlike in Amplify Gen 1. You will only need this command if you are building a mobile app or have Gen 1 requirements.
186+
187+
Amplify Gen 2 introduces a fully typed experience for data that no longer requires an explicit codegen step, unlike in Amplify Gen 1. You will only need this command if you are building a mobile app or have Gen 1 requirements.
188+
218189
</Callout>
219190

220191
Codegen generates native code for Swift (iOS), Java (Android), and JavaScript that represents your GraphQL API's data models. It can also generate GraphQL statements (queries, mutations, and subscriptions) so that you don't have to manually code them.
221192

222-
```bash title="Terminal" showLineNumbers={false}
223-
npx amplify generate graphql-client-code --format [choices: "modelgen", "graphql-codegen", "introspection"]
224-
```
225-
226193
Once your sandbox completes a deployment, you can run the following command in the terminal to generate client code that is specific to your needs:
227194

228-
<InlineFilter filters={['angular','javascript','nextjs','react','react-native','vue']}>
229-
```bash title="Terminal" showLineNumbers={false}
230-
npx amplify generate graphql-client-code --format modelgen
231-
```
232-
</InlineFilter>
233-
<InlineFilter filters={['android']}>
234-
```bash title="Terminal" showLineNumbers={false}
235-
npx amplify generate graphql-client-code --format modelgen --model-target java --out app/src/main/java
236-
```
237-
</InlineFilter>
238-
<InlineFilter filters={['flutter']}>
239-
```bash title="Terminal" showLineNumbers={false}
240-
npx amplify generate graphql-client-code --format modelgen --model-target dart --out lib/models
195+
```bash
196+
npx amplify generate graphql-client-code
197+
--format [choices: "modelgen", "graphql-codegen", "introspection"]
241198
```
242-
</InlineFilter>
243-
<InlineFilter filters={['swift']}>
244-
```bash title="Terminal" showLineNumbers={false}
245-
npx amplify generate graphql-client-code --format modelgen
246-
```
247-
248-
Move the generated files to your project. You can do this by dragging and dropping the files to your project.
249-
250-
![Dialog appears when users drag and drop the generated files into Xcode. It displays targets, added folders, and destination options. The default settings should be sufficient for drag and drop.](/images/lib/getting-started/ios/set-up-swift-8.png)
251-
</InlineFilter>
252199

253200
## Delete a sandbox
254201

255202
You can delete a cloud sandbox environment in several ways:
256203

257204
1. Ctrl+C your sandbox and choose to delete resources.
258205
1. Run `npx amplify sandbox delete` or `npx amplify sandbox delete --name`
259-
1. Visit the Amplify console and [delete sandboxes](/[platform]/deploy-and-host/sandbox-environments/setup/#manage-sandbox-environments).
206+
1. Visit the Amplify console and [delete sandboxes](/gen2/deploy-and-host/sandbox-environments/setup/#manage-sandbox-environments).

src/pages/[platform]/deploy-and-host/sandbox-environments/setup/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ Keep the following best practices in mind when working with cloud sandbox enviro
8181
- Sandboxes are identical in fidelity to your production environments.
8282
- Code changes are continuously deployed to your sandbox on every save for fast iterations.
8383
- Use sandboxes for experimentation and testing, not for production workloads.
84-
- Deploy one sandbox per Amplify app to prevent conflicts.
84+
- Deploy one sandbox per Amplify app per developer to prevent conflicts.
8585
- Reset sandboxes occasionally to clear out unused resources and save costs.

0 commit comments

Comments
 (0)