2

I have a little doubt about "Mappings section" of the aws cloudformation syntax:

Example:

...
Mappings:
  accounts:
    56565d644801:true
    986958470041:true
    090960219037:true
    05166767667:false

functions:
  MyFunction:
    handler: src/MyFunction/func.lambda_handler
    role: MyRole
    events:
      - schedule:
          rate: rate(12 hours)
          enabled: Fn::FindInMap
                - accounts
                - Ref "AWS::AccountId"
...

Could the Mappings section be included in a serverless.yml file ? I meant, eventhough it is a valid cloudformation syntax, would it possible include it in the serverless.yml, so that later we can implement it (serverless | sls deploy ...)?

thanks,

sniperd
  • 5,124
  • 6
  • 28
  • 44

2 Answers2

2

You might be able to use:

functions:
  # ...

resources:
  Mappings:
    accounts:
      56565d644801:true
      986958470041:true
      090960219037:true
      05166767667:false
kichik
  • 33,220
  • 7
  • 94
  • 114
  • Thanks a lot ! It worked in the resources section... I had put it in the wrong place ;-) I need to continue working on this. If I have any other doubt, I will open a new question. – José Enrique Hernández Mar 22 '18 at 00:37
0

Just another way to work with mapping is through stage params.

https://www.serverless.com/framework/docs/guides/parameters

params:
  stage1:
    schedule:true
  stage2:
    schedule:false

functions:
  MyFunction:
    handler: src/MyFunction/func.lambda_handler
    role: MyRole
    events:
      - schedule:
          rate: rate(12 hours)
          enabled: ${param:schedule}

Then call adding the stage arg (default is dev)

serverless deploy --stage stage1
Rodrigo Matias
  • 352
  • 2
  • 7