You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { env } from'$amplify/env/say-hello'; // the import is '$amplify/env/<functionname>'
75
+
import { env } from'$amplify/env/say-hello'; // the import is '$amplify/env/<function-name>'
76
76
77
77
exportconst handler =async (event) => {
78
78
// the env object has intellisense for all environment variables that are available to the function
@@ -100,6 +100,48 @@ If you did not, you will need to manually configure your project. Within your `a
100
100
101
101
</Accordion>
102
102
103
+
### Generated env files
104
+
105
+
When you configure your function with environment variables or secrets, Amplify's backend tooling generates a file using the function's `name` in `.amplify/generated` with references to your environment variables and secrets, as well as [environment variables predefined by the Lambda runtime](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime). This provides a type-safe experience for working with environment variables that does not require typing `process.env` manually.
106
+
107
+
<Calloutinfo>
108
+
109
+
**Note:** generated files are created before deployments when executing `ampx sandbox` or `ampx pipeline-deploy`
110
+
111
+
</Callout>
112
+
113
+
For example, if you have a function with the following definition:
// the env object has intellisense for all environment variables that are available to the function
139
+
return`Hello, ${env.NAME}!`;
140
+
};
141
+
```
142
+
143
+
Encountering issues with this file? [Visit the troubleshooting guide for `Cannot find module $amplify/env/<function-name>`](/[platform]/build-a-backend/troubleshooting/cannot-find-module-amplify-env/)
144
+
103
145
## Secrets
104
146
105
147
Sometimes it is necessary to provide a secret value to a function. For example, it may need a database password or an API key to perform some business use case. Environment variables should NOT be used for this because environment variable values are included in plaintext in the function configuration. Instead, secret access can be used.
0 commit comments