sbstjn / serverless-dynamodb-autoscaling

Serverless Plugin for Amazon DynamoDB Auto Scaling configuration.
https://sbstjn.com/serverless-dynamodb-auto-scaling-with-cloudformation.html
MIT License
148 stars 27 forks source link

Enable autoscaling only for one environment #34

Closed dbeja closed 3 years ago

dbeja commented 6 years ago

Hi,

Is it possible to enable autoscaling only for prod? What would be the best way to achieve that?

Thanks!

sbstjn commented 6 years ago

Great idea! The plugin does not support anything like this currently, but maybe you can somehow do this with Reference Variables in Javascript Files

dbeja commented 6 years ago

Thanks!

The way I did this was to keep the autoscaling for all environments but with lower values to all environments except prod:

custom:
  maxRead_prod: 2000
  maxWrite_prod: 1000
  capacities:
    - table: users
      read:
        minimum: 5
        maximum: ${self:custom.maxRead_${self:provider.stage}, '10'}
      write:
        minimum: 5
        maximum: ${self:custom.maxRead_${self:provider.stage}, '10'}
oleschaper commented 6 years ago

Hi,

just wanted to do the same thing but for me the nested variable replacement did not work (I got null in the generated template) so I had to write

maximum: ${self.custom.maxRead_prod}

Any idea why?

dbeja commented 6 years ago

Do you have the stage defined on provider with a custom value?

provider:
  name: aws
  runtime: nodejs6.10
  stage: ${opt:stage, 'dev'}
oleschaper commented 6 years ago

Ok, I was using serverless 1.18.0, I updated to 1.24.1 and now it works.

ashtonmeuser commented 6 years ago

Just stumbled upon this and would like to point out that @dbeja is using the maxRead_ custom variable for both reads and writes. His serverless.yml file should contain the following.

custom:
  maxRead_prod: 2000
  maxWrite_prod: 1000
  capacities:
    - table: users
      read:
        minimum: 5
        maximum: ${self:custom.maxRead_${self:provider.stage}, '10'}
      write:
        minimum: 5
        maximum: ${self:custom.maxWrite_${self:provider.stage}, '10'}