Serverless.yml - get the aws region you are running in

Hi

Is it possible to get the current region which you are running serverless against when running the script?
For example if I run this command
serverless deploy -r us-west-1 -s test

Is it possible to reference the value of us-west-1 in my serverless.yml file?

Thanks
Damien

Using ${opt:region, self:provider.region} should work. It’s probably more common to include the following snippet inside your serverless.yml then use ${self:custom.region}

custom:
  region: ${opt:region, self:provider.region}

Thanks for your help

I tried the following
provider:
name: aws
runtime: java8
custom:
region: ${opt:region, self:provider.region}
environment:
SPRING_PROFILES_ACTIVE: ${custom.region}

But got this error message
Serverless Error ---------------------------------------

 Invalid variable reference syntax for variable custom.region.
 You can only reference env vars, options, & files. You
 can check our docs for more info.

It would help if you can format your serverless.yml.

1 Like

perhaps can try ${self:custom.region} ?

2 Likes

I success this code.
you can try it !

provider:
    name: aws
    runtime: java8
    #region option
    region: ${opt:region, self:custom.defaultRegion}
custom:
    defaultRegion: ap-northeast-1

I use the serverless pseudo parameters plugin for this: https://www.serverless.com/plugins/serverless-pseudo-parameters With this plugin you can reference #{AWS::Region}:#{AWS::AccountId} in your yaml, for example.