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

Failure: Missing region in config #189

Closed
bgenchel opened this issue Jan 20, 2017 · 10 comments
Closed

Failure: Missing region in config #189

bgenchel opened this issue Jan 20, 2017 · 10 comments

Comments

@bgenchel
Copy link

I get this error upon sending my first request while using serverless-offline. No idea what it means, though other issues on the internet seem to imply that it has to do with environment variables that get populated when you deploy ... how does one get over this while working/testing with serverless-offline?

@hassankhan
Copy link

Same here, I've defined my stage and region in serverless.yml so not quite sure why its not picking them up.

@dherault
Copy link
Owner

Hi, thanks for reporting this issue. This does not look like an error the plugin would raise. Can someone paste a stack trace please ?

@hassankhan
Copy link

hassankhan commented Jan 20, 2017

I've attached the stack trace, but the error occurs when trying to initialise an AWS service. The stack trace doesn't show any errors from the plugin - it seems as if environment variables such as stage and region aren't being passed any more :/

An error occurred
{ ConfigError: Missing region in config
    at Request.VALIDATE_REGION (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/event_listeners.js:81:45)
    at Request.callListeners (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at callNextListener (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/event_listeners.js:75:9
    at finish (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:308:7)
    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:324:9
    at SharedIniFileCredentials.get (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/credentials.js:126:7)
    at getAsyncCredentials (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:318:24)
    at Config.getCredentials (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:338:9)
    at Request.VALIDATE_CREDENTIALS (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/event_listeners.js:70:26)
    at Request.callListeners (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:101:18)
    at Request.emit (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:668:14)
    at Request.transition (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at Request.runTo (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:394:15)
    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:768:12
    at Request.promise (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:760:12)
    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/dist/bundle.js:1:4310
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  message: 'Missing region in config',
  code: 'ConfigError',
  time: 2017-01-20T13:23:32.750Z } 'ConfigError: Missing region in config\n    at Request.VALIDATE_REGION (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/event_listeners.js:81:45)\n    at Request.callListeners (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:105:20)\n    at callNextListener (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:95:12)\n    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/event_listeners.js:75:9\n    at finish (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:308:7)\n    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:324:9\n    at SharedIniFileCredentials.get (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/credentials.js:126:7)\n    at getAsyncCredentials (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:318:24)\n    at Config.getCredentials (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/config.js:338:9)\n    at Request.VALIDATE_CREDENTIALS (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/event_listeners.js:70:26)\n    at Request.callListeners (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:101:18)\n    at Request.emit (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/sequential_executor.js:77:10)\n    at Request.emit (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:668:14)\n    at Request.transition (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:22:10)\n    at AcceptorStateMachine.runTo (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/state_machine.js:14:12)\n    at Request.runTo (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:394:15)\n    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:768:12\n    at Request.promise (/Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/node_modules/aws-sdk/lib/request.js:760:12)\n    at /Users/hassankhan/Projects/serverless-project/node_modules/serverless-common/dist/bundle.js:1:4310\n    at process._tickDomainCallback (internal/process/next_tick.js:129:7)'

@bgenchel
Copy link
Author

Mine isn't nearly as detailed.
screen shot 2017-01-20 at 8 47 12 am

@hassankhan
Copy link

hassankhan commented Jan 21, 2017

Ahh I just remembered a workaround, export the environment variable yourself:

$ export SERVERLESS_REGION=us-east-1
$ sls offline --location .webpack

I'm using this package in conjunction with serverless-webpack, that's probably why my stacktrace is more beefy.

@benday280412
Copy link

benday280412 commented May 18, 2017

I was facing this same issue, but the above didn't fix it, this however did:

$ export AWS_REGION=eu-west-2

@wallaceroque
Copy link

Thank you @benday280412 ! Works for me too!

@dherault dherault closed this as completed Jul 6, 2017
@arabold
Copy link

arabold commented Jul 7, 2017

This error happens if you run code locally that tries to access AWS resources without explicitly specifying a region. E.g. if you just do something like this:

const sns = new AWS.SNS({ apiVersion: '2010-08-01' });

In that case the AWS_REGION environment might be set if the user doesn't set it explicitly in the ~/.profile or somewhere similar. When deployed to AWS this isn't a problem as the region is implicitly set and it will "just work".

Typically you want to explicitly specify a region for your resources. The resources you want to access might not be in the same region where your code runs. We usually use the following pattern (and I guess that's what @hassankhan does as well):

const sns = new AWS.SNS({ apiVersion: '2010-08-01', region: process.env.SERVERLESS_REGION });

This sets the region explicitly to a SERVERLESS_REGION environment variable that we set via serverless.yml.

To simulate the AWS environment more closely, serverless-offline could (should?) explicitly set the AWS_REGION environment variable to the selected or default Serverless region. That should solve the problem described above. Not sure if it's a good or bad idea to set the AWS_REGION explicitly in serverless-offline though. Any thoughts?

@dherault You think we should open a new task discussing setting AWS_REGION in serverless-offline automatically?

@arabold
Copy link

arabold commented Jul 7, 2017

Coincidentally I've just found this: serverless/serverless#3908 -- Seems serverless invoke local had a similar problem which is fixed in that PR finally.

@dimitrovs
Copy link

We shouldn't have to explicitly set AWS_REGION when it's already configured in Serverless. The fix referenced by @arabold makes sense to me.

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

7 participants