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
Copy file name to clipboardExpand all lines: README.md
+110-5Lines changed: 110 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,10 +52,13 @@ Put options under `custom.appsync-simulator` in your `serverless.yml` file
52
52
| port | 20002 | AppSync operations port |
53
53
| wsPort | 20003 | AppSync subscriptions port |
54
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 |
55
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 |
56
58
| dynamoDb.region | localhost | Dynamodb region. Specify it if you're connecting to a remote Dynamodb intance. |
57
59
| dynamoDb.accessKeyId | DEFAULT_ACCESS_KEY | AWS Access Key ID to access DynamoDB |
This plugin supports *some* resources resolution from the `Ref` and `Fn::GetAtt` functions
76
+
in your yaml file. It also supports *some* other Cfn functions such as `Fn::Join`, `Fb::Sub`, etc.
77
+
78
+
**Note:** Under the hood, this features relies on the [cfn-resolver-lib](https://github.com/robessog/cfn-resolver-lib) package. For more info on supported cfn functions, refer to [the documentation](https://github.com/robessog/cfn-resolver-lib/blob/master/README.md)
79
+
80
+
## Basic usage
81
+
82
+
You can reference resources in your functions' environment variables (that will be accessible from your lambda functions) or datasource definitions.
83
+
The plugin will automatically resolve them for you.
84
+
85
+
````yaml
86
+
provider:
87
+
environment:
88
+
BUCKET_NAME:
89
+
Ref: MyBucket # resolves to `my-bucket-name`
90
+
91
+
resources:
92
+
Resources:
93
+
MyDbTable:
94
+
Type: AWS::DynamoDB::Table
95
+
Properties:
96
+
TableName: myTable
97
+
...
98
+
MyBucket:
99
+
Type: AWS::S3::Bucket
100
+
Properties:
101
+
BucketName: my-bucket-name
102
+
...
103
+
104
+
# in your appsync config
105
+
dataSources:
106
+
- type: AMAZON_DYNAMODB
107
+
name: dynamosource
108
+
config:
109
+
tableName:
110
+
Ref: MyDbTable # resolves to `myTable`
111
+
````
112
+
113
+
## Override (or mock) values
114
+
115
+
Sometimes, some references **cannot** be resolved, as they come from an *Output* from Cloudformation; or you might want to use mocked values in your local environment.
116
+
117
+
In those cases, you can define (or override) those values using the `refMap` and `getAttMap` options.
118
+
119
+
- `refMap`takes a mapping of *resource name* to *value* pairs
120
+
- `getAttMap`takes a mapping of *resource name* to *attribute/values* pairs
121
+
122
+
Example:
123
+
124
+
````yaml
125
+
custom:
126
+
serverless-appsync-simulator:
127
+
refMap:
128
+
# Override `MyDbTable` resolution from the previous example.
129
+
MyDbTable: 'mock-myTable'
130
+
getAttMap:
131
+
# define ElasticSearchInstance DomainName
132
+
ElasticSearchInstance:
133
+
DomainEndpoint: "localhost:9200"
134
+
135
+
# in your appsync config
136
+
dataSources:
137
+
- type: AMAZON_ELASTICSEARCH
138
+
name: elasticsource
139
+
config:
140
+
# endpoint resolves as 'http://localhost:9200'
141
+
endpoint:
142
+
Fn::Join:
143
+
- ""
144
+
- - https://
145
+
- Fn::GetAtt:
146
+
- ElasticSearchInstance
147
+
- DomainEndpoint
148
+
````
149
+
150
+
## Limitations
151
+
152
+
This plugin only tries to resolve the following parts of the yml tree:
153
+
- `provider.environment`
154
+
- `functions[*].environment`
155
+
- `custom.appSync`
156
+
157
+
If you have the need of resolving others, feel free to open an issue and explain your use case.
158
+
159
+
For now, the supported resources to be automatically resovled by `Ref:` are:
160
+
- DynamoDb tables
161
+
- S3 Buckets
71
162
72
-
This plugin currently only supports resolvers implemented by `amplify-appsync-simulator`.
73
-
At the time of writing, this is:
163
+
Feel free to open a PR or an issue to extend them as well.
74
164
165
+
# Supported Resolver types
166
+
167
+
This plugin supports resolvers implemented by `amplify-appsync-simulator`, as well as custom resolvers.
168
+
169
+
**From Aws Amplify:**
75
170
- NONE
76
171
- AWS_LAMBDA (*)
77
172
- AMAZON_DYNAMODB
173
+
- PIPELINE
174
+
175
+
**Implemented by this plugin**
176
+
- AWS_LAMBDA (*)
177
+
- AMAZON_ELASTIC_SEARCH
178
+
- HTTP
179
+
180
+
(*) The `AWS_LAMBDA` dataloader has been partially copied from Aws Amplify but has been extended
181
+
to support the *BatchInvoke* operations
78
182
79
-
(*) Note: This plugin also supports `AWS_LAMBDA`'s `BatchInvoke` (which Amplify Simulator doesn't)
0 commit comments