diff --git a/packages/nodes-base/nodes/Aws/AwsLambda.node.ts b/packages/nodes-base/nodes/Aws/AwsLambda.node.ts index 70e254342b..312316a7d1 100644 --- a/packages/nodes-base/nodes/Aws/AwsLambda.node.ts +++ b/packages/nodes-base/nodes/Aws/AwsLambda.node.ts @@ -8,9 +8,7 @@ import { IDataObject } from 'n8n-workflow'; -import { awsApiRequest } from './GenericFunctions'; - -import { Lambda } from 'aws-sdk'; +import { awsApiRequestREST } from './GenericFunctions'; export class AwsLambda implements INodeType { description: INodeTypeDescription = { @@ -91,7 +89,7 @@ export class AwsLambda implements INodeType { async getFunctions(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; try { - var data = await awsApiRequest.call(this, 'lambda', 'GET', '/2015-03-31/functions/'); + var data = await awsApiRequestREST.call(this, 'lambda', 'GET', '/2015-03-31/functions/'); } catch (err) { throw new Error(`AWS Error: ${err}`); } @@ -121,8 +119,7 @@ export class AwsLambda implements INodeType { }; try { - - var responseData = await awsApiRequest.call( + var responseData = await awsApiRequestREST.call( this, 'lambda', 'POST', diff --git a/packages/nodes-base/nodes/Aws/AwsSns.node.ts b/packages/nodes-base/nodes/Aws/AwsSns.node.ts index ad25539b67..7b12184b6f 100644 --- a/packages/nodes-base/nodes/Aws/AwsSns.node.ts +++ b/packages/nodes-base/nodes/Aws/AwsSns.node.ts @@ -8,9 +8,7 @@ import { IDataObject } from 'n8n-workflow'; -import { awsConfigCredentials } from './GenericFunctions'; - -import { SNS } from 'aws-sdk'; +import { awsApiRequestSOAP } from './GenericFunctions'; export class AwsSns implements INodeType { description: INodeTypeDescription = { @@ -51,6 +49,7 @@ export class AwsSns implements INodeType { name: 'subject', type: 'string', default: '', + required: true, description: 'Subject when the message is delivered to email endpoints', }, { @@ -72,18 +71,15 @@ export class AwsSns implements INodeType { // Get all the available topics to display them to user so that he can // select them easily async getTopics(this: ILoadOptionsFunctions): Promise { - await awsConfigCredentials.call(this); - const returnData: INodePropertyOptions[] = []; - - let sns = new SNS(); try { - var data = await sns.listTopics({}).promise(); + var data = await awsApiRequestSOAP.call(this, 'sns', 'GET', '/?Action=ListTopics'); } catch (err) { throw new Error(`AWS Error: ${err}`); } - for (let topic of data.Topics!) { + const topics = data.ListTopicsResponse.ListTopicsResult.Topics.member; + for (let topic of topics) { let topicArn = topic.TopicArn as string; let topicName = topicArn.split(':')[5]; @@ -102,22 +98,19 @@ export class AwsSns implements INodeType { const items = this.getInputData(); const returnData: IDataObject[] = []; - await awsConfigCredentials.call(this); - const sns = new SNS(); - for (let i = 0; i < items.length; i++) { - const params = { - TopicArn: this.getNodeParameter('topic', i) as string, - Subject: this.getNodeParameter('subject', i) as string, - Message: this.getNodeParameter('message', i) as string, - }; + const params = [ + 'TopicArn=' + this.getNodeParameter('topic', i) as string, + 'Subject=' + this.getNodeParameter('subject', i) as string, + 'Message=' + this.getNodeParameter('message', i) as string, + ]; try { - var responseData = await sns.publish(params).promise(); + var responseData = await awsApiRequestSOAP.call(this, 'sns', 'GET', '/?Action=Publish&' + params.join('&')); } catch (err) { throw new Error(`AWS Error: ${err}`); } - returnData.push({MessageId: responseData.MessageId} as IDataObject); + returnData.push({MessageId: responseData.PublishResponse.PublishResult.MessageId} as IDataObject); } return [this.helpers.returnJsonArray(returnData)]; diff --git a/packages/nodes-base/nodes/Aws/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/GenericFunctions.ts index 30b3f2f94a..cf5f7e0af2 100644 --- a/packages/nodes-base/nodes/Aws/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/GenericFunctions.ts @@ -4,27 +4,12 @@ import { ILoadOptionsFunctions, } from 'n8n-core'; -import { config } from 'aws-sdk'; import { OptionsWithUri } from 'request'; import { sign } from 'aws4'; - -export async function awsConfigCredentials(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions): Promise { - const credentials = this.getCredentials('aws'); - - if (credentials === undefined) { - throw new Error('No credentials got returned!'); - } - - config.update({ - region: `${credentials.region}`, - accessKeyId: `${credentials.accessKeyId}`, - secretAccessKey: `${credentials.secretAccessKey}`, - }); -} +import { parseString } from 'xml2js'; export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any const credentials = this.getCredentials('aws'); - if (credentials === undefined) { throw new Error('No credentials got returned!'); } @@ -42,9 +27,8 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I body: signOpts.body, }; - let response: string try { - response = await this.helpers.request!(options); + return await this.helpers.request!(options); } catch (error) { console.error(error); @@ -57,12 +41,35 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I } } - throw errorMessage; + if (errorMessage !== undefined) { + throw errorMessage; + } + throw error.response.body; } +} + +export async function awsApiRequestREST(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any + const response = await awsApiRequest.call(this, service, method, path, body, headers); try { return JSON.parse(response); } catch (e) { return response } } + +export async function awsApiRequestSOAP(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any + const response = await awsApiRequest.call(this, service, method, path, body, headers); + try { + return await new Promise((resolve, reject) => { + parseString(response, { explicitArray: false }, (err, data) => { + if (err) { + return reject(err); + } + resolve(data); + }); + }); + } catch (e) { + return response + } +} diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 4ee7ae8d65..fa6a8a55ed 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -128,7 +128,6 @@ }, "dependencies": { "aws4": "^1.8.0", - "aws-sdk": "^2.543.0", "basic-auth": "^2.0.1", "cron": "^1.6.0", "glob-promise": "^3.4.0",