Serverless Deploy Skip custom

Hi all,

I dunno how but i could not find an answer to this online. Seems like a very simple thing though.

in my serverless.yml file i got the following

custom:
  dynamodb:
    start:
      port: 8000
      inMemory: true
      migrate: true
      seed: true
      sharedDB: true

When ever i deploy to --stage prod i comment out the custom section.

How do we solve this issue. Frankly i read about variables but i could not get how works really.

Any guidance is appreciated

Cheers

Can you wrap your YAML in ```yaml and ``` so that the formatting is maintained.

You probably probably want something like this:

custom:
  stage: "${opt:stage, self:provider.stage}"
  dynamodb: ${self:custom.${self:custom.stage}.dynamodb}
  prod:
    dynamodb:
  dev:
    dynamodb:
      start:
        port: 8000
        inMemory: true
        migrate: true
        seed: true
        sharedDB: true

First it seems the code edit is not allowing for the yaml format. Sorry mate.

Second, thanks, i think i got how it works. will give it a shot

1 Like

In case someone finds this post here goes a good solution

in the serverless.yml add the following

custom:
  envs: ${file(envs/env.${opt:stage, self:provider.stage}.yml)}

add envs/env.dev.yml, envs/env.prod.yml

You can now access the contents as follows

functions:
  hello:
    handler: handers/hello.world
    environment:
      name:  ${self:custom.envs.name}

in your hello.js in world you can access name like process.env.name

hope this helps someone someday