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
resolves#1366
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
Copy file name to clipboardExpand all lines: site/content/docs/developing/environment-variables.en.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Environment variables are variables that are available to your service, based on the environment they're running in. Your service can reference them without having to define them. Environment variables are useful for when you want to pass in data to your service that's specific to a particular environment. For example, your test database name versus your production database name.
4
4
5
-
Accessing environment variables is usually simply based on the language you're using. Here are some examples of getting an environment variable called `DATABASE_NAME` in a few different languages.
5
+
Accessing environment variables is usually simply based on the language you're using. Here are some examples of getting an environment variable called `DATABASE_NAME` in a few different languages.
By default, the AWS Copilot CLI passes in some default environment variables for your service to use.
24
+
By default, the AWS Copilot CLI passes in some default environment variables for your service to use.
25
25
26
-
*`COPILOT_APPLICATION_NAME` - this is the name of the application this service is running in.
26
+
*`COPILOT_APPLICATION_NAME` - this is the name of the application this service is running in.
27
27
*`COPILOT_ENVIRONMENT_NAME` - this is the name of the environment the service is running in (test vs prod, for example)
28
-
*`COPILOT_SERVICE_NAME` - this is the name of the current service.
29
-
*`COPILOT_LB_DNS` - this is the DNS name of the Load Balancer (if it exists) such as _kudos-Publi-MC2WNHAIOAVS-588300247.us-west-2.elb.amazonaws.com_. Note: if you're using a custom domain name, this value will still be the Load Balancer's DNS name.
28
+
*`COPILOT_SERVICE_NAME` - this is the name of the current service.
29
+
*`COPILOT_LB_DNS` - this is the DNS name of the Load Balancer (if it exists) such as _kudos-Publi-MC2WNHAIOAVS-588300247.us-west-2.elb.amazonaws.com_. Note: if you're using a custom domain name, this value will still be the Load Balancer's DNS name.
30
30
*`COPILOT_SERVICE_DISCOVERY_ENDPOINT` - this is the endpoint to add after a service name to talk to another service in your environment via service discovery. The value is `{env name}.{app name}.local`. For more information about service discovery, check out our [Service Discovery guide](../developing/service-discovery.en.md).
31
31
32
32
## How do I add my own Environment Variables?
33
33
34
-
Adding your own environment variable is easy. You can add them directly to your [manifest](../manifest/overview.en.md) in the `variables` section. The following snippet will pass a environment variable called `LOG_LEVEL` to your service, with the value set to `debug`.
34
+
Adding your own environment variable is easy. You can add them directly to your [manifest](../manifest/overview.en.md) in the `variables` section. The following snippet will pass a environment variable called `LOG_LEVEL` to your service, with the value set to `debug`.
35
35
36
36
```yaml
37
-
# in copilot/{service name}/manifest.yml
37
+
# in copilot/{service name}/manifest.yml
38
38
variables:
39
39
LOG_LEVEL: debug
40
40
```
41
41
42
42
You can also pass in a specific value for an environment variable based on the environment. We'll follow the same example as above, by setting the log level, but overriding the value to be `info` in our production environment. Changes to your manifest take effect when you deploy them, so changing them locally is safe.
43
43
44
44
```yaml
45
-
# in copilot/{service name}/manifest.yml
45
+
# in copilot/{service name}/manifest.yml
46
46
variables:
47
47
LOG_LEVEL: debug
48
48
@@ -56,6 +56,20 @@ Here's a quick guide showing you how to add environment variables to your app by
56
56
57
57

58
58
59
+
Additionally, if you want to add environment variables in bulk, you can list them in an [env file](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/taskdef-envfiles.html#taskdef-envfiles-considerations). And then specify its path (from the root of the workspace) in the `env_file` field of your[manifest](../manifest/overview.en.md).
60
+
61
+
```yaml
62
+
# in copilot/{service name}/manifest.yml
63
+
env_file: log.env
64
+
```
65
+
66
+
And in `log.env` we could have
67
+
```
68
+
#This is a comment and will be ignored
69
+
LOG_LEVEL=debug
70
+
LOG_INFO=all
71
+
```
72
+
59
73
## How do I know the name of my DynamoDB table, S3 bucket, RDS database, etc?
60
74
61
75
When using the Copilot CLI to provision additional AWS resources such as DynamoDB tables, S3 buckets, databases, etc., any output values will be passed in as environment variables to your app. For more information, check out the [additional resources guide](../developing/additional-aws-resources.en.md).
0 commit comments