Skip to content

Commit e98300b

Browse files
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 b6fe6dd commit e98300b

File tree

2 files changed

+75
-31
lines changed

2 files changed

+75
-31
lines changed

src/pages/gen2/deploy-and-host/sandbox-environments/features/index.mdx

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,68 @@ Sandbox environments include additional features for managing secrets, deploying
1818
## Secure secrets in your sandbox
1919

2020
<Callout info>
21+
2122
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.
23+
2224
</Callout>
2325

24-
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>`.
26+
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.
2527

2628
### Set secrets
2729

28-
You can add secrets while running your cloud sandbox with the following command:
30+
You can add secrets to your sandbox environment using the following command:
2931

3032
```bash
3133
npx amplify sandbox secret set foo
3234
? Enter secret value: ###
3335
Done!
3436

35-
> npx amplify sandbox secret set bar
37+
npx amplify sandbox secret set bar
3638
? Enter secret value: ###
3739
Done!
3840
```
3941

40-
### Access secrets
42+
After these commands, your sandbox will have two secrets named `foo` and `bar`.
43+
44+
### List secrets
45+
46+
You can list all of the secret names available in your sandbox environment with the following command:
47+
48+
```bash
49+
npx amplify sandbox secret list
50+
- foo
51+
- bar
52+
```
53+
54+
### Retrieve a secret
55+
56+
<Callout warning>
57+
58+
**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).
59+
60+
</Callout>
61+
62+
To show the value of a secret, run the following command.
63+
64+
```bash
65+
npx amplify sandbox secret get foo
66+
name: foo
67+
version: 1
68+
value: abc123
69+
lastUpdated: Mon Nov 13 2023 22:19:12 GMT-0800 (Pacific Standard Time)
70+
```
71+
72+
### Remove secrets
73+
74+
To remove a secret from from the sandbox, run the following command in your terminal:
75+
76+
```bash
77+
npx amplify sandbox secret remove foo
78+
```
79+
80+
### Reference secrets
4181

42-
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.
82+
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.
4383

4484
```ts
4585
import { defineAuth, secret } from '@aws-amplify/backend';
@@ -59,53 +99,55 @@ export const auth = defineAuth({
5999
});
60100
```
61101

62-
### Retrieve secrets
63-
64-
To get the value of a secret from the cloud, run the following command in your terminal:
102+
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.
65103

66-
```bash
67-
npx amplify sandbox secret get foo
68-
name: foo
69-
version: 1
70-
value: 123
71-
lastUpdated: Mon Nov 13 2023 22:19:12 GMT-0800 (Pacific Standard Time)
72-
```
104+
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).
73105

74-
### Remove secrets
106+
<Callout info>
75107

76-
To remove a secret from the cloud, run the following command in your terminal:
108+
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)
77109

78-
```bash
79-
npx amplify sandbox secret remove foo
80-
```
110+
</Callout>
81111

82-
### Work with multiple AWS profiles
112+
## Work with multiple AWS profiles
83113

84-
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:
114+
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:
85115

86116
```bash
87117
npx amplify sandbox secret set foo --profile work
88118
```
89119

90-
## Multiple sandboxes per app
120+
## Work with multiple named sandboxes
91121

92122
<Callout info>
93-
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.
123+
124+
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.
125+
94126
</Callout>
95127

96-
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:
128+
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:
97129

98130
```bash
99-
npx amplify sandbox --name s1
131+
npx amplify sandbox --identifier feature1sandbox
100132
```
101133

102-
Once the deployment completes, exit sandbox `s1` and run the following command in the terminal:
134+
This will start a sandbox named `feature1sandbox`.
135+
136+
Once the deployment completes, exit sandbox and run the following command in the terminal:
103137

104138
```bash
105-
npx amplify sandbox --name s2
139+
npx amplify sandbox --identifier feature2sandbox
106140
```
107141

108-
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.
142+
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.
143+
144+
### Secret management with named sandboxes
145+
146+
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:
147+
148+
```bash
149+
npx amplify sandbox --identifier feature1sandbox secret set baz
150+
```
109151

110152
## Generate client config
111153

@@ -124,7 +166,9 @@ npx amplify generate config --app-id <AMPLIFY_APP_ID> --branch main --format ["m
124166
## Generate client codegen
125167

126168
<Callout info>
127-
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.
169+
170+
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.
171+
128172
</Callout>
129173

130174
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.

src/pages/gen2/deploy-and-host/sandbox-environments/setup/index.mdx

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

0 commit comments

Comments
 (0)