Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin assumes aws-sdk preconfiguration #2

Open
erikerikson opened this issue Jun 17, 2016 · 5 comments
Open

Plugin assumes aws-sdk preconfiguration #2

erikerikson opened this issue Jun 17, 2016 · 5 comments

Comments

@erikerikson
Copy link
Contributor

The plugin assumes that the aws-sdk library has been configured with credentials, proxy agent settings, et cetera before artillery-plugin-cloudwatch is loaded (i.e. during the creation of an require('artillery-core').runner). As a result, if such configuration has not been applied to the aws-sdk library then the call to cloudwatch will fail.

@erikerikson
Copy link
Contributor Author

this issue is now noted in the readme. will await use cases before taking action.

@JankesJanco
Copy link

Can you please give me an advice? How can I configure aws-sdk library as you noted here? I am new to nodejs and I have no idea how to do this. Thanks

@erikerikson
Copy link
Contributor Author

erikerikson commented Dec 15, 2017

For example: http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-environment.html

export/set AWS_ACCESS_KEY_ID=[...]
AWS_SECRET_ACCESS_KEY=[...]
AWS_SESSION_TOKEN=[...]

Configuration that is not based on environment variable settings will require you write a script that loads the aws-sdk and also serverless-artillery/lib, configures aws-sdkas needed, and then invokes the command you would like to run.

The key knowledge here is that require caches dependencies (within a process) so that when serverless-artillery requires the aws-sdk it gets the same reference (i.e. physical memory space) that your script does when requiring it, which means you can make changes to that object's state (i.e. by adding configuration) and have those changes apply to serverless-artillery's use of it.

So, for example, you could set a proxy:

const aws = require('aws-sdk')
const agent = require('https-proxy-agent')
const slsart = require ('serverless-artillery/lib')
aws.config.update({
  httpOptions: { agent: new agent('http://internal.proxy.com') }
})
slsart['invoke']({ region: 'us-west-2'})

@JankesJanco
Copy link

Great. Thanks for fast and exhaustive reply.

@JankesJanco
Copy link

JankesJanco commented Dec 18, 2017

Only for specification / clarification of my issue. I was getting this error:

Error reporting metrics to CloudWatch via putMetricData: { ConfigError: Missing region in config
    at Request.VALIDATE_REGION (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/event_listeners.js:91:45)
    at Request.callListeners (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at callNextListener (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at /usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/event_listeners.js:85:9
    at finish (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/config.js:320:7)
    at /usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/config.js:338:9
    at SharedIniFileCredentials.get (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/credentials.js:126:7)
    at getAsyncCredentials (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/config.js:332:24)
    at Config.getCredentials (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/config.js:352:9)
    at Request.VALIDATE_CREDENTIALS (/usr/lib/node_modules/artillery-plugin-cloudwatch/node_modules/aws-sdk/lib/event_listeners.js:80:26)
  message: 'Missing region in config',
  code: 'ConfigError',
  time: 2017-12-18T12:35:48.361Z }

I had to set AWS region (not AWS credentials) to get rid of this error. It can be done in same way as described above. I've just define enviroment variable AWS_REGION:

export AWS_REGION=eu-central-1

Documentation about configuring AWS region is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants