2020-11-26 17:46:36 +01:00
|
|
|
const AWS = require("aws-sdk")
|
2021-01-13 17:39:47 +01:00
|
|
|
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
|
2020-11-26 17:46:36 +01:00
|
|
|
|
2021-01-11 18:18:22 +01:00
|
|
|
const SCHEMA = {
|
|
|
|
datasource: {
|
|
|
|
region: {
|
2021-01-13 17:39:47 +01:00
|
|
|
type: FIELD_TYPES.STRING,
|
2021-01-11 18:18:22 +01:00
|
|
|
required: true,
|
|
|
|
default: "us-east-1",
|
|
|
|
},
|
|
|
|
accessKeyId: {
|
2021-01-13 17:39:47 +01:00
|
|
|
type: FIELD_TYPES.PASSWORD,
|
2021-01-11 18:18:22 +01:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
secretKey: {
|
2021-01-13 17:39:47 +01:00
|
|
|
type: FIELD_TYPES.PASSWORD,
|
2021-01-11 18:18:22 +01:00
|
|
|
required: true,
|
|
|
|
},
|
2020-11-26 17:46:36 +01:00
|
|
|
},
|
2021-01-11 18:18:22 +01:00
|
|
|
query: {
|
2021-01-13 17:39:47 +01:00
|
|
|
read: {
|
|
|
|
DynamoConfig: {
|
|
|
|
type: QUERY_TYPES.FIELDS,
|
|
|
|
fields: {
|
|
|
|
Table: {
|
|
|
|
type: FIELD_TYPES.STRING,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
Index: {
|
|
|
|
type: FIELD_TYPES.STRING,
|
|
|
|
},
|
|
|
|
KeyConditionExpression: {
|
|
|
|
type: FIELD_TYPES.STRING,
|
|
|
|
},
|
|
|
|
ExpressionAttributeNames: {
|
|
|
|
type: FIELD_TYPES.STRING,
|
|
|
|
},
|
|
|
|
ExpressionAttributeValues: {
|
|
|
|
type: FIELD_TYPES.STRING,
|
|
|
|
},
|
|
|
|
},
|
2021-01-11 18:18:22 +01:00
|
|
|
},
|
2021-01-13 17:39:47 +01:00
|
|
|
},
|
2020-11-26 17:46:36 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
class DynamoDBIntegration {
|
|
|
|
constructor(config) {
|
|
|
|
this.config = config
|
|
|
|
this.connect()
|
|
|
|
this.client = new AWS.DynamoDB.DocumentClient()
|
|
|
|
}
|
|
|
|
|
|
|
|
async connect() {
|
|
|
|
AWS.config.update(this.config)
|
|
|
|
}
|
|
|
|
|
2021-01-13 17:39:47 +01:00
|
|
|
async read(query) {
|
2020-11-26 17:46:36 +01:00
|
|
|
const response = await this.client.query({
|
2021-01-13 17:39:47 +01:00
|
|
|
TableName: query.Table,
|
|
|
|
KeyConditionExpression: query.KeyConditionExpression,
|
|
|
|
ExpressionAttributeNames: query.ExpressionAttributeNames,
|
|
|
|
ExpressionAttributeValues: query.ExpressionAttributeValues,
|
2020-11-26 17:46:36 +01:00
|
|
|
})
|
|
|
|
return response
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2021-01-11 18:18:22 +01:00
|
|
|
schema: SCHEMA,
|
2020-11-26 17:46:36 +01:00
|
|
|
integration: DynamoDBIntegration,
|
|
|
|
}
|