Skip to content

Commit b09f398

Browse files
authored
Merge pull request #24 from purple-technology/f/env-vars
2 parents 8744aad + ab3c576 commit b09f398

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@ Serverless: GraphiQl: http://localhost:20002
4646

4747
Put options under `custom.appsync-simulator` in your `serverless.yml` file
4848

49-
| option | default | description |
50-
| ------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
51-
| apiKey | `0123456789` | When using `API_KEY` as authentication type, the key to authenticate to the endpoint. |
52-
| port | 20002 | AppSync operations port |
53-
| wsPort | 20003 | AppSync subscriptions port |
54-
| location | . (base directory) | Location of the lambda functions handlers. |
55-
| refMap | {} | A mapping of [resource resolutions](#resource-cloudformation-functions-resolution) for the `Ref` function |
56-
| getAttMap | {} | A mapping of [resource resolutions](#resource-cloudformation-functions-resolution) for the `GetAtt` function |
57-
| dynamoDb.endpoint | http://localhost:8000 | Dynamodb endpoint. Specify it if you're not using serverless-dynamodb-local. Otherwise, port is taken from dynamodb-local conf |
58-
| dynamoDb.region | localhost | Dynamodb region. Specify it if you're connecting to a remote Dynamodb intance. |
59-
| dynamoDb.accessKeyId | DEFAULT_ACCESS_KEY | AWS Access Key ID to access DynamoDB |
60-
| dynamoDb.secretAccessKey | DEFAULT_SECRET | AWS Secret Key to access DynamoDB |
49+
| option | default | description |
50+
|--------------------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
51+
| apiKey | `0123456789` | When using `API_KEY` as authentication type, the key to authenticate to the endpoint. |
52+
| port | 20002 | AppSync operations port |
53+
| wsPort | 20003 | AppSync subscriptions port |
54+
| location | . (base directory) | Location of the lambda functions handlers. |
55+
| lambda.loadLocalEnv | false | If `true`, all environment variables (`$ env`) will be accessible from the resolver function. Read more in section [Environment variables](#environment-variables). |
56+
| refMap | {} | A mapping of [resource resolutions](#resource-cloudformation-functions-resolution) for the `Ref` function |
57+
| getAttMap | {} | A mapping of [resource resolutions](#resource-cloudformation-functions-resolution) for the `GetAtt` function |
58+
| dynamoDb.endpoint | http://localhost:8000 | Dynamodb endpoint. Specify it if you're not using serverless-dynamodb-local. Otherwise, port is taken from dynamodb-local conf |
59+
| dynamoDb.region | localhost | Dynamodb region. Specify it if you're connecting to a remote Dynamodb intance. |
60+
| dynamoDb.accessKeyId | DEFAULT_ACCESS_KEY | AWS Access Key ID to access DynamoDB |
61+
| dynamoDb.secretAccessKey | DEFAULT_SECRET | AWS Secret Key to access DynamoDB |
6162

6263
Example:
6364

@@ -147,6 +148,21 @@ dataSources:
147148
- DomainEndpoint
148149
````
149150

151+
## Environment variables
152+
153+
```yaml
154+
custom:
155+
appsync-simulator:
156+
lambda:
157+
loadLocalEnv: true
158+
```
159+
160+
If `true`, all environment variables (`$ env`) will be accessible from the resolver function.
161+
162+
If `false`, only environment variables defined in `serverless.yml` will be accessible from the resolver function.
163+
164+
> _Note: `serverless.yml` environment variables have higher priority than local environment variables. Thus some of your local environment variables, could get overridden by environment variables from `serverless.yml`._
165+
150166
## Limitations
151167

152168
This plugin only tries to resolve the following parts of the yml tree:

src/getAppSyncConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default function getAppSyncConfig(context, appSyncConfig) {
7676
fileName: path.join(context.options.location, fileName),
7777
event: payload,
7878
environment: {
79+
...(context.options.lambda.loadLocalEnv === true ? process.env : {}),
7980
...context.serverless.service.provider.environment,
8081
...func.environment,
8182
},

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class ServerlessAppSyncSimulator {
129129
port: 20002,
130130
wsPort: 20003,
131131
location: '.',
132+
lambda: {
133+
loadLocalEnv: false,
134+
},
132135
refMap: {},
133136
getAttMap: {},
134137
dynamoDb: {

0 commit comments

Comments
 (0)