Daniel-t / node-red-contrib-aws

A collection of Node-RED nodes for AWS.
Apache License 2.0
57 stars 59 forks source link

Improvement request: allow passing AWS credentials #69

Closed oleg31337 closed 3 years ago

oleg31337 commented 3 years ago

Allow passing region and credentials with a message something like that:

var awsregion=node.region; var awskey=node.accessKey; var awssecret=node.secretKey; if (typeof msg.region !== 'undefined' && msg.region !== null && msg.region !== ""){ awsregion=msg.region.toLowerCase(); } if (typeof msg.awskey !== 'undefined' && msg.awskey !== null && msg.awskey !== "" && typeof msg.awssecret !== 'undefined' && msg.awssecret !== null && msg.awssecret !== ""){ awskey=msg.awskey; awssecret=msg.awssecret; } var awsService = new AWS.EC2( { 'region': awsregion, 'accessKeyId': awskey, 'secretAccessKey': awssecret } );

Daniel-t commented 3 years ago

This is tricky, at the moment the AWS service is initiated once per node, however passing the creds in this way would initiate it for every message.

Could potentially check for the existance of these three attributes in the message and re-initialise only if one (or more) are present.

oleg31337 commented 3 years ago

Yeah that what I do in the code above, if it exists then re-set the region/key/secrets. I have tested it inside your code and it works. Though I'm not really great with Javascript and code must be beautifulized :-)

Daniel-t commented 3 years ago

Turns out it only needed two lines of code (1 new, and one minor change).

Instead of making it credential specific, you can now pass an AWSConfig option which can include new credentials or other config items as needed.