Skip to content

Commit b94c133

Browse files
marcorenibboure
authored andcommitted
Support external dynamodb endpoint and define default AWS credenti… (#4)
* Support external dynamodb endpoint and define default AWS credentials * Support external dynamodb region parameter * Update README.md
1 parent 317918a commit b94c133

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ This plugin relies on your serverless yml file and on the `serverless-offline` p
2121

2222
````yml
2323
plugins:
24-
- serverless-dynamodb-local # only if you need dynamodb resolvers
24+
- serverless-dynamodb-local # only if you need dynamodb resolvers and you don't have an external dynamodb
2525
- serverless-appsync-simulator
2626
- serverless-offline
2727
````
2828

2929
**Note:** Order is important `serverless-appsync-simulator` must go **before** `serverless-offline`
3030

31-
To start the simulator, run the followin command:
31+
To start the simulator, run the following command:
3232
````bash
3333
sls offline start
3434
````
@@ -46,19 +46,25 @@ 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-
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+
| 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+
| dynamoDb.region | localhost | Dynamodb region. Specify it if you're connecting to a remote Dynamodb intance. |
57+
| dynamoDb.accessKeyId | DEFAULT_ACCESS_KEY | AWS Access Key ID to access DynamoDB |
58+
| dynamoDb.secretAccessKey | DEFAULT_SECRET | AWS Secret Key to access DynamoDB |
5659
Example:
5760

5861
````yml
5962
custom:
6063
appsync-simulator:
6164
location: '.webpack/service' # use webpack build directory
65+
dynamoDb:
66+
endpoint: 'http://my-custom-dynamo:8000'
67+
6268
````
6369

6470
# Caveats

src/getAppSyncConfig.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,20 @@ export default function getAppSyncConfig(context, appSyncConfig) {
4848

4949
switch (source.type) {
5050
case 'AMAZON_DYNAMODB': {
51-
const { port } = context.options.dynamoDb;
51+
const {
52+
endpoint,
53+
region,
54+
accessKeyId,
55+
secretAccessKey,
56+
} = context.options.dynamoDb;
57+
5258
return {
5359
...dataSource,
5460
config: {
55-
endpoint: `http://localhost:${port}`,
56-
region: 'localhost',
61+
endpoint,
62+
region,
63+
accessKeyId,
64+
secretAccessKey,
5765
tableName: getTableName(source.config.tableName),
5866
},
5967
};

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class ServerlessAppSyncSimulator {
1919
wsPort: 20003,
2020
location: '.',
2121
dynamoDb: {
22-
port: get(this.serverless.service, 'custom.dynamodb.start.port', 8000),
22+
endpoint: `http://localhost:${get(this.serverless.service, 'custom.dynamodb.start.port', 8000)}`,
23+
region: 'localhost',
24+
accessKeyId: 'DEFAULT_ACCESS_KEY',
25+
secretAccessKey: 'DEFAULT_SECRET',
2326
},
2427
},
2528
get(this.serverless.service, 'custom.appsync-simulator', {}),

0 commit comments

Comments
 (0)