Skip to content

Commit 48db6a2

Browse files
committed
Ensure arc.tables also works in AWS :sweating:
1 parent 15115f5 commit 48db6a2

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/tables/factory.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let { getAwsClient, getPorts } = require('../lib')
1+
let { getAwsClient, getPorts, useAWS } = require('../lib')
22
let getAwsSdkClient = require('./dynamo')
33
let enumerable = false
44
let paginate = true
@@ -10,27 +10,36 @@ module.exports = function factory ({ tables, options = {} }, callback) {
1010
let { ARC_ENV, AWS_REGION } = process.env
1111
let local = ARC_ENV === 'testing'
1212
let region = AWS_REGION || 'us-west-2'
13+
let plugins = [ '@aws-lite/dynamodb' ]
1314

14-
getPorts((err, ports) => {
15-
if (err) callback(err)
16-
else {
17-
let port = ports.tables
18-
if (!port) {
19-
return callback(ReferenceError('Sandbox tables port not found'))
20-
}
21-
let config = {
22-
host: `localhost`,
23-
port,
24-
protocol: 'http',
25-
region,
26-
plugins: [ '@aws-lite/dynamodb' ],
15+
if (useAWS()) {
16+
getAwsClient({ region, plugins }, (err, aws) => {
17+
if (err) callback(err)
18+
else dynamoConstructor({ aws, local, options, tables }, callback)
19+
})
20+
}
21+
else {
22+
getPorts((err, ports) => {
23+
if (err) callback(err)
24+
else {
25+
let port = ports.tables
26+
if (!port) {
27+
return callback(ReferenceError('Sandbox tables port not found'))
28+
}
29+
let config = {
30+
host: `localhost`,
31+
port,
32+
protocol: 'http',
33+
region,
34+
plugins,
35+
}
36+
getAwsClient(config, (err, aws) => {
37+
if (err) callback(err)
38+
else dynamoConstructor({ aws, local, options, tables }, callback)
39+
})
2740
}
28-
getAwsClient(config, (err, aws) => {
29-
if (err) callback(err)
30-
else dynamoConstructor({ aws, local, options, port, region, tables }, callback)
31-
})
32-
}
33-
})
41+
})
42+
}
3443
}
3544

3645
function dynamoConstructor (params, callback) {

0 commit comments

Comments
 (0)