mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
dynamodb: request item
This commit is contained in:
parent
0c3a191859
commit
cfe80b454d
149
packages/nodes-base/nodes/Aws/AwsDynamoDB.node.ts
Normal file
149
packages/nodes-base/nodes/Aws/AwsDynamoDB.node.ts
Normal file
|
@ -0,0 +1,149 @@
|
|||
import {IExecuteFunctions} from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { awsApiRequestREST } from './GenericFunctions';
|
||||
|
||||
function decodeAttribute(type: string, attribute: any): any {
|
||||
switch (type) {
|
||||
case 'S':
|
||||
return String(attribute);
|
||||
case 'SS':
|
||||
case 'M':
|
||||
case 'L':
|
||||
case 'NS':
|
||||
return Array(...attribute);
|
||||
case 'N':
|
||||
return Number(attribute);
|
||||
case 'BOOL':
|
||||
return Boolean(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
export class AwsDynamoDB implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'AWS DynamoDB',
|
||||
name: 'awsDynamoDb',
|
||||
icon: 'file:dynamodb.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Query data on AWS DynamoDB',
|
||||
defaults: {
|
||||
name: 'AWS DynamoDB',
|
||||
color: '#2273b9',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'aws',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Item',
|
||||
value: 'item',
|
||||
description: 'Query Items',
|
||||
},
|
||||
{
|
||||
name: 'Query',
|
||||
value: 'query',
|
||||
description: 'Invoke a function',
|
||||
},
|
||||
],
|
||||
default: 'item',
|
||||
description: 'The resource to operate on.',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'GetItem',
|
||||
value: 'get',
|
||||
description: 'Read an item.',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
{
|
||||
displayName: 'Table',
|
||||
name: 'table',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item', 'query'],
|
||||
}
|
||||
},
|
||||
default: '',
|
||||
description: 'Specify the table you want to operate on',
|
||||
},
|
||||
{
|
||||
displayName: 'Item',
|
||||
name: 'item',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['get'],
|
||||
}
|
||||
},
|
||||
default: '',
|
||||
description: 'Specify the Item you want to operate on',
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (resource === 'item') {
|
||||
if (operation === 'get') {
|
||||
const table = this.getNodeParameter('table', 0) as string;
|
||||
const item = this.getNodeParameter('item', 0) as string;
|
||||
|
||||
const body = {
|
||||
TableName: table,
|
||||
Key: {id: {S: item}},
|
||||
};
|
||||
|
||||
const headers = {
|
||||
'X-Amz-Target': 'DynamoDB_20120810.GetItem',
|
||||
'Content-Type': 'application/x-amz-json-1.0'
|
||||
};
|
||||
const response = await awsApiRequestREST.call(this, 'dynamodb', 'POST', '/', JSON.stringify(body), headers)
|
||||
|
||||
const _item: any = {};
|
||||
for (const [attribute, value] of Object.entries(response.Item)) {
|
||||
const [type, content] = Object.entries(value)[0];
|
||||
_item[attribute] = decodeAttribute(type, content);
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(_item)];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return [[]];
|
||||
}
|
||||
}
|
13
packages/nodes-base/nodes/Aws/dynamodb.svg
Normal file
13
packages/nodes-base/nodes/Aws/dynamodb.svg
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="256px" height="289px" viewBox="0 0 256 289" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
|
||||
<g>
|
||||
<path d="M165.258,288.501 L168.766,288.501 L226.027,259.867 L226.98,258.52 L226.98,29.964 L226.027,28.61 L168.766,0 L165.215,0 L165.258,288.501" fill="#5294CF"/>
|
||||
<path d="M90.741,288.501 L87.184,288.501 L29.972,259.867 L28.811,257.87 L28.222,31.128 L29.972,28.61 L87.184,0 L90.785,0 L90.741,288.501" fill="#1F5B98"/>
|
||||
<path d="M87.285,0 L168.711,0 L168.711,288.501 L87.285,288.501 L87.285,0 Z" fill="#2D72B8"/>
|
||||
<path d="M256,137.769 L254.065,137.34 L226.437,134.764 L226.027,134.968 L168.715,132.676 L87.285,132.676 L29.972,134.968 L29.972,91.264 L29.912,91.296 L29.972,91.168 L87.285,77.888 L168.715,77.888 L226.027,91.168 L247.096,102.367 L247.096,95.167 L256,94.193 L255.078,92.395 L226.886,72.236 L226.027,72.515 L168.715,54.756 L87.285,54.756 L29.972,72.515 L29.972,28.61 L0,63.723 L0,94.389 L0.232,94.221 L8.904,95.167 L8.904,102.515 L0,107.28 L0,137.793 L0.232,137.769 L8.904,137.897 L8.904,150.704 L1.422,150.816 L0,150.68 L0,181.205 L8.904,185.993 L8.904,193.426 L0.373,194.368 L0,194.088 L0,224.749 L29.972,259.867 L29.972,215.966 L87.285,233.725 L168.715,233.725 L226.196,215.914 L226.96,216.249 L254.781,196.387 L256,194.408 L247.096,193.426 L247.096,186.142 L245.929,185.676 L226.886,195.941 L226.196,197.381 L168.715,210.584 L168.715,210.6 L87.285,210.6 L87.285,210.584 L29.972,197.325 L29.972,153.461 L87.285,155.745 L87.285,155.801 L168.715,155.801 L226.027,153.461 L227.332,154.061 L254.111,151.755 L256,150.832 L247.096,150.704 L247.096,137.897 L256,137.769" fill="#1A476F"/>
|
||||
<path d="M226.027,215.966 L226.027,259.867 L256,224.749 L256,194.288 L226.2,215.914 L226.027,215.966" fill="#2D72B8"/>
|
||||
<path d="M226.027,197.421 L226.2,197.381 L256,181.353 L256,150.704 L226.027,153.461 L226.027,197.421" fill="#2D72B8"/>
|
||||
<path d="M226.2,91.208 L226.027,91.168 L226.027,134.968 L256,137.769 L256,107.135 L226.2,91.208" fill="#2D72B8"/>
|
||||
<path d="M226.2,72.687 L256,94.193 L256,63.731 L226.027,28.61 L226.027,72.515 L226.2,72.575 L226.2,72.687" fill="#2D72B8"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
|
@ -283,6 +283,7 @@
|
|||
"dist/nodes/Autopilot/Autopilot.node.js",
|
||||
"dist/nodes/Autopilot/AutopilotTrigger.node.js",
|
||||
"dist/nodes/Aws/AwsLambda.node.js",
|
||||
"dist/nodes/Aws/AwsDynamoDB.node.js",
|
||||
"dist/nodes/Aws/Comprehend/AwsComprehend.node.js",
|
||||
"dist/nodes/Aws/Rekognition/AwsRekognition.node.js",
|
||||
"dist/nodes/Aws/S3/AwsS3.node.js",
|
||||
|
|
Loading…
Reference in a new issue