How to make a plugin with aws-sdk pass corporate proxy

aws

#1

Hi,

I just made a new plugin

https://www.npmjs.com/package/aws-cognito-idp-userpool-domain (it’s on the line to be published)

but I had noticed that when I’m behind the corporate proxy it just works when I add the lines below to the code:

var proxy = require('proxy-agent');

AWS.config.update({
  httpOptions: { agent: proxy('http://username:password@internal.proxy.com') }
});

How can I reuse the proxy setting from Serverless framework in a way I do not need to add this code, and mainly the username and password?

I have noticed that even without credentials in the environment variables (https_proxy), serverless works fine. Why aws-sdk inside a plugin require credentials?

thanks!


#2

here’s the trick

insted of:

const AWS = require('aws-sdk');
const proxy = require('proxy-agent');

AWS.config.update({
  httpOptions: { 
    agent: proxy('http://user:pasword@<proxyserver>:<port>/') 
  }
});

this.cognitoIdp = new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });

use:

this.cognitoIdp = new this.serverless.providers.aws.sdk.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18', region: this.serverless.providers.aws.getRegion() });

and all should be fine.